From fede4a8102869981cb93576e9295b0111e1c39e7 Mon Sep 17 00:00:00 2001 From: Tatsuyuki Ishi Date: Sat, 20 Jan 2024 16:48:00 +0900 Subject: [PATCH] Ignore addrsig sections corrupted by strip When removing symbols, the indices in .llvm_addrsig also needs to be updated, but binutils is not aware of this and leaves the table in a corrupt state. Use the same test as what LLD uses to reject potentially corrupted addrsig sections. Unfortunately, testing this seems tricky. While producing a file with OOB addrsig index is not hard, it's hard to consistently trigger a segfault with that access. Signed-off-by: Tatsuyuki Ishi --- elf/input-files.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/elf/input-files.cc b/elf/input-files.cc index e6d43deabc..bb622d390b 100644 --- a/elf/input-files.cc +++ b/elf/input-files.cc @@ -356,7 +356,12 @@ void ObjectFile::initialize_sections(Context &ctx) { // Save .llvm_addrsig for --icf=safe. if (shdr.sh_type == SHT_LLVM_ADDRSIG && !ctx.arg.relocatable) { - llvm_addrsig = std::move(this->sections[i]); + if (shdr.sh_link != 0) { + llvm_addrsig = std::move(this->sections[i]); + } else { + Warn(ctx) << *this << ": Ignoring .llvm_addrsig section without SH_LINK; " << + "was the file processed by strip or objcopy -r?"; + } continue; }