diff mbox series

asan: Do not call asan_function_start () without the current function [PR113251]

Message ID 20240108092434.554918-1-iii@linux.ibm.com
State New
Headers show
Series asan: Do not call asan_function_start () without the current function [PR113251] | expand

Commit Message

Ilya Leoshkevich Jan. 8, 2024, 9:22 a.m. UTC
Bootstrap and regtest running on x86_64-redhat-linux,
ppc64le-redhat-linux and s390x-redhat-linux.  Ok for trunk when
successful?



Using ASAN on i686-linux with -fPIC causes an ICE, because when
pc_thunks are generated, there is no current function anymore, but
asan_function_start () expects one.

Fix by not calling asan_function_start () without one.

A narrower fix would be to temporarily disable ASAN around pc_thunk
generation.  However, the issue looks generic enough, and may affect
less often tested configurations, so go for a broader fix.

Fixes: e66dc37b299c ("asan: Align .LASANPC on function boundary")
Suggested-by: Jakub Jelinek <jakub@redhat.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>

gcc/ChangeLog:

	PR sanitizer/113251
	* varasm.cc (assemble_function_label_raw): Do not call
	asan_function_start () without the current function.
---
 gcc/varasm.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Jakub Jelinek Jan. 8, 2024, 9:34 a.m. UTC | #1
On Mon, Jan 08, 2024 at 10:22:57AM +0100, Ilya Leoshkevich wrote:
> Bootstrap and regtest running on x86_64-redhat-linux,
> ppc64le-redhat-linux and s390x-redhat-linux.  Ok for trunk when
> successful?
> 
> 
> 
> Using ASAN on i686-linux with -fPIC causes an ICE, because when
> pc_thunks are generated, there is no current function anymore, but
> asan_function_start () expects one.
> 
> Fix by not calling asan_function_start () without one.
> 
> A narrower fix would be to temporarily disable ASAN around pc_thunk
> generation.  However, the issue looks generic enough, and may affect
> less often tested configurations, so go for a broader fix.
> 
> Fixes: e66dc37b299c ("asan: Align .LASANPC on function boundary")
> Suggested-by: Jakub Jelinek <jakub@redhat.com>
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> 
> gcc/ChangeLog:
> 
> 	PR sanitizer/113251
> 	* varasm.cc (assemble_function_label_raw): Do not call
> 	asan_function_start () without the current function.

LGTM, thanks.

	Jakub
diff mbox series

Patch

diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index 25c1e05628d..1a869ae458a 100644
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -1845,7 +1845,9 @@  assemble_function_label_raw (FILE *file, const char *name)
   ASM_OUTPUT_LABEL (file, name);
   if ((flag_sanitize & SANITIZE_ADDRESS)
       /* Notify ASAN only about the first function label.  */
-      && (in_cold_section_p == first_function_block_is_cold))
+      && (in_cold_section_p == first_function_block_is_cold)
+      /* Do not notify ASAN when called from, e.g., code_end ().  */
+      && cfun)
     asan_function_start ();
 }