[lld] r242142 - [ELF/AArch64] Fix export TLS dynamic symbol
Adhemerval Zanella
adhemerval.zanella at linaro.org
Tue Jul 14 06:25:32 PDT 2015
Author: azanella
Date: Tue Jul 14 08:25:32 2015
New Revision: 242142
URL: http://llvm.org/viewvc/llvm-project?rev=242142&view=rev
Log:
[ELF/AArch64] Fix export TLS dynamic symbol
This patch fixes the TLS dynamic variable exportation from .got.plt segments,
created by General-dynamic relocations (TLSDESC). Current code only export
symbols in dynamic table from .got sections.
Modified:
lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.cpp
lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64RelocationPass.cpp
lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64SectionChunks.cpp
lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64SectionChunks.h
lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.cpp
lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.h
lld/trunk/test/elf/AArch64/general-dyn-tls-0.test
Modified: lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.cpp?rev=242142&r1=242141&r2=242142&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.cpp Tue Jul 14 08:25:32 2015
@@ -33,10 +33,12 @@ void AArch64ExecutableWriter::buildDynam
for (auto sec : this->_layout.sections()) {
if (auto section = dyn_cast<AtomSection<ELF64LE>>(sec)) {
for (const auto &atom : section->atoms()) {
- if (_targetLayout.getGOTSection().hasGlobalGOTEntry(atom->_atom)) {
- this->_dynamicSymbolTable->addSymbol(atom->_atom, section->ordinal(),
- atom->_virtualAddr, atom);
- continue;
+ // Add all globals GOT symbols (in both .got and .got.plt sections)
+ // on dynamic symbol table.
+ for (const auto §ion : _targetLayout.getGOTSections()) {
+ if (section->hasGlobalGOTEntry(atom->_atom))
+ _dynamicSymbolTable->addSymbol(atom->_atom, section->ordinal(),
+ atom->_virtualAddr, atom);
}
}
}
Modified: lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64RelocationPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64RelocationPass.cpp?rev=242142&r1=242141&r2=242142&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64RelocationPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64RelocationPass.cpp Tue Jul 14 08:25:32 2015
@@ -288,7 +288,8 @@ protected:
}
std::error_code handleTLSDESC(const Reference &ref) {
- if (isa<DefinedAtom>(ref.target())) {
+ if (isa<DefinedAtom>(ref.target()) ||
+ isa<SharedLibraryAtom>(ref.target())) {
const_cast<Reference &>(ref).setTarget(getTLSDESCPLTEntry(ref.target()));
}
return std::error_code();
Modified: lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64SectionChunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64SectionChunks.cpp?rev=242142&r1=242141&r2=242142&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64SectionChunks.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64SectionChunks.cpp Tue Jul 14 08:25:32 2015
@@ -13,11 +13,11 @@
namespace lld {
namespace elf {
-AArch64GOTSection::AArch64GOTSection(const ELFLinkingContext &ctx)
- : AtomSection<ELF64LE>(ctx, ".got", DefinedAtom::typeGOT, DefinedAtom::permRW_,
- TargetLayout<ELF64LE>::ORDER_GOT)
-{
- this->_alignment = 8;
+AArch64GOTSection::AArch64GOTSection(const ELFLinkingContext &ctx,
+ StringRef name, int32_t order)
+ : AtomSection<ELF64LE>(ctx, name, DefinedAtom::typeGOT, DefinedAtom::permRW_,
+ order) {
+ _alignment = 8;
}
const AtomLayout *AArch64GOTSection::appendAtom(const Atom *atom) {
Modified: lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64SectionChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64SectionChunks.h?rev=242142&r1=242141&r2=242142&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64SectionChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64SectionChunks.h Tue Jul 14 08:25:32 2015
@@ -17,7 +17,8 @@ namespace elf {
class AArch64GOTSection : public AtomSection<ELF64LE> {
public:
- AArch64GOTSection(const ELFLinkingContext &ctx);
+ AArch64GOTSection(const ELFLinkingContext &ctx, StringRef name,
+ int32_t order);
bool hasGlobalGOTEntry(const Atom *a) const {
return _tlsMap.count(a);
Modified: lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.cpp?rev=242142&r1=242141&r2=242142&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.cpp Tue Jul 14 08:25:32 2015
@@ -18,14 +18,17 @@ using namespace lld;
using namespace elf;
AArch64TargetLayout::AArch64TargetLayout(ELFLinkingContext &ctx) :
- TargetLayout(ctx),
- _gotSection(new (this->_allocator) AArch64GOTSection(ctx)) {}
+ TargetLayout(ctx) {}
AtomSection<ELF64LE> *AArch64TargetLayout::createSection(
StringRef name, int32_t type, DefinedAtom::ContentPermissions permissions,
TargetLayout<ELF64LE>::SectionOrder order) {
- if (type == DefinedAtom::typeGOT && name == ".got")
- return _gotSection;
+ if (type == DefinedAtom::typeGOT && (name == ".got" || name == ".got.plt")) {
+ auto section = new (this->_allocator) AArch64GOTSection(this->_ctx, name,
+ order);
+ _gotSections.push_back(section);
+ return section;
+ }
return TargetLayout<ELF64LE>::createSection(name, type, permissions, order);
}
Modified: lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.h?rev=242142&r1=242141&r2=242142&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.h Tue Jul 14 08:25:32 2015
@@ -32,7 +32,9 @@ public:
DefinedAtom::ContentPermissions permissions,
TargetLayout<ELF64LE>::SectionOrder order) override;
- const AArch64GOTSection &getGOTSection() const { return *_gotSection; }
+ const std::vector<AArch64GOTSection *> &getGOTSections() const {
+ return _gotSections;
+ }
uint64_t getTPOffset() {
std::call_once(_tpOffOnce, [this]() {
@@ -53,7 +55,7 @@ private:
};
private:
- AArch64GOTSection *_gotSection;
+ std::vector<AArch64GOTSection *> _gotSections;
uint64_t _tpOff = 0;
std::once_flag _tpOffOnce;
};
Modified: lld/trunk/test/elf/AArch64/general-dyn-tls-0.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/AArch64/general-dyn-tls-0.test?rev=242142&r1=242141&r2=242142&view=diff
==============================================================================
--- lld/trunk/test/elf/AArch64/general-dyn-tls-0.test (original)
+++ lld/trunk/test/elf/AArch64/general-dyn-tls-0.test Tue Jul 14 08:25:32 2015
@@ -31,13 +31,13 @@
#CHECKRELOCATION: Relocations [
#CHECKRELOCATION: .rela.dyn {
-#CHECKRELOCATION: 0x401090 R_AARCH64_TLSDESC - 0x0
+#CHECKRELOCATION: 0x401090 R_AARCH64_TLSDESC var 0x0
#CHECKRELOCATION: }
#CHECK: Contents of section .text:
-#CHECK: 400230 a8c31fb8 40018052 0b000094 000000b0 .... at ..R........
+#CHECK: 400250 a8c31fb8 40018052 0b000094 000000b0 .... at ..R........
# \_ adrp x0, 401000 <_DYNAMIC> (R_AARCH64_TLSDESC_ADR_PAGE21)
-#CHECK-NEXT: 400240 014840f9 00400291 20003fd6 49d03bd5 .H at ..@.. .?.I.;.
+#CHECK-NEXT: 400260 014840f9 00400291 20003fd6 49d03bd5 .H at ..@.. .?.I.;.
# \_ | | ldr x1, [x0,#144] (R_AARCH64_TLSDESC_LD64_LO12_NC)
# \_ | add x0, x0, #0x90 (R_AARCH64_TLSDESC_ADD_LO12_NC)
# \_ blr x1 (R_AARCH64_TLSDESC_CALL)
More information about the llvm-commits
mailing list