[PATCH] D67164: [ELF] Don't shrink RelrSection

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 06:09:22 PDT 2019


MaskRay created this revision.
MaskRay added reviewers: grimar, jakehehrlich, peter.smith, ruiu.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

Fixes PR43214.

The size of SHT_RELR may oscillate between 2 numbers (see D53003 <https://reviews.llvm.org/D53003> for a
similar --pack-dyn-relocs=android issue).  This can happen if the shrink
of SHT_RELR causes it to take more bytes to encode relocation offsets
(this can happen with thunks or segments with overlapping p_offset
ranges), and the expansion of SHT_RELR causes it to take fewer bytes to
encode relocation offsets.

To avoid the issue, add padding 1s to the end of the relocation section
if its size would decrease. Trailing 1s do not decode to more
relocations.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D67164

Files:
  ELF/SyntheticSections.cpp


Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -1957,6 +1957,11 @@
     }
   }
 
+  // Don't allow the section to shrink; otherwise the size of the section can
+  // oscillate infinitely. Trailing 1s do not decode to more relocations.
+  if (relrRelocs.size() < oldSize)
+    relrRelocs.resize(oldSize, Elf_Relr(1));
+
   return relrRelocs.size() != oldSize;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67164.218674.patch
Type: text/x-patch
Size: 481 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190904/8ae5130e/attachment.bin>


More information about the llvm-commits mailing list