Skip to content

Commit

Permalink
RISC-V: Add -X to link spec
Browse files Browse the repository at this point in the history
--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.

(cherry picked from commit 50c218e)
  • Loading branch information
MaskRay authored and kito-cheng committed Jul 19, 2024
1 parent 92003fa commit 3a7e796
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions gcc/config/riscv/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
1 change: 1 addition & 0 deletions gcc/config/riscv/freebsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*}} \
Expand Down
1 change: 1 addition & 0 deletions gcc/config/riscv/linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
Expand Down

0 comments on commit 3a7e796

Please sign in to comment.