From b20127377a602e853071a4f6d95d72e82543fcc0 Mon Sep 17 00:00:00 2001 From: Paul Floyd Date: Fri, 23 Feb 2024 09:33:24 +0100 Subject: [PATCH] FreeBSD: changes for building with GCC Use MARK_STACK_NO_EXEC (it's a null macro on non-linux platforms). GCC complains if it's not used. parse_procselfmaps yet again. The hack that I added in 6fdd59afb5e473b30e7ad1fbadcf9a397253fed4 only works for clang/ld.lld. This change makes it also work with GCC/ld.bfd. Still a hack though. --- coregrind/m_aspacemgr/aspacemgr-linux.c | 15 +++++++++++++-- include/pub_tool_basics_asm.h | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/coregrind/m_aspacemgr/aspacemgr-linux.c b/coregrind/m_aspacemgr/aspacemgr-linux.c index 22eefd30d..da3db87fc 100644 --- a/coregrind/m_aspacemgr/aspacemgr-linux.c +++ b/coregrind/m_aspacemgr/aspacemgr-linux.c @@ -3981,6 +3981,17 @@ static void parse_procselfmaps ( Int oid[4]; SysRes sres; Int map_count = 0; + // this assumes that compiling with clang uses ld.lld which produces 3 LOAD segements + // and that compiling with GCC uses ld.bfd which produces 2 LOAD segments +#if defined(__clang__) + Int const rx_map = 1; + Int const rw_map = 2; +#elif defined(__GNUC__) + Int const rx_map = 0; + Int const rw_map = 1; +#else +#error("unsupported compiler") +#endif // could copy the whole kinfo_vmentry but it is 1160 bytes char *rx_filename = NULL; ULong rx_dev = 0U; @@ -4024,7 +4035,7 @@ static void parse_procselfmaps ( map_count = (p - (char *)procmap_buf)/kve->kve_structsize; - if (tool_read_maps && map_count == 2) { + if (tool_read_maps && map_count == rw_map) { aspacem_assert((prot & (VKI_PROT_READ | VKI_PROT_WRITE)) == (VKI_PROT_READ | VKI_PROT_WRITE)); filename = rx_filename; dev = rx_dev; @@ -4041,7 +4052,7 @@ static void parse_procselfmaps ( foffset, filename, tool_read_maps && map_count == 2 ); } - if (tool_read_maps && map_count == 1) { + if (tool_read_maps && map_count == rx_map) { aspacem_assert((prot & (VKI_PROT_READ | VKI_PROT_EXEC)) == (VKI_PROT_READ | VKI_PROT_EXEC)); rx_filename = filename; rx_dev = dev; diff --git a/include/pub_tool_basics_asm.h b/include/pub_tool_basics_asm.h index 894fd1f5f..99f2ab18e 100644 --- a/include/pub_tool_basics_asm.h +++ b/include/pub_tool_basics_asm.h @@ -60,7 +60,7 @@ The call to MARK_STACK_NO_EXEC should be put unconditionally at the end of all asm source files. */ -#if defined(VGO_linux) +#if defined(VGO_linux) || defined(VGO_freebsd) # if defined(VGA_arm) # define MARK_STACK_NO_EXEC .section .note.GNU-stack,"",%progbits # else -- 2.11.4.GIT