Skip to content

Commit 97a1cb9

Browse files
androm3datru
authored andcommitted
[clang] hexagon: fix link order for libc/builtins (#117057)
When linking programs with `eld`, we get a link error like below: Error: /inst/clang+llvm-19.1.0-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/bin/../target/hexagon-unknown-linux-musl//usr/lib/libc.a(scalbn.lo)(.text.scalbn+0x3c): undefined reference to `__hexagon_muldf3' libc has references to the clang_rt builtins library, so the order of the libraries should be reversed. (cherry picked from commit 9cc2502)
1 parent 6553889 commit 97a1cb9

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

clang/lib/Driver/ToolChains/Hexagon.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,9 @@ constructHexagonLinkArgs(Compilation &C, const JobAction &JA,
379379
if (NeedsXRayDeps)
380380
linkXRayRuntimeDeps(HTC, Args, CmdArgs);
381381

382-
CmdArgs.push_back("-lclang_rt.builtins-hexagon");
383382
if (!Args.hasArg(options::OPT_nolibc))
384383
CmdArgs.push_back("-lc");
384+
CmdArgs.push_back("-lclang_rt.builtins-hexagon");
385385
}
386386
if (D.CCCIsCXX()) {
387387
if (HTC.ShouldLinkCXXStdlib(Args))

clang/test/Driver/hexagon-toolchain-linux.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// CHECK000-NOT: {{.*}}basic_linux_libcxx_tree{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}crti.o
1212
// CHECK000: "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
1313
// CHECK000: "{{.*}}basic_linux_libcxx_tree{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}crt1.o"
14-
// CHECK000: "-lclang_rt.builtins-hexagon" "-lc"
14+
// CHECK000: "-lc" "-lclang_rt.builtins-hexagon"
1515
// -----------------------------------------------------------------------------
1616
// Passing --musl --shared
1717
// -----------------------------------------------------------------------------
@@ -21,7 +21,7 @@
2121
// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree -shared %s 2>&1 | FileCheck -check-prefix=CHECK001 %s
2222
// CHECK001-NOT: -dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1
2323
// CHECK001: "{{.*}}basic_linux_libcxx_tree{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}crti.o"
24-
// CHECK001: "-lclang_rt.builtins-hexagon" "-lc"
24+
// CHECK001: "-lc" "-lclang_rt.builtins-hexagon"
2525
// CHECK001-NOT: {{.*}}basic_linux_libcxx_tree{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}crt1.o
2626
// -----------------------------------------------------------------------------
2727
// Passing --musl -nostdlib
@@ -33,8 +33,8 @@
3333
// CHECK002: "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
3434
// CHECK002-NOT: {{.*}}basic_linux_libcxx_tree{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}crti.o
3535
// CHECK002-NOT: {{.*}}basic_linux_libcxx_tree{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}crt1.o
36-
// CHECK002-NOT: "-lclang_rt.builtins-hexagon"
3736
// CHECK002-NOT: "-lc"
37+
// CHECK002-NOT: "-lclang_rt.builtins-hexagon"
3838
// -----------------------------------------------------------------------------
3939
// Passing --musl -nostartfiles
4040
// -----------------------------------------------------------------------------
@@ -45,7 +45,7 @@
4545
// CHECK003: "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
4646
// CHECK003-NOT: {{.*}}basic_linux_libcxx_tree{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}Scrt1.o
4747
// CHECK003-NOT: {{.*}}basic_linux_libcxx_tree{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}crt1.o
48-
// CHECK003: "-lclang_rt.builtins-hexagon" "-lc"
48+
// CHECK003: "-lc" "-lclang_rt.builtins-hexagon"
4949
// -----------------------------------------------------------------------------
5050
// Passing --musl -nodefaultlibs
5151
// -----------------------------------------------------------------------------
@@ -55,8 +55,8 @@
5555
// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree -nodefaultlibs %s 2>&1 | FileCheck -check-prefix=CHECK004 %s
5656
// CHECK004: "-dynamic-linker={{/|\\\\}}lib{{/|\\\\}}ld-musl-hexagon.so.1"
5757
// CHECK004: "{{.*}}basic_linux_libcxx_tree{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}crt1.o"
58-
// CHECK004-NOT: "-lclang_rt.builtins-hexagon"
5958
// CHECK004-NOT: "-lc"
59+
// CHECK004-NOT: "-lclang_rt.builtins-hexagon"
6060
// -----------------------------------------------------------------------------
6161
// Passing --musl -nolibc
6262
// -----------------------------------------------------------------------------

0 commit comments

Comments
 (0)