[libcxx-commits] [llvm] [libcxx] [compiler-rt] [lldb] [lld] [lld-macho] Find objects in library search path (PR #78628)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jan 19 08:58:14 PST 2024
https://github.com/OldWorldOrdr updated https://github.com/llvm/llvm-project/pull/78628
>From e73fc2d0263e9e601f2964a90cfe347e8d2bb87c Mon Sep 17 00:00:00 2001
From: OldWorldOrdr <joey.t.reinhart at gmail.com>
Date: Thu, 18 Jan 2024 16:20:52 -0500
Subject: [PATCH 1/5] [lld-macho] Find objects in library search path
---
lld/MachO/Driver.cpp | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 401459a054394e..f04165f5c02615 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -95,11 +95,16 @@ static std::optional<StringRef> findLibrary(StringRef name) {
findPathCombination("lib" + name, config->librarySearchPaths,
{".tbd", ".dylib", ".so"}))
return path;
- return findPathCombination("lib" + name, config->librarySearchPaths,
- {".a"});
+ else if (std::optional<StringRef> path = findPathCombination(
+ "lib" + name, config->librarySearchPaths, {".a"}))
+ return path;
+ return findPathCombination(name, config->librarySearchPaths, {""});
}
- return findPathCombination("lib" + name, config->librarySearchPaths,
- {".tbd", ".dylib", ".so", ".a"});
+ if (std::optional<StringRef> path =
+ findPathCombination("lib" + name, config->librarySearchPaths,
+ {".tbd", ".dylib", ".so", ".a"}))
+ return path;
+ return findPathCombination(name, config->librarySearchPaths, {""});
};
std::optional<StringRef> path = doFind();
>From 5b29c5da6770982fb2f36edcd3a367893b18a19d Mon Sep 17 00:00:00 2001
From: OldWorldOrdr <joey.t.reinhart at gmail.com>
Date: Thu, 18 Jan 2024 21:16:57 -0500
Subject: [PATCH 2/5] [lld-macho] find objects in library search path version 2
---
lld/MachO/Driver.cpp | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index f04165f5c02615..f8b01da5255c6d 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -90,21 +90,19 @@ static std::optional<StringRef> findLibrary(StringRef name) {
return entry->second;
auto doFind = [&] {
+ // Special case for Csu support files.
+ if (name.ends_with(".o"))
+ return findPathCombination(name, config->librarySearchPaths, {""});
if (config->searchDylibsFirst) {
if (std::optional<StringRef> path =
findPathCombination("lib" + name, config->librarySearchPaths,
{".tbd", ".dylib", ".so"}))
return path;
- else if (std::optional<StringRef> path = findPathCombination(
- "lib" + name, config->librarySearchPaths, {".a"}))
- return path;
- return findPathCombination(name, config->librarySearchPaths, {""});
+ return findPathCombination("lib" + name, config->librarySearchPaths,
+ {".a"});
}
- if (std::optional<StringRef> path =
- findPathCombination("lib" + name, config->librarySearchPaths,
- {".tbd", ".dylib", ".so", ".a"}))
- return path;
- return findPathCombination(name, config->librarySearchPaths, {""});
+ return findPathCombination("lib" + name, config->librarySearchPaths,
+ {".tbd", ".dylib", ".so", ".a"});
};
std::optional<StringRef> path = doFind();
>From 5aab87e5c580ca1dba654fb00cf9571c7e3c7999 Mon Sep 17 00:00:00 2001
From: OldWorldOrdr <joey.t.reinhart at gmail.com>
Date: Fri, 19 Jan 2024 01:32:20 -0500
Subject: [PATCH 3/5] add test case
---
lld/test/MachO/link-csu-obj.s | 10 ++++++++++
1 file changed, 10 insertions(+)
create mode 100644 lld/test/MachO/link-csu-obj.s
diff --git a/lld/test/MachO/link-csu-obj.s b/lld/test/MachO/link-csu-obj.s
new file mode 100644
index 00000000000000..00cb26bb260743
--- /dev/null
+++ b/lld/test/MachO/link-csu-obj.s
@@ -0,0 +1,10 @@
+# REQUIRES: x86
+# RUN: mkdir -p %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/libhello.s -o %t/hello.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/main.o
+# RUN: %lld -L %t %t/main.o %t/hello.o -o %t/a.out
+
+.globl _main
+_main:
+ call _print_hello
+ ret
>From e5c118067bd049da924010b26fe420267567eade Mon Sep 17 00:00:00 2001
From: OldWorldOrdr <joey.t.reinhart at gmail.com>
Date: Fri, 19 Jan 2024 11:38:25 -0500
Subject: [PATCH 4/5] Update Driver.cpp
---
lld/MachO/Driver.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index f8b01da5255c6d..97937d5107e667 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -90,7 +90,7 @@ static std::optional<StringRef> findLibrary(StringRef name) {
return entry->second;
auto doFind = [&] {
- // Special case for Csu support files.
+ // Special case for Csu support files that are required for Mac OS X 10.7 and older (crt1.o)
if (name.ends_with(".o"))
return findPathCombination(name, config->librarySearchPaths, {""});
if (config->searchDylibsFirst) {
>From 91572d43bb763fa03bf2a51d51aba2a6c27cd967 Mon Sep 17 00:00:00 2001
From: OldWorldOrdr <joey.t.reinhart at gmail.com>
Date: Fri, 19 Jan 2024 11:58:04 -0500
Subject: [PATCH 5/5] Update Driver.cpp
---
lld/MachO/Driver.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 97937d5107e667..7ac3f51cec103f 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -90,7 +90,8 @@ static std::optional<StringRef> findLibrary(StringRef name) {
return entry->second;
auto doFind = [&] {
- // Special case for Csu support files that are required for Mac OS X 10.7 and older (crt1.o)
+ // Special case for Csu support files required for Mac OS X 10.7 and older
+ // (crt1.o)
if (name.ends_with(".o"))
return findPathCombination(name, config->librarySearchPaths, {""});
if (config->searchDylibsFirst) {
More information about the libcxx-commits
mailing list