[lld] a4c5db3 - [ELF] Remove redundant fillTrap and memset(*, 0, *). NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 16 22:37:36 PST 2022
Author: Fangrui Song
Date: 2022-01-16T22:37:31-08:00
New Revision: a4c5db30be4e216834b44e31b47304ea1b92635f
URL: https://github.com/llvm/llvm-project/commit/a4c5db30be4e216834b44e31b47304ea1b92635f
DIFF: https://github.com/llvm/llvm-project/commit/a4c5db30be4e216834b44e31b47304ea1b92635f.diff
LOG: [ELF] Remove redundant fillTrap and memset(*, 0, *). NFC
The new tests in build-id.s would catch problems if we made a mistake here.
Added:
Modified:
lld/ELF/SyntheticSections.cpp
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 2bb94b54bc1e..6069c603bacb 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -2398,11 +2398,6 @@ void GnuHashTableSection::finalizeContents() {
}
void GnuHashTableSection::writeTo(uint8_t *buf) {
- // The output buffer is not guaranteed to be zero-cleared because we pre-
- // fill executable sections with trap instructions. This is a precaution
- // for that case, which happens only when --no-rosegment is given.
- memset(buf, 0, size);
-
// Write a header.
write32(buf, nBuckets);
write32(buf + 4, getPartition().dynSymTab->getNumSymbols() - symbols.size());
@@ -2515,10 +2510,6 @@ void HashTableSection::finalizeContents() {
void HashTableSection::writeTo(uint8_t *buf) {
SymbolTableBaseSection *symTab = getPartition().dynSymTab.get();
-
- // See comment in GnuHashTableSection::writeTo.
- memset(buf, 0, size);
-
unsigned numSymbols = symTab->getNumSymbols();
uint32_t *p = reinterpret_cast<uint32_t *>(buf);
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 737863bb4208..ba69189eeccd 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -2851,8 +2851,8 @@ template <class ELFT> void Writer<ELFT>::writeTrapInstr() {
// Fill the last page.
for (PhdrEntry *p : part.phdrs)
if (p->p_type == PT_LOAD && (p->p_flags & PF_X))
- fillTrap(Out::bufferStart + alignDown(p->firstSec->offset + p->p_filesz,
- config->maxPageSize),
+ fillTrap(Out::bufferStart +
+ alignDown(p->firstSec->offset + p->p_filesz, 4),
Out::bufferStart + alignTo(p->firstSec->offset + p->p_filesz,
config->maxPageSize));
More information about the llvm-commits
mailing list