[llvm] [llvm-objcopy] Fix file offsets when PT_INTERP/PT_LOAD offsets are equal (PR #80562)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 15 00:23:57 PST 2024


================
@@ -1234,6 +1234,13 @@ static bool compareSegmentsByOffset(const Segment *A, const Segment *B) {
     return true;
   if (A->OriginalOffset > B->OriginalOffset)
     return false;
+  // If one is PT_LOAD and the other isn't (e.g. PT_INTERP, PT_GNU_RELRO,
+  // PT_TLS), order the PT_LOAD first to ensure ParentSegment relationship will
+  // be correct.
+  bool AIsLOAD = A->Type == PT_LOAD;
+  bool BIsLOAD = B->Type == PT_LOAD;
+  if (AIsLOAD != BIsLOAD)
----------------
jh7370 wrote:

Sorry for the delayed response: I'm not sure I follow why simply picking the highest alignment in a set of overlapping segments isn't sufficient? The comment you made is about PT_TLS having a lower alignment than PT_LOAD, in which case we'd want the PT_LOAD's higher alignment. But actually, the type of the PT_LOAD is somewhat irrelevant I'd have thought: you could imagine a custom segment type that requires alignment overlapping another segment type and the higher alignment would still be desirable to be used, regardless of the order of those segments.

https://github.com/llvm/llvm-project/pull/80562


More information about the llvm-commits mailing list