From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2138) id A02873858D38; Mon, 25 Mar 2024 14:20:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A02873858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1711376415; bh=QQJFVmDUh8rAYIdvh7mejEYYA2mtAH9XCBrmz/qqwDc=; h=From:To:Subject:Date:From; b=mp93k8PIm0J6MYwe9VtJDfBJ4T2qLFOWDX2dBTToD6iF7Msu2ZqCxshFrbDL/Ed3t cP4vVkQdKYKQ9lmfGfe0nK7XplmASUc9Con08nzmlWEanvWpIt6kF6nGBbhgGU8mnL l7+QKaZnYc9NaF1S1d8iWHcb7ruh3Us+HWbIurzM= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Andreas Schwab To: glibc-cvs@sourceware.org Subject: [glibc] RISC-V: Fix the static-PIE non-relocated object check X-Act-Checkin: glibc X-Git-Author: Palmer Dabbelt X-Git-Refname: refs/heads/master X-Git-Oldrev: dc1a77269c971652a8a5167ec366792eae052e65 X-Git-Newrev: 96d1b9ac2321b565f340ba8f3674597141e3450d Message-Id: <20240325142015.A02873858D38@sourceware.org> Date: Mon, 25 Mar 2024 14:20:15 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=96d1b9ac2321b565f340ba8f3674597141e3450d commit 96d1b9ac2321b565f340ba8f3674597141e3450d Author: Palmer Dabbelt Date: Thu Feb 22 15:24:00 2024 -0800 RISC-V: Fix the static-PIE non-relocated object check The value of l_scope is only valid post relocation, so this original check was triggering undefined behavior. Instead just directly check to see if the object has been relocated, at which point using l_scope is safe. Reported-by: Andreas Schwab Closes: BZ #31317 Fixes: e0590f41fe ("RISC-V: Enable static-pie.") Signed-off-by: Palmer Dabbelt Diff: --- sysdeps/riscv/dl-machine.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h index 0cbb476c05..b2f28697f7 100644 --- a/sysdeps/riscv/dl-machine.h +++ b/sysdeps/riscv/dl-machine.h @@ -348,7 +348,7 @@ elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[], gotplt[1] = (ElfW(Addr)) l; } - if (l->l_type == lt_executable && l->l_scope != NULL) + if (l->l_type == lt_executable && l->l_relocated) { /* The __global_pointer$ may not be defined by the linker if the $gp register does not be used to access the global variable