[all-commits] [llvm/llvm-project] c324c9: [Driver] Pass -X to ld for riscv*-{elf, freebsd, linux}

Fangrui Song via All-commits all-commits at lists.llvm.org
Thu Jun 16 23:34:02 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: c324c938becdbb963b34895cc12ffccb261bf167
      https://github.com/llvm/llvm-project/commit/c324c938becdbb963b34895cc12ffccb261bf167
  Author: Fangrui Song <i at maskray.me>
  Date:   2022-06-16 (Thu, 16 Jun 2022)

  Changed paths:
    M clang/lib/Driver/ToolChains/FreeBSD.cpp
    M clang/lib/Driver/ToolChains/Gnu.cpp
    M clang/lib/Driver/ToolChains/RISCVToolchain.cpp
    M clang/test/Driver/riscv32-toolchain.c
    M clang/test/Driver/riscv64-toolchain.c

  Log Message:
  -----------
  [Driver] Pass -X to ld for riscv*-{elf,freebsd,linux}

GNU ld has a hack that defaults to -X (--discard-locals) in the emulation file
`riscvelf.em`. The recommended way, as gcc/config/arm does, is to let the
compiler driver pass -X to ld.
(The motivation is likely to discard a plethora of `.L` symbols due to linker
relaxation.)

lld default to --discard-none. To make clang+lld match GNU ld's behavior, pass
-X to ld.

Note: GNU ld has a special rule to treat ld -r -s as ld -r -S -x. With -X, driver `-r -Wl,-s`
will behave as ld `-r -S -X`. This removes fewer symbols than `-r -S -x` but is safe.

Differential Revision: https://reviews.llvm.org/D127826




More information about the All-commits mailing list