Skip to content

Commit

Permalink
Ignore addrsig sections corrupted by strip
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ishitatsuyuki committed Jan 20, 2024
1 parent 29c0baa commit fede4a8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion elf/input-files.cc
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,12 @@ void ObjectFile<E>::initialize_sections(Context<E> &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;
}

Expand Down

0 comments on commit fede4a8

Please sign in to comment.