[lld] r189907 - [lld][ELF] Differentiate between Note sections(RW/RO)
Shankar Easwaran
shankare at codeaurora.org
Tue Sep 3 19:42:02 PDT 2013
Author: shankare
Date: Tue Sep 3 21:42:02 2013
New Revision: 189907
URL: http://llvm.org/viewvc/llvm-project?rev=189907&view=rev
Log:
[lld][ELF] Differentiate between Note sections(RW/RO)
It looks like there is a possibility of seeing RO/RW note sections
and we would need to create an appropriate RO/RW segment associated
with them.
Adds a test too.
Added:
lld/trunk/test/elf/X86_64/Inputs/note_ro_rw.o
lld/trunk/test/elf/X86_64/Inputs/note_ro_rw.s
lld/trunk/test/elf/X86_64/note-sections-ro_plus_rw.test
Modified:
lld/trunk/include/lld/Core/DefinedAtom.h
lld/trunk/lib/Core/DefinedAtom.cpp
lld/trunk/lib/ReaderWriter/ELF/Atoms.h
lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h
lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h
lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
Modified: lld/trunk/include/lld/Core/DefinedAtom.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/DefinedAtom.h?rev=189907&r1=189906&r2=189907&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/DefinedAtom.h (original)
+++ lld/trunk/include/lld/Core/DefinedAtom.h Tue Sep 3 21:42:02 2013
@@ -147,7 +147,8 @@ public:
typeDataDirectoryEntry, // linker created for data directory header [PECOFF]
typeThreadZeroFill, // Uninitialized thread local data(TBSS) [ELF]
typeThreadData, // Initialized thread local data(TDATA) [ELF]
- typeNote, // Identifies note sections [ELF]
+ typeRONote, // Identifies readonly note sections [ELF]
+ typeRWNote, // Identifies readwrite note sections [ELF]
};
// Permission bits for atoms and segments. The order of these values are
Modified: lld/trunk/lib/Core/DefinedAtom.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/DefinedAtom.cpp?rev=189907&r1=189906&r2=189907&view=diff
==============================================================================
--- lld/trunk/lib/Core/DefinedAtom.cpp (original)
+++ lld/trunk/lib/Core/DefinedAtom.cpp Tue Sep 3 21:42:02 2013
@@ -41,7 +41,7 @@ DefinedAtom::ContentPermissions DefinedA
case typeLiteral16:
case typeDTraceDOF:
case typeCompactUnwindInfo:
- case typeNote:
+ case typeRONote:
return permR__;
case typeData:
@@ -53,6 +53,7 @@ DefinedAtom::ContentPermissions DefinedA
case typeLazyDylibPointer:
case typeThunkTLV:
case typeDataDirectoryEntry:
+ case typeRWNote:
return permRW_;
case typeGOT:
Modified: lld/trunk/lib/ReaderWriter/ELF/Atoms.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Atoms.h?rev=189907&r1=189906&r2=189907&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Atoms.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Atoms.h Tue Sep 3 21:42:02 2013
@@ -296,9 +296,6 @@ public:
if (_symbol->st_shndx == llvm::ELF::SHN_COMMON)
return _contentType = typeZeroFill;
- if (_section->sh_type == llvm::ELF::SHT_NOTE)
- return _contentType = typeNote;
-
switch (_section->sh_type) {
case llvm::ELF::SHT_PROGBITS:
flags &= ~llvm::ELF::SHF_ALLOC;
@@ -320,6 +317,17 @@ public:
break;
}
break;
+ case llvm::ELF::SHT_NOTE:
+ flags &= ~llvm::ELF::SHF_ALLOC;
+ switch (flags) {
+ case llvm::ELF::SHF_WRITE:
+ ret = typeRWNote;
+ break;
+ default:
+ ret = typeRONote;
+ break;
+ }
+ break;
case llvm::ELF::SHT_NOBITS:
ret = typeZeroFill;
break;
@@ -410,6 +418,7 @@ public:
case llvm::ELF::SHT_DYNAMIC:
case llvm::ELF::SHT_PROGBITS:
+ case llvm::ELF::SHT_NOTE:
flags &= ~llvm::ELF::SHF_ALLOC;
flags &= ~llvm::ELF::SHF_GROUP;
switch (flags) {
@@ -439,9 +448,6 @@ public:
case llvm::ELF::SHT_FINI_ARRAY:
return _permissions = permRW_;
- case llvm::ELF::SHT_NOTE:
- return _permissions = permR__;
-
default:
return _permissions = perm___;
}
Modified: lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h?rev=189907&r1=189906&r2=189907&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h Tue Sep 3 21:42:02 2013
@@ -53,7 +53,8 @@ public:
enum DefaultSectionOrder {
ORDER_NOT_DEFINED = 0,
ORDER_INTERP = 10,
- ORDER_NOTE = 20,
+ ORDER_RO_NOTE = 15,
+ ORDER_RW_NOTE = 20,
ORDER_HASH = 30,
ORDER_DYNAMIC_SYMBOLS = 40,
ORDER_DYNAMIC_STRINGS = 50,
@@ -118,7 +119,7 @@ public:
// For example : PT_TLS, we have two sections .tdata/.tbss
// that are part of PT_TLS, we need to create this additional
// segment only once
- typedef int64_t AdditionalSegmentKey;
+ typedef std::pair<int64_t, int64_t> AdditionalSegmentKey;
// The segments are created using
// SegmentName, Segment flags
typedef std::pair<StringRef, int64_t> SegmentKey;
@@ -133,6 +134,16 @@ public:
}
};
+ class AdditionalSegmentHashKey {
+ public:
+ int64_t operator() (int64_t segmentType, int64_t segmentFlag) const {
+ // k.first = SegmentName
+ // k.second = SegmentFlags
+ return llvm::hash_combine(segmentType, segmentFlag);
+ }
+ };
+
+
// Merged Sections contain the map of Sectionnames to a vector of sections,
// that have been merged to form a single section
typedef std::map<StringRef, MergedSections<ELFT> *> MergedSectionMapT;
@@ -340,8 +351,11 @@ Layout::SectionOrder DefaultLayout<ELFT>
case DefinedAtom::typeStub:
return ORDER_PLT;
- case DefinedAtom::typeNote:
- return ORDER_NOTE;
+ case DefinedAtom::typeRONote:
+ return ORDER_RO_NOTE;
+
+ case DefinedAtom::typeRWNote:
+ return ORDER_RW_NOTE;
case DefinedAtom::typeThreadData:
return ORDER_TDATA;
@@ -407,7 +421,8 @@ Layout::SegmentType DefaultLayout<ELFT>:
case ORDER_EH_FRAMEHDR:
return llvm::ELF::PT_LOAD;
- case ORDER_NOTE:
+ case ORDER_RO_NOTE:
+ case ORDER_RW_NOTE:
return llvm::ELF::PT_NOTE;
case ORDER_DYNAMIC:
@@ -453,7 +468,8 @@ bool DefaultLayout<ELFT>::hasOutputSegme
case ORDER_EH_FRAMEHDR:
case ORDER_TDATA:
case ORDER_TBSS:
- case ORDER_NOTE:
+ case ORDER_RO_NOTE:
+ case ORDER_RW_NOTE:
case ORDER_DYNAMIC:
case ORDER_CTORS:
case ORDER_DTORS:
@@ -601,8 +617,9 @@ template <class ELFT> void DefaultLayout
// We need a seperate segment for sections that dont have
// the segment type to be PT_LOAD
if (segmentType != llvm::ELF::PT_LOAD) {
+ const AdditionalSegmentKey key(segmentType, lookupSectionFlag);
const std::pair<AdditionalSegmentKey, Segment<ELFT> *>
- additionalSegment(segmentType, nullptr);
+ additionalSegment(key, nullptr);
std::pair<typename AdditionalSegmentMapT::iterator, bool>
additionalSegmentInsert(
_additionalSegmentMap.insert(additionalSegment));
Modified: lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h?rev=189907&r1=189906&r2=189907&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h Tue Sep 3 21:42:02 2013
@@ -156,7 +156,8 @@ public:
this->_type = SHT_NOBITS;
break;
- case DefinedAtom::typeNote:
+ case DefinedAtom::typeRONote:
+ case DefinedAtom::typeRWNote:
this->_type = SHT_NOTE;
break;
}
@@ -285,7 +286,8 @@ const lld::AtomLayout &AtomSection<ELFT>
case DefinedAtom::typeStub:
case DefinedAtom::typeResolver:
case DefinedAtom::typeThreadData:
- case DefinedAtom::typeNote:
+ case DefinedAtom::typeRONote:
+ case DefinedAtom::typeRWNote:
_atoms.push_back(new (_alloc) lld::AtomLayout(atom, fOffset, 0));
this->_fsize = fOffset + definedAtom->size();
this->_msize = mOffset + definedAtom->size();
Modified: lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp?rev=189907&r1=189906&r2=189907&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp (original)
+++ lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp Tue Sep 3 21:42:02 2013
@@ -491,7 +491,8 @@ struct ScalarEnumerationTraits<lld::Defi
lld::DefinedAtom::typeThreadData);
io.enumCase(value, "thread-zero-fill",
lld::DefinedAtom::typeThreadZeroFill);
- io.enumCase(value, "note", lld::DefinedAtom::typeNote);
+ io.enumCase(value, "note", lld::DefinedAtom::typeRONote);
+ io.enumCase(value, "note", lld::DefinedAtom::typeRWNote);
}
};
Added: lld/trunk/test/elf/X86_64/Inputs/note_ro_rw.o
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/X86_64/Inputs/note_ro_rw.o?rev=189907&view=auto
==============================================================================
Binary files lld/trunk/test/elf/X86_64/Inputs/note_ro_rw.o (added) and lld/trunk/test/elf/X86_64/Inputs/note_ro_rw.o Tue Sep 3 21:42:02 2013 differ
Added: lld/trunk/test/elf/X86_64/Inputs/note_ro_rw.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/X86_64/Inputs/note_ro_rw.s?rev=189907&view=auto
==============================================================================
--- lld/trunk/test/elf/X86_64/Inputs/note_ro_rw.s (added)
+++ lld/trunk/test/elf/X86_64/Inputs/note_ro_rw.s Tue Sep 3 21:42:02 2013
@@ -0,0 +1,21 @@
+ .section ".note.ro", "a"
+ .p2align 2
+ .long 1f - 0f # name size (not including padding)
+ .long 3f - 2f # desc size (not including padding)
+ .long 0x01234567 # type
+0: .asciz "NaMe" # name
+1: .p2align 2
+2: .long 0x76543210 # desc
+ .long 0x89abcdef
+3: .p2align 2
+ .section ".note.rw", "aw"
+ .p2align 2
+ .long 1f - 0f # name size (not including padding)
+ .long 3f - 2f # desc size (not including padding)
+ .long 0x01234567 # type
+0: .asciz "NaMe" # name
+1: .p2align 2
+2: .long 0x76543210 # desc
+ .long 0x89abcdef
+3: .p2align 2
+
Added: lld/trunk/test/elf/X86_64/note-sections-ro_plus_rw.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/X86_64/note-sections-ro_plus_rw.test?rev=189907&view=auto
==============================================================================
--- lld/trunk/test/elf/X86_64/note-sections-ro_plus_rw.test (added)
+++ lld/trunk/test/elf/X86_64/note-sections-ro_plus_rw.test Tue Sep 3 21:42:02 2013
@@ -0,0 +1,44 @@
+# This tests the functionality that lld is able to recreate the note sections
+# if they appear in the input, it looks like we need to differentiate RO note
+# sections from RW note sections, and each creating a segment of its own
+
+RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/note_ro_rw.o \
+RUN: --noinhibit-exec -o %t -static
+RUN: llvm-readobj -sections %t | FileCheck -check-prefix=NOTESECTIONS %s
+RUN: llvm-readobj -program-headers %t | FileCheck -check-prefix=NOTESEGMENT %s
+
+NOTESECTIONS: Section {
+NOTESECTIONS: Index: 1
+NOTESECTIONS: Name: .note.ro (1)
+NOTESECTIONS: Type: SHT_NOTE (0x7)
+NOTESECTIONS: Flags [ (0x2)
+NOTESECTIONS: SHF_ALLOC (0x2)
+NOTESECTIONS: ]
+NOTESECTIONS: AddressAlignment: 4
+NOTESECTIONS: }
+NOTESECTIONS: Section {
+NOTESECTIONS: Index: 2
+NOTESECTIONS: Name: .note.rw (10)
+NOTESECTIONS: Type: SHT_NOTE (0x7)
+NOTESECTIONS: Flags [ (0x3)
+NOTESECTIONS: SHF_ALLOC (0x2)
+NOTESECTIONS: SHF_WRITE (0x1)
+NOTESECTIONS: ]
+NOTESECTIONS: Size: 28
+NOTESECTIONS: AddressAlignment: 4
+NOTESECTIONS: }
+NOTESEGMENT: ProgramHeader {
+NOTESEGMENT: Type: PT_NOTE (0x4)
+NOTESEGMENT: Flags [ (0x4)
+NOTESEGMENT: PF_R (0x4)
+NOTESEGMENT: ]
+NOTESEGMENT: Alignment: 4
+NOTESEGMENT: }
+NOTESEGMENT: ProgramHeader {
+NOTESEGMENT: Type: PT_NOTE (0x4)
+NOTESEGMENT: Flags [ (0x6)
+NOTESEGMENT: PF_R (0x4)
+NOTESEGMENT: PF_W (0x2)
+NOTESEGMENT: ]
+NOTESEGMENT: Alignment: 4
+NOTESEGMENT: }
More information about the llvm-commits
mailing list