Skip to content

Commit

Permalink
Do not count .tbss into account when creating PT_GNU_RELRO
Browse files Browse the repository at this point in the history
Fixes #1151
  • Loading branch information
rui314 committed Nov 21, 2023
1 parent 3cb8a52 commit de7d37e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
13 changes: 6 additions & 7 deletions elf/output-chunks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,12 @@ static std::vector<ElfPhdr<E>> create_phdr(Context<E> &ctx) {
// Create a PT_GNU_RELRO.
if (ctx.arg.z_relro) {
for (i64 i = 0; i < ctx.chunks.size(); i++) {
if (!ctx.chunks[i]->is_relro)
continue;

define(PT_GNU_RELRO, PF_R, 1, ctx.chunks[i++]);
while (i < ctx.chunks.size() && ctx.chunks[i]->is_relro)
append(ctx.chunks[i++]);
vec.back().p_align = 1;
if (ctx.chunks[i]->is_relro && !is_tbss(ctx.chunks[i])) {
define(PT_GNU_RELRO, PF_R, 1, ctx.chunks[i++]);
while (i < ctx.chunks.size() && ctx.chunks[i]->is_relro)
append(ctx.chunks[i++]);
vec.back().p_align = 1;
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions test/elf/tbss-only.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
. $(dirname $0)/common.inc

cat <<EOF | $CC -o $t/a.o -c -xc -
__thread char foo;
__attribute__((section(".data.rel.ro.bar"), aligned(16*1024)))
char bar;
int main() {}
EOF

$CC -B. -o $t/exe $t/a.o
$QEMU $t/exe

0 comments on commit de7d37e

Please sign in to comment.