Skip to content

Commit c743d72

Browse files
committed
Merging r354184:
------------------------------------------------------------------------ r354184 | ruiu | 2019-02-15 15:11:18 -0800 (Fri, 15 Feb 2019) | 10 lines [PPC64] Preserve LocalEntry when linking On PowerPC64, it is necessary to keep the LocalEntry bits in st_other, especially when -r is used. Otherwise, when the resulting object is used in a posterior linking, LocalEntry info will be unavailable and functions may be called through the wrong entrypoint. Patch by Leandro Lupori. Differential Revision: https://reviews.llvm.org/D56782 ------------------------------------------------------------------------ llvm-svn: 361921
1 parent 11c3a5c commit c743d72

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

lld/ELF/SyntheticSections.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,6 +2001,11 @@ template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) {
20012001
ESym->setVisibility(Sym->Visibility);
20022002
}
20032003

2004+
// The 3 most significant bits of st_other are used by OpenPOWER ABI.
2005+
// See getPPC64GlobalEntryToLocalEntryOffset() for more details.
2006+
if (Config->EMachine == EM_PPC64)
2007+
ESym->st_other |= Sym->StOther & 0xe0;
2008+
20042009
ESym->st_name = Ent.StrTabOffset;
20052010
ESym->st_shndx = getSymSectionIndex(Ent.Sym);
20062011

lld/test/ELF/ppc64-local-entry.s

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# REQUIRES: ppc
2+
3+
# RUN: llvm-mc -filetype=obj -triple=powerpc64 %s -o %t
4+
# RUN: ld.lld -r %t -o %t2
5+
# RUN: llvm-objdump -s -section=.symtab %t2 | FileCheck %s
6+
7+
.text
8+
.abiversion 2
9+
.globl _start
10+
.p2align 2
11+
.type _start,@function
12+
13+
_start:
14+
.Lfunc_begin0:
15+
.Lfunc_gep0:
16+
addis 2, 12, .TOC.-.Lfunc_gep0@ha
17+
addi 2, 2, .TOC.-.Lfunc_gep0@l
18+
.Lfunc_lep0:
19+
.localentry _start, .Lfunc_lep0-.Lfunc_gep0
20+
# The code below is not important, it just needs to access some
21+
# global data or function, in order to use the TOC.
22+
# In this case, it performs the following:
23+
# g += 10;
24+
# Also note that this code is not intended to be run, but only
25+
# to check if the linker will preserve the localentry info.
26+
addis 3, 2, g@toc@ha
27+
addi 3, 3, g@toc@l
28+
lwz 4, 0(3)
29+
addi 4, 4, 10
30+
stw 4, 0(3)
31+
blr
32+
.long 0
33+
.quad 0
34+
.Lfunc_end0:
35+
.size _start, .Lfunc_end0-.Lfunc_begin0
36+
37+
.type g,@object # @g
38+
.lcomm g,4,4
39+
40+
// We expect the st_other byte to be 0x60:
41+
// localentry = 011 (gep + 2 instructions), reserved = 000,
42+
// visibility = 00 (STV_DEFAULT)
43+
// Currently, llvm-objdump does not support displaying
44+
// st_other's PPC64 specific flags, thus we check the
45+
// result of the hexdump of .symtab section.
46+
47+
// CHECK: 0070 00000000 00000000 00000009 12600001

0 commit comments

Comments
 (0)