Skip to content

Commit 897fd6e

Browse files
committed
Merging r361237:
------------------------------------------------------------------------ r361237 | maskray | 2019-05-21 03:41:25 -0700 (Tue, 21 May 2019) | 14 lines [PPC64] Update LocalEntry from assigned symbols On PowerPC64 ELFv2 ABI, functions may have 2 entry points: global and local. The local entry point location of a function is stored in the st_other field of the symbol, as an offset relative to the global entry point. In order to make symbol assignments (e.g. .equ/.set) work properly with this, PPCTargetELFStreamer already copies the local entry bits from the source symbol to the destination one, on emitAssignment(). The problem is that this copy is performed only at the assignment location, where the source symbol may not yet have processed the .localentry directive, that sets the local entry. This may cause the destination symbol to end up with wrong local entry information. Other symbol info is not affected by this because, in this case, the destination symbol value is actually a symbol reference. This change keeps track of these assignments, and update all needed st_other fields when finish() is called. Patch by Leandro Lupori! Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D56586 ------------------------------------------------------------------------ llvm-svn: 362671
1 parent 4db27e1 commit 897fd6e

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "InstPrinter/PPCInstPrinter.h"
1616
#include "MCTargetDesc/PPCMCAsmInfo.h"
1717
#include "PPCTargetStreamer.h"
18+
#include "llvm/ADT/SmallPtrSet.h"
1819
#include "llvm/ADT/StringRef.h"
1920
#include "llvm/ADT/Triple.h"
2021
#include "llvm/BinaryFormat/ELF.h"
@@ -182,16 +183,33 @@ class PPCTargetELFStreamer : public PPCTargetStreamer {
182183

183184
void emitAssignment(MCSymbol *S, const MCExpr *Value) override {
184185
auto *Symbol = cast<MCSymbolELF>(S);
186+
185187
// When encoding an assignment to set symbol A to symbol B, also copy
186188
// the st_other bits encoding the local entry point offset.
187-
if (Value->getKind() != MCExpr::SymbolRef)
188-
return;
189-
const auto &RhsSym = cast<MCSymbolELF>(
190-
static_cast<const MCSymbolRefExpr *>(Value)->getSymbol());
191-
unsigned Other = Symbol->getOther();
189+
if (copyLocalEntry(Symbol, Value))
190+
UpdateOther.insert(Symbol);
191+
else
192+
UpdateOther.erase(Symbol);
193+
}
194+
195+
void finish() override {
196+
for (auto *Sym : UpdateOther)
197+
copyLocalEntry(Sym, Sym->getVariableValue());
198+
}
199+
200+
private:
201+
SmallPtrSet<MCSymbolELF *, 32> UpdateOther;
202+
203+
bool copyLocalEntry(MCSymbolELF *D, const MCExpr *S) {
204+
auto *Ref = dyn_cast<const MCSymbolRefExpr>(S);
205+
if (!Ref)
206+
return false;
207+
const auto &RhsSym = cast<MCSymbolELF>(Ref->getSymbol());
208+
unsigned Other = D->getOther();
192209
Other &= ~ELF::STO_PPC64_LOCAL_MASK;
193210
Other |= RhsSym.getOther() & ELF::STO_PPC64_LOCAL_MASK;
194-
Symbol->setOther(Other);
211+
D->setOther(Other);
212+
return true;
195213
}
196214
};
197215

llvm/test/MC/PowerPC/ppc64-localentry-symver.s renamed to llvm/test/MC/PowerPC/ppc64-localentry-symbols.s

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
# CHECK: 0000000000000000 gw F .text 00000000 0x60 __impl_foo
55
# CHECK: 0000000000000000 g F .text 00000000 0x60 foo
66
# CHECK: 0000000000000000 gw F .text 00000000 0x60 foo@FBSD_1.1
7+
# CHECK: 0000000000000008 g F .text 00000000 0x60 func
8+
# CHECK: 0000000000000008 gw F .text 00000000 0x60 weak_func
9+
10+
.text
11+
.abiversion 2
712

813
.globl foo
914
.type foo,@function
@@ -15,3 +20,15 @@ foo:
1520
.symver __impl_foo, foo@FBSD_1.1
1621
.weak __impl_foo
1722
.set __impl_foo, foo
23+
24+
.globl func
25+
# Mimick FreeBSD weak function/reference
26+
.weak weak_func
27+
.equ weak_func, func
28+
29+
.p2align 2
30+
.type func,@function
31+
func:
32+
nop
33+
nop
34+
.localentry func, 8

0 commit comments

Comments
 (0)