From ca14cdf9b6b91b063b0907cc94b1e4cdacaa368c Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sun, 30 Jul 2023 11:36:35 +0900 Subject: [PATCH] Do not create a PT_RISCV_ATTRIBUTES segment if .riscv.attributes is missing --- elf/output-chunks.cc | 3 ++- test/elf/riscv64_attributes2.sh | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100755 test/elf/riscv64_attributes2.sh diff --git a/elf/output-chunks.cc b/elf/output-chunks.cc index 5895de7a90..84da128bff 100644 --- a/elf/output-chunks.cc +++ b/elf/output-chunks.cc @@ -355,7 +355,8 @@ static std::vector> create_phdr(Context &ctx) { // Create a PT_RISCV_ATTRIBUTES if constexpr (is_riscv) - 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 *chunk : ctx.chunks) diff --git a/test/elf/riscv64_attributes2.sh b/test/elf/riscv64_attributes2.sh new file mode 100755 index 0000000000..ee108a7c63 --- /dev/null +++ b/test/elf/riscv64_attributes2.sh @@ -0,0 +1,14 @@ +#!/bin/bash +. $(dirname $0)/common.inc + +cat < $t/log +! grep -F .riscv.attributes $t/log || false +! grep -F RISCV_ATTR $t/log || false