Skip to content

Commit

Permalink
Drop SHF_COMPRESSED when creating a relocatable file
Browse files Browse the repository at this point in the history
We always uncompress compressed sections when copying, so we should
not propagate the flag.

Fixes #1195
  • Loading branch information
rui314 committed Feb 19, 2024
1 parent 64c2084 commit b0a3a5c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion elf/output-chunks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ OutputSection<E>::OutputSection(Context<E> &ctx, std::string_view name,
u32 type, u64 flags) {
this->name = name;
this->shdr.sh_type = type;
this->shdr.sh_flags = flags & ~SHF_MERGE & ~SHF_STRINGS;
this->shdr.sh_flags = flags & ~SHF_MERGE & ~SHF_STRINGS & ~SHF_COMPRESSED;

if (auto it = ctx.arg.section_align.find(name);
it != ctx.arg.section_align.end())
Expand Down
19 changes: 19 additions & 0 deletions test/elf/relocatable-compressed-debug-info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
. $(dirname $0)/common.inc

# OneTBB isn't tsan-clean
nm mold | grep -q '__tsan_init' && skip

cat <<EOF | $GCC -c -o $t/a.o -xc - -g3 -gz
#include <stdio.h>
void hello() { printf("Hello world\n"); }
EOF

cat <<EOF | $GCC -c -o $t/b.o -xc - -g3 -gz
void hello();
int main() { hello(); }
EOF

./mold --relocatable -o $t/c.o $t/a.o $t/b.o
$CC -B. -o $t/exe $t/c.o
$QEMU $t/exe

0 comments on commit b0a3a5c

Please sign in to comment.