[lld] eeac6b2 - [lld-macho] Handle multiple LC_LINKER_OPTIONs
Jez Ng via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 16 12:23:29 PDT 2021
Author: Jez Ng
Date: 2021-06-16T15:23:06-04:00
New Revision: eeac6b2beceeb82382354d730b615159af3bc70e
URL: https://github.com/llvm/llvm-project/commit/eeac6b2beceeb82382354d730b615159af3bc70e
DIFF: https://github.com/llvm/llvm-project/commit/eeac6b2beceeb82382354d730b615159af3bc70e.diff
LOG: [lld-macho] Handle multiple LC_LINKER_OPTIONs
We previously only parsed the first one.
Reviewed By: #lld-macho, thakis
Differential Revision: https://reviews.llvm.org/D104352
Added:
Modified:
lld/MachO/InputFiles.cpp
lld/test/MachO/lc-linker-option.ll
Removed:
################################################################################
diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index 097cf6172e66f..2fc08ff911c2f 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -702,11 +702,10 @@ template <class LP> void ObjFile::parse() {
if (!checkCompatibility(this))
return;
- if (const load_command *cmd = findCommand(hdr, LC_LINKER_OPTION)) {
- auto *c = reinterpret_cast<const linker_option_command *>(cmd);
- StringRef data{reinterpret_cast<const char *>(c + 1),
- c->cmdsize - sizeof(linker_option_command)};
- parseLCLinkerOption(this, c->count, data);
+ for (auto *cmd : findCommands<linker_option_command>(hdr, LC_LINKER_OPTION)) {
+ StringRef data{reinterpret_cast<const char *>(cmd + 1),
+ cmd->cmdsize - sizeof(linker_option_command)};
+ parseLCLinkerOption(this, cmd->count, data);
}
ArrayRef<Section> sectionHeaders;
diff --git a/lld/test/MachO/lc-linker-option.ll b/lld/test/MachO/lc-linker-option.ll
index 7bcef677ae36d..e80ccf6ade767 100644
--- a/lld/test/MachO/lc-linker-option.ll
+++ b/lld/test/MachO/lc-linker-option.ll
@@ -15,6 +15,8 @@
; RUN: llvm-as %t/l.ll -o %t/l.o
;; The dynamic call to _CFBigNumGetInt128 uses dyld_stub_binder,
;; which needs -lSystem from LC_LINKER_OPTION to get resolved.
+;; The reference to __cxa_allocate_exception will require -lc++ from
+;; LC_LINKER_OPTION to get resolved.
; RUN: %lld %t/l.o -o %t/l -framework CoreFoundation
; RUN: llvm-otool -l %t/l | FileCheck --check-prefix=LIB %s \
; RUN: --implicit-check-not LC_LOAD_DYLIB
@@ -24,12 +26,24 @@
; LIB: cmd LC_LOAD_DYLIB
; LIB-NEXT: cmdsize
; LIB-NEXT: name /usr/lib/libSystem.dylib
+; LIB: cmd LC_LOAD_DYLIB
+; LIB-NEXT: cmdsize
+; LIB-NEXT: name /usr/lib/libc++abi.dylib
;; Check that we don't create duplicate LC_LOAD_DYLIBs.
; RUN: %lld -lSystem %t/l.o -o %t/l -framework CoreFoundation
-; RUN: llvm-otool -l %t/l | FileCheck --check-prefix=FRAME %s \
+; RUN: llvm-otool -l %t/l | FileCheck --check-prefix=LIB2 %s \
; RUN: --implicit-check-not LC_LOAD_DYLIB
-;
+; LIB2: cmd LC_LOAD_DYLIB
+; LIB2-NEXT: cmdsize
+; LIB2-NEXT: name /usr/lib/libSystem.dylib
+; LIB2: cmd LC_LOAD_DYLIB
+; LIB2-NEXT: cmdsize
+; LIB2-NEXT: name /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
+; LIB2: cmd LC_LOAD_DYLIB
+; LIB2-NEXT: cmdsize
+; LIB2-NEXT: name /usr/lib/libc++abi.dylib
+
; RUN: llvm-as %t/invalid.ll -o %t/invalid.o
; RUN: not %lld %t/invalid.o -o /dev/null 2>&1 | FileCheck --check-prefix=INVALID %s
; INVALID: error: -why_load is not allowed in LC_LINKER_OPTION
@@ -53,12 +67,15 @@ target triple = "x86_64-apple-macosx10.15.0"
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
!0 = !{!"-lSystem"}
-!llvm.linker.options = !{!0, !0}
+!1 = !{!"-lc++"}
+!llvm.linker.options = !{!0, !0, !1}
declare void @_CFBigNumGetInt128(...)
+declare i8* @__cxa_allocate_exception(i64)
define void @main() {
call void bitcast (void (...)* @_CFBigNumGetInt128 to void ()*)()
+ call i8* @__cxa_allocate_exception(i64 4)
ret void
}
More information about the llvm-commits
mailing list