[PATCH] D44986: Initialize Elf header and Program Header to Zero

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 28 10:53:35 PDT 2018


ruiu added inline comments.


================
Comment at: lld/ELF/Writer.cpp:2111
   uint8_t *Buf = Buffer->getBufferStart();
+  memset(Buf, 0 , sizeof(Elf_Ehdr)+sizeof(Elf_Phdr));
   memcpy(Buf, "\177ELF", 4);
----------------
mgrang wrote:
> Please make spacing uniform.
> ```
> memset(Buf, 0, sizeof(Elf_Ehdr) + sizeof(Elf_Phdr));
> ```
> 
> Also could you please add a unit test?
If -r option is given, we don't emit Phdr, so this is inaccurate. It's in practice not a problem because I can't think of an ELF file that is smaller than sizeof(Elf_Ehdr) + sizeof(Elf_Phdr), but being accurate helps readers understand the code.

So it is better to just set the first sizeof(Elf_Ehdr).


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D44986





More information about the llvm-commits mailing list