[PATCH] [lld][ELF] Order segments properly
Shankar Kalpathi Easwaran
shankarke at gmail.com
Sun Feb 24 11:17:01 PST 2013
Hi Bigcheese,
Order the segments by their types
http://llvm-reviews.chandlerc.com/D458
Files:
SegmentChunks.h
Index: SegmentChunks.h
===================================================================
--- SegmentChunks.h
+++ SegmentChunks.h
@@ -112,6 +112,20 @@
const Layout::SegmentType type);
enum SegmentOrder {
+ NULLT,
+ PHDR,
+ INTERP,
+ LOAD,
+ DYNAMIC,
+ NOTE,
+ TLS,
+ EH_FRAME,
+ GNU_STACK,
+ GNU_RELRO,
+ UNKNOWN
+ };
+
+ enum LoadSegmentOrder {
permUnknown,
permRWX,
permRX,
@@ -181,6 +195,9 @@
inline int rawflags() const { return _atomflags; }
+ /// \brief Convert atomflags to secondary segment order for segments
+ /// that have the same segment type. The segments are sorted by
+ /// their permisions
inline int64_t atomflags() const {
switch (_atomflags) {
@@ -208,6 +225,34 @@
}
}
+ /// \brief convert the segment type to enumeration for sorting secgments
+ inline int64_t segmentOrder() const {
+ switch (_segmentType) {
+ case llvm::ELF::PT_NULL:
+ return NULLT;
+ case llvm::ELF::PT_PHDR:
+ return PHDR;
+ case llvm::ELF::PT_LOAD:
+ return LOAD;
+ case llvm::ELF::PT_DYNAMIC:
+ return DYNAMIC;
+ case llvm::ELF::PT_INTERP:
+ return INTERP;
+ case llvm::ELF::PT_NOTE:
+ return NOTE;
+ case llvm::ELF::PT_TLS:
+ return TLS;
+ case llvm::ELF::PT_GNU_EH_FRAME:
+ return EH_FRAME;
+ case llvm::ELF::PT_GNU_STACK:
+ return GNU_STACK;
+ case llvm::ELF::PT_GNU_RELRO:
+ return GNU_RELRO;
+ default:
+ llvm_unreachable("unknown segment type");
+ }
+ }
+
inline int64_t numSlices() const { return _segmentSlices.size(); }
inline range<SliceIter> slices() { return _segmentSlices; }
@@ -270,7 +315,9 @@
template <class ELFT>
bool Segment<ELFT>::compareSegments(Segment<ELFT> *sega, Segment<ELFT> *segb) {
- return sega->atomflags() < segb->atomflags();
+ if (sega->segmentOrder() == segb->segmentOrder())
+ return sega->atomflags() < segb->atomflags();
+ return sega->segmentOrder() < segb->segmentOrder();
}
template <class ELFT> void Segment<ELFT>::assignOffsets(uint64_t startOffset) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D458.1.patch
Type: text/x-patch
Size: 2107 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130224/8ca3ff28/attachment.bin>
More information about the llvm-commits
mailing list