[lld] r175657 - [ELF][Writer] Add .interp section.
Michael J. Spencer
bigcheesegs at gmail.com
Wed Feb 20 12:13:48 PST 2013
Author: mspencer
Date: Wed Feb 20 14:13:47 2013
New Revision: 175657
URL: http://llvm.org/viewvc/llvm-project?rev=175657&view=rev
Log:
[ELF][Writer] Add .interp section.
Added:
lld/trunk/test/elf/dynamic-interp.test
Modified:
lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h
lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h
lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h
lld/trunk/lib/ReaderWriter/ELF/Writer.cpp
Modified: lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h?rev=175657&r1=175656&r2=175657&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h (original)
+++ lld/trunk/include/lld/ReaderWriter/ELFTargetInfo.h Wed Feb 20 14:13:47 2013
@@ -49,6 +49,10 @@ public:
return false;
}
+ virtual StringRef getInterpreter() const {
+ return "/lib64/ld-linux-x86-64.so.2";
+ }
+
/// \brief Does the output have dynamic sections.
bool isDynamic() const {
return _options._outputKind == OutputKind::DynamicExecutable ||
Modified: lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h?rev=175657&r1=175656&r2=175657&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h Wed Feb 20 14:13:47 2013
@@ -183,7 +183,8 @@ bool ProgramHeader<ELFT>::addSegment(Seg
for (auto slice : segment->slices()) {
// If we have a TLS segment, emit a LOAD first.
if (segment->segmentType() == llvm::ELF::PT_TLS ||
- segment->segmentType() == llvm::ELF::PT_DYNAMIC) {
+ segment->segmentType() == llvm::ELF::PT_DYNAMIC ||
+ segment->segmentType() == llvm::ELF::PT_INTERP) {
auto phdr = allocateProgramHeader();
if (phdr.second)
allocatedNew = true;
Modified: lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h?rev=175657&r1=175656&r2=175657&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h Wed Feb 20 14:13:47 2013
@@ -758,6 +758,31 @@ public:
private:
EntriesT _entries;
};
+
+template <class ELFT> class InterpSection : public Section<ELFT> {
+public:
+ InterpSection(const ELFTargetInfo &ti, StringRef str, int32_t order,
+ StringRef interp)
+ : Section<ELFT>(ti, str),
+ _interp(interp){
+ this->setOrder(order);
+ this->_align2 = 1;
+ // + 1 for null term.
+ this->_fsize = interp.size() + 1;
+ this->_msize = this->_fsize;
+ this->_type = SHT_PROGBITS;
+ this->_flags = SHF_ALLOC;
+ }
+
+ void write(ELFWriter *writer, llvm::FileOutputBuffer &buffer) {
+ uint8_t *chunkBuffer = buffer.getBufferStart();
+ uint8_t *dest = chunkBuffer + this->fileOffset();
+ std::memcpy(dest, _interp.data(), _interp.size());
+ }
+
+private:
+ StringRef _interp;
+};
} // end namespace elf
} // end namespace lld
Modified: lld/trunk/lib/ReaderWriter/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Writer.cpp?rev=175657&r1=175656&r2=175657&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Writer.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Writer.cpp Wed Feb 20 14:13:47 2013
@@ -69,6 +69,7 @@ private:
/// \name Dynamic sections.
/// @{
LLD_UNIQUE_BUMP_PTR(DynamicTable<ELFT>) _dynamicTable;
+ LLD_UNIQUE_BUMP_PTR(InterpSection<ELFT>) _interpSection;
/// @}
CRuntimeFile<ELFT> _runtimeFile;
};
@@ -337,7 +338,11 @@ void ExecutableWriter<ELFT>::createDefau
if (_targetInfo.isDynamic()) {
_dynamicTable.reset(new (_alloc) DynamicTable<ELFT>(
_targetInfo, ".dynamic", DefaultLayout<ELFT>::ORDER_DYNAMIC));
+ _interpSection.reset(new (_alloc) InterpSection<ELFT>(
+ _targetInfo, ".interp", DefaultLayout<ELFT>::ORDER_INTERP,
+ _targetInfo.getInterpreter()));
_layout->addSection(_dynamicTable.get());
+ _layout->addSection(_interpSection.get());
}
// give a chance for the target to add sections
Added: lld/trunk/test/elf/dynamic-interp.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/dynamic-interp.test?rev=175657&view=auto
==============================================================================
--- lld/trunk/test/elf/dynamic-interp.test (added)
+++ lld/trunk/test/elf/dynamic-interp.test Wed Feb 20 14:13:47 2013
@@ -0,0 +1,8 @@
+RUN: lld -core -target x86_64-linux %p/Inputs/use-shared.x86-64 \
+RUN: %p/Inputs/shared.so-x86-64 -output=%t -entry=main \
+RUN: -output-type=dynamic
+RUN: llvm-objdump -p %t | FileCheck %s
+
+CHECK: INTERP
+CHECK: flags r--
+CHECK: off
More information about the llvm-commits
mailing list