Skip to content

Commit

Permalink
Do not create a PT_RISCV_ATTRIBUTES segment if .riscv.attributes is m…
Browse files Browse the repository at this point in the history
…issing
  • Loading branch information
rui314 committed Jul 30, 2023
1 parent 6d667fa commit ca14cdf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion elf/output-chunks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ static std::vector<ElfPhdr<E>> create_phdr(Context<E> &ctx) {

// Create a PT_RISCV_ATTRIBUTES
if constexpr (is_riscv<E>)
define(PT_RISCV_ATTRIBUTES, PF_R, 1, ctx.extra.riscv_attributes);
if (ctx.extra.riscv_attributes->shdr.sh_size)
define(PT_RISCV_ATTRIBUTES, PF_R, 1, ctx.extra.riscv_attributes);

// Create a PT_OPENBSD_RANDOMIZE
for (Chunk<E> *chunk : ctx.chunks)
Expand Down
14 changes: 14 additions & 0 deletions test/elf/riscv64_attributes2.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 -
void _start() {}
EOF

$STRIP --remove-section=.riscv.attributes $t/a.o

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

readelf -W --segments --sections $t/exe > $t/log
! grep -F .riscv.attributes $t/log || false
! grep -F RISCV_ATTR $t/log || false

0 comments on commit ca14cdf

Please sign in to comment.