[all-commits] [llvm/llvm-project] fa8aad: [Driver] Fix link order of BareMetal toolchain object

Garvit Gupta via All-commits all-commits at lists.llvm.org
Tue Jun 17 10:37:45 PDT 2025


  Branch: refs/heads/users/quic-garvgupt/link_order
  Home:   https://github.com/llvm/llvm-project
  Commit: fa8aad1e9df9b21696fea33de4678a809a13367c
      https://github.com/llvm/llvm-project/commit/fa8aad1e9df9b21696fea33de4678a809a13367c
  Author: Garvit Gupta <quic_garvgupt at quicinc.com>
  Date:   2025-06-17 (Tue, 17 Jun 2025)

  Changed paths:
    M clang/lib/Driver/ToolChains/BareMetal.cpp
    M clang/test/Driver/aarch64-toolchain-extra.c
    M clang/test/Driver/aarch64-toolchain.c
    M clang/test/Driver/arm-toolchain-extra.c
    M clang/test/Driver/arm-toolchain.c
    M clang/test/Driver/baremetal-multilib.yaml
    M clang/test/Driver/baremetal-sysroot.cpp
    M clang/test/Driver/baremetal.cpp

  Log Message:
  -----------
  [Driver] Fix link order of BareMetal toolchain object

The linker job in BareMetal toolchain object will be used by gnuld and lld both.
However, gnuld process the arguments in the order in which they appear on command
line, whereas there is no such restriction with lld.

The previous order was:
LibraryPaths -> Libraries -> LTOOptions -> LinkerInputs
The new iorder is:
LibraryPaths -> LTOOptions -> LinkerInputs -> Libraries

LTO options need to be added before adding any linker inputs because file format
after compile stage during LTO is bitcode which gnuld natively cannot process.
Hence iwill need to pass appropriate plugins before adding any bitcode file on the
command line.

Object files that are getting linked need to be passed before processing any
libraries so that gnuld can appropriately do symbol resolution for the symbols
for which no definition is provided through user code.

Similar link order is also followed by other linker jobs for gnuld such as in
gnutools::Linker in Gnu.cpp

This is the 3rd patch in the series of patches of merging RISCVToolchain into
BareMetal toolchain object.

RFC:
https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524

Change-Id: I0e68e403c08b5687cc3346e833981f7b9f3819c4



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list