[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
Wed Feb 7 23:52:51 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:

I don't know of a concrete example of this in the wild, but should we also handle the case where both are `PT_LOAD` somehow? I feel like just picking whichever is higher alignment would be enough to properly preserve the parent/child relationship and get the alignment correct.

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


More information about the llvm-commits mailing list