[lld] 9c4292a - [ELF] Remove unneeded SyntheticSection memset(*, 0, *)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 16 22:52:02 PST 2022
Author: Fangrui Song
Date: 2022-01-16T22:51:57-08:00
New Revision: 9c4292a59da2d8fc31ead9649868ec5bfb3cf883
URL: https://github.com/llvm/llvm-project/commit/9c4292a59da2d8fc31ead9649868ec5bfb3cf883
DIFF: https://github.com/llvm/llvm-project/commit/9c4292a59da2d8fc31ead9649868ec5bfb3cf883.diff
LOG: [ELF] Remove unneeded SyntheticSection memset(*, 0, *)
After the D33630 fallout was properly fixed by a4c5db30be4e216834b44e31b47304ea1b92635f.
Tested by D37462/D44986 tests, the new --no-rosegment test in build-id.s, and a few --rosegment/--no-rosegment programs.
Added:
Modified:
lld/ELF/SyntheticSections.cpp
Removed:
################################################################################
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 6069c603bacb..f20000ab7a3b 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -496,9 +496,8 @@ static void writeCieFde(uint8_t *buf, ArrayRef<uint8_t> d) {
memcpy(buf, d.data(), d.size());
size_t aligned = alignTo(d.size(), config->wordsize);
-
- // Zero-clear trailing padding if it exists.
- memset(buf + d.size(), 0, aligned - d.size());
+ assert(std::all_of(buf + d.size(), buf + aligned,
+ [](uint8_t c) { return c == 0; }));
// Fix the size field. -4 since size does not include the size field itself.
write32(buf, aligned - 4);
@@ -2221,7 +2220,6 @@ static uint32_t getSymSectionIndex(Symbol *sym) {
// Write the internal symbol table contents to the output symbol table.
template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *buf) {
// The first entry is a null entry as per the ELF spec.
- memset(buf, 0, sizeof(Elf_Sym));
buf += sizeof(Elf_Sym);
auto *eSym = reinterpret_cast<Elf_Sym *>(buf);
@@ -3720,10 +3718,6 @@ static uint8_t getAbiVersion() {
}
template <typename ELFT> void elf::writeEhdr(uint8_t *buf, Partition &part) {
- // For executable segments, the trap instructions are written before writing
- // the header. Setting Elf header bytes to zero ensures that any unused bytes
- // in header are zero-cleared, instead of having trap instructions.
- memset(buf, 0, sizeof(typename ELFT::Ehdr));
memcpy(buf, "\177ELF", 4);
auto *eHdr = reinterpret_cast<typename ELFT::Ehdr *>(buf);
More information about the llvm-commits
mailing list