[llvm] [llvm-objcopy] Add --gap-fill and --pad-to options (PR #65815)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 19 01:18:18 PDT 2023


================
@@ -2635,9 +2635,36 @@ template <class ELFT> Error ELFWriter<ELFT>::finalize() {
 }
 
 Error BinaryWriter::write() {
-  for (const SectionBase &Sec : Obj.allocSections())
+  SmallVector<const SectionBase *, 30> LoadableSections;
+  for (const SectionBase &Sec : Obj.allocSections()) {
+    if ((Sec.Flags & SectionFlag::SecLoad) && Sec.Type != SHT_NOBITS)
----------------
jh7370 wrote:

> Another question is whether NOBITS sections should be filled with a pattern, but GNU objcopy does this, which makes sense to me.

FWIW, the ELF spec explicitly states that `PT_LOAD` with `p_memsz > p_filesz` is padded with zeros (this is the case for a .bss section at a the end of a segment). It would be weird for other output formats to define a different system for initializing NOBITS data.

Anyway, no concrete concerns here, if @MaskRay is happy (like I said, I don't know much about the details of binary output).

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


More information about the llvm-commits mailing list