[llvm-commits] [lld] r172133 - in /lld/trunk: lib/ReaderWriter/ELF/AtomsELF.h lib/ReaderWriter/ELF/WriterELF.cpp test/CMakeLists.txt test/elf/Inputs/init_array.x86-64 test/elf/init_array.test
Michael J. Spencer
bigcheesegs at gmail.com
Thu Jan 10 14:41:42 PST 2013
Author: mspencer
Date: Thu Jan 10 16:41:42 2013
New Revision: 172133
URL: http://llvm.org/viewvc/llvm-project?rev=172133&view=rev
Log:
[ELF] Add support for __init_array_{start,end}.
With this change c++ global constructors and destructors work.
Added:
lld/trunk/test/elf/Inputs/init_array.x86-64
lld/trunk/test/elf/init_array.test
Modified:
lld/trunk/lib/ReaderWriter/ELF/AtomsELF.h
lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp
lld/trunk/test/CMakeLists.txt
Modified: lld/trunk/lib/ReaderWriter/ELF/AtomsELF.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/AtomsELF.h?rev=172133&r1=172132&r2=172133&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/AtomsELF.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/AtomsELF.h Thu Jan 10 16:41:42 2013
@@ -283,6 +283,9 @@
|| _symbol->st_shndx == llvm::ELF::SHN_COMMON)
ret = typeZeroFill;
break;
+ case llvm::ELF::SHT_INIT_ARRAY:
+ ret = typeData;
+ break;
}
return ret;
@@ -356,6 +359,9 @@
case llvm::ELF::SHT_NOBITS:
return permRW_;
+ case llvm::ELF::SHT_INIT_ARRAY:
+ return permRW_;
+
default:
return perm___;
}
Modified: lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp?rev=172133&r1=172132&r2=172133&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/WriterELF.cpp Thu Jan 10 16:41:42 2013
@@ -1457,6 +1457,8 @@
ORDER_EH_FRAMEHDR,
ORDER_CTORS,
ORDER_DTORS,
+ ORDER_INIT_ARRAY,
+ ORDER_FINI_ARRAY,
ORDER_DYNAMIC,
ORDER_GOT,
ORDER_GOT_PLT,
@@ -1565,7 +1567,9 @@
return ORDER_RODATA;
case DefinedAtom::typeData:
- return ORDER_DATA;
+ return llvm::StringSwitch<Reference::Kind>(name)
+ .StartsWith(".init_array", ORDER_INIT_ARRAY)
+ .Default(ORDER_DATA);
case DefinedAtom::typeZeroFill:
return ORDER_BSS;
@@ -1624,6 +1628,8 @@
case ORDER_GOT_PLT:
case ORDER_DATA:
case ORDER_BSS:
+ case ORDER_INIT_ARRAY:
+ case ORDER_FINI_ARRAY:
return llvm::ELF::PT_LOAD;
default:
@@ -1654,6 +1660,8 @@
case ORDER_GOT:
case ORDER_GOT_PLT:
case ORDER_DATA:
+ case ORDER_INIT_ARRAY:
+ case ORDER_FINI_ARRAY:
case ORDER_BSS:
return true;
@@ -1708,6 +1716,25 @@
return error_code::success();
}
+ /// \biref Find an output Section given a section name.
+ ///
+ /// \todo Make this not O(n). We can't use _mergedSectionMap because it
+ /// doesn't get virtual addresses set :(
+ Chunk<target_endianness, max_align, is64Bits> *
+ findOutputSection(StringRef name) {
+ for (auto seg : _segments) {
+ for (auto sliceI = seg->slices_begin(),
+ sliceE = seg->slices_end(); sliceI != sliceE; ++sliceI) {
+ for (auto secI = (*sliceI)->sections_begin(),
+ secE = (*sliceI)->sections_end(); secI != secE; ++secI) {
+ if ((*secI)->name() == name)
+ return *secI;
+ }
+ }
+ }
+ return nullptr;
+ }
+
/// \brief find a absolute atom given a name
AbsoluteAtomIterT findAbsoluteAtom(const StringRef name) {
return std::find_if(_absoluteAtoms.begin(), _absoluteAtoms.end(),
@@ -2211,6 +2238,8 @@
_runtimeFile.addAbsoluteAtom("__bss_end");
_runtimeFile.addAbsoluteAtom("_end");
_runtimeFile.addAbsoluteAtom("end");
+ _runtimeFile.addAbsoluteAtom("__init_array_start");
+ _runtimeFile.addAbsoluteAtom("__init_array_end");
}
/// \brief Hook in lld to add CRuntime file
@@ -2234,6 +2263,18 @@
auto bssEndAtomIter = _layout->findAbsoluteAtom("__bss_end");
auto underScoreEndAtomIter = _layout->findAbsoluteAtom("_end");
auto endAtomIter = _layout->findAbsoluteAtom("end");
+ auto initArrayStartIter = _layout->findAbsoluteAtom("__init_array_start");
+ auto initArrayEndIter = _layout->findAbsoluteAtom("__init_array_end");
+
+ auto section = _layout->findOutputSection(".init_array");
+ if (section) {
+ initArrayStartIter->setValue(section->virtualAddr());
+ initArrayEndIter->setValue(section->virtualAddr() +
+ section->memSize());
+ } else {
+ initArrayStartIter->setValue(0);
+ initArrayEndIter->setValue(0);
+ }
assert(!(bssStartAtomIter == _layout->absAtomsEnd() ||
bssEndAtomIter == _layout->absAtomsEnd() ||
Modified: lld/trunk/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/CMakeLists.txt?rev=172133&r1=172132&r2=172133&view=diff
==============================================================================
--- lld/trunk/test/CMakeLists.txt (original)
+++ lld/trunk/test/CMakeLists.txt Thu Jan 10 16:41:42 2013
@@ -20,7 +20,7 @@
set(LLD_TEST_DEPS
lld-core lld-test.deps
FileCheck not llvm-nm
- lld
+ lld llvm-objdump
)
set(LLD_TEST_PARAMS
lld_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
Added: lld/trunk/test/elf/Inputs/init_array.x86-64
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Inputs/init_array.x86-64?rev=172133&view=auto
==============================================================================
Binary files lld/trunk/test/elf/Inputs/init_array.x86-64 (added) and lld/trunk/test/elf/Inputs/init_array.x86-64 Thu Jan 10 16:41:42 2013 differ
Added: lld/trunk/test/elf/init_array.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/init_array.test?rev=172133&view=auto
==============================================================================
--- lld/trunk/test/elf/init_array.test (added)
+++ lld/trunk/test/elf/init_array.test Thu Jan 10 16:41:42 2013
@@ -0,0 +1,5 @@
+RUN: lld -flavor ld -target x86_64-linux -o %t %p/Inputs/init_array.x86-64
+RUN: llvm-objdump -t -section-headers %t | FileCheck %s
+
+CHECK: .init_array {{[0-9]+}} [[ADDR:[0-9]+]]
+CHECK: [[ADDR]] g *ABS* {{[0-9]+}} __init_array_start
More information about the llvm-commits
mailing list