[gcc r15-10] RISC-V: Add -X to link spec

2024-04-26 Thread Fangrui Song via Gcc-cvs
https://gcc.gnu.org/g:50c218e3ffe57860591a987ecf44fcc0abb31f2c

commit r15-10-g50c218e3ffe57860591a987ecf44fcc0abb31f2c
Author: Fangrui Song 
Date:   Fri Apr 26 18:14:33 2024 -0700

RISC-V: Add -X to link spec

--discard-locals (-X) instructs the linker to remove local .L* symbols,
which occur a lot due to label differences for linker relaxation. The
arm port has a similar need and passes -X to ld.

In contrast, the RISC-V port does not pass -X to ld and rely on the
default --discard-locals in GNU ld's riscv port. The arm way is more
conventional (compiler driver instead of the linker customizes the
default linker behavior) and works with lld.

gcc/ChangeLog:

* config/riscv/elf.h (LINK_SPEC): Add -X.
* config/riscv/freebsd.h (LINK_SPEC): Add -X.
* config/riscv/linux.h (LINK_SPEC): Add -X.

Diff:
---
 gcc/config/riscv/elf.h | 1 +
 gcc/config/riscv/freebsd.h | 1 +
 gcc/config/riscv/linux.h   | 1 +
 3 files changed, 3 insertions(+)

diff --git a/gcc/config/riscv/elf.h b/gcc/config/riscv/elf.h
index f533764d9f8..c97f13c0cca 100644
--- a/gcc/config/riscv/elf.h
+++ b/gcc/config/riscv/elf.h
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #define LINK_SPEC "\
 -melf" XLEN_SPEC DEFAULT_ENDIAN_SPEC "riscv \
 %{mno-relax:--no-relax} \
+-X \
 %{mbig-endian:-EB} \
 %{mlittle-endian:-EL} \
 %{shared}"
diff --git a/gcc/config/riscv/freebsd.h b/gcc/config/riscv/freebsd.h
index bd08a985285..5dd4d51c42b 100644
--- a/gcc/config/riscv/freebsd.h
+++ b/gcc/config/riscv/freebsd.h
@@ -44,6 +44,7 @@ along with GCC; see the file COPYING3.  If not see
   %{p:%nconsider using `-pg' instead of `-p' with gprof (1)}   \
   %{v:-V}  \
   %{assert*} %{R*} %{rpath*} %{defsym*}\
+  -X   \
   %{mbig-endian:-EB}   \
   %{mlittle-endian:-EL}\
   %{shared:-Bshareable %{h*} %{soname*}}   \
diff --git a/gcc/config/riscv/linux.h b/gcc/config/riscv/linux.h
index 15851f653bc..3c356227134 100644
--- a/gcc/config/riscv/linux.h
+++ b/gcc/config/riscv/linux.h
@@ -50,6 +50,7 @@ along with GCC; see the file COPYING3.  If not see
 #define LINK_SPEC "\
 -melf" XLEN_SPEC DEFAULT_ENDIAN_SPEC "riscv" LD_EMUL_SUFFIX " \
 %{mno-relax:--no-relax} \
+-X \
 %{mbig-endian:-EB} \
 %{mlittle-endian:-EL} \
 %{shared} \


[gcc r15-4707] arm: Support -mfdpic for more targets

2024-10-27 Thread Fangrui Song via Gcc-cvs
https://gcc.gnu.org/g:8e6cc1e7cdbb431a0950e491ed2830213f3ad81b

commit r15-4707-g8e6cc1e7cdbb431a0950e491ed2830213f3ad81b
Author: Fangrui Song 
Date:   Sun Oct 27 12:37:21 2024 -0700

arm: Support -mfdpic for more targets

Targets that are not arm*-*-uclinuxfdpiceabi can use -S -mfdpic, but -c
-mfdpic does not pass --fdpic to gas.  This is an unnecessary
restriction.  Just define the ASM_SPEC in bpabi.h.

Additionally, use armelf[b]_linux_fdpiceabi emulations for -mfdpic in
linux-eabi.h.  This will allow a future musl fdpic port to use the
desired BFD emulation.

gcc/ChangeLog:

* config/arm/bpabi.h (TARGET_FDPIC_ASM_SPEC): Transform -mfdpic.
* config/arm/linux-eabi.h (TARGET_FDPIC_LINKER_EMULATION): Define.
(SUBTARGET_EXTRA_LINK_SPEC): Use TARGET_FDPIC_LINKER_EMULATION
if -mfdpic.

Diff:
---
 gcc/config/arm/bpabi.h  | 2 +-
 gcc/config/arm/linux-eabi.h | 5 -
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/gcc/config/arm/bpabi.h b/gcc/config/arm/bpabi.h
index 2e418fa91350..fd4b65a28afe 100644
--- a/gcc/config/arm/bpabi.h
+++ b/gcc/config/arm/bpabi.h
@@ -55,7 +55,7 @@
 #define TARGET_FIX_V4BX_SPEC " %{mcpu=arm8|mcpu=arm810|mcpu=strongarm*"\
   "|march=armv4|mcpu=fa526|mcpu=fa626:--fix-v4bx}"
 
-#define TARGET_FDPIC_ASM_SPEC ""
+#define TARGET_FDPIC_ASM_SPEC "%{mfdpic: --fdpic}"
 
 #define BE8_LINK_SPEC  \
   "%{!r:%{!mbe32:%:be8_linkopt(%{mlittle-endian:little}"   \
diff --git a/gcc/config/arm/linux-eabi.h b/gcc/config/arm/linux-eabi.h
index 50b753df9bcd..b12e4ff82cc3 100644
--- a/gcc/config/arm/linux-eabi.h
+++ b/gcc/config/arm/linux-eabi.h
@@ -46,12 +46,15 @@
 #undef  TARGET_LINKER_EMULATION
 #if TARGET_BIG_ENDIAN_DEFAULT
 #define TARGET_LINKER_EMULATION "armelfb_linux_eabi"
+#define TARGET_FDPIC_LINKER_EMULATION "armelfb_linux_fdpiceabi"
 #else
 #define TARGET_LINKER_EMULATION "armelf_linux_eabi"
+#define TARGET_FDPIC_LINKER_EMULATION "armelf_linux_fdpiceabi"
 #endif
 
 #undef  SUBTARGET_EXTRA_LINK_SPEC
-#define SUBTARGET_EXTRA_LINK_SPEC " -m " TARGET_LINKER_EMULATION
+#define SUBTARGET_EXTRA_LINK_SPEC " -m %{mfdpic: " \
+  TARGET_FDPIC_LINKER_EMULATION ";:" TARGET_LINKER_EMULATION "}"
 
 /* GNU/Linux on ARM currently supports three dynamic linkers:
- ld-linux.so.2 - for the legacy ABI


[gcc r15-6602] Respect -fprofile-prefix-map for getcwd in .gcno files

2025-01-06 Thread Fangrui Song via Gcc-cvs
https://gcc.gnu.org/g:fa778ba7d04497bdf32751488c8efd82db3b5e65

commit r15-6602-gfa778ba7d04497bdf32751488c8efd82db3b5e65
Author: Fangrui Song 
Date:   Tue Dec 31 16:32:07 2024 -0800

Respect -fprofile-prefix-map for getcwd in .gcno files

so that
`gcc -c a.cc --coverage -fprofile-prefix-map=$PWD=.`
does not emit $PWD in the generated a.gcno file.

gcc/ChangeLog:

PR gcov-profile/96092
* coverage.cc (coverage_init): Remap getpwd().

Diff:
---
 gcc/coverage.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/coverage.cc b/gcc/coverage.cc
index 20f26359e10d..7181e7573594 100644
--- a/gcc/coverage.cc
+++ b/gcc/coverage.cc
@@ -1341,7 +1341,7 @@ coverage_init (const char *filename)
  gcov_write_unsigned (bbg_file_stamp);
  /* Use an arbitrary checksum */
  gcov_write_unsigned (0);
- gcov_write_string (getpwd ());
+ gcov_write_string (remap_profile_filename (getpwd ()));
 
  /* Do not support has_unexecuted_blocks for Ada.  */
  gcov_write_unsigned (strcmp (lang_hooks.name, "GNU Ada") != 0);