[PATCH] D119506: [lld-macho] Set FinalDefinitionInLinkageUnit on most LTO externs
Jez Ng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 15 10:59:26 PDT 2022
int3 updated this revision to Diff 415504.
int3 added a comment.
update
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D119506/new/
https://reviews.llvm.org/D119506
Files:
lld/MachO/LTO.cpp
lld/test/MachO/lto-final-definition.ll
lld/test/MachO/lto-internalize.ll
Index: lld/test/MachO/lto-internalize.ll
===================================================================
--- lld/test/MachO/lto-internalize.ll
+++ lld/test/MachO/lto-internalize.ll
@@ -17,7 +17,7 @@
;; Check that main is not internalized. This covers the case of bitcode symbols
;; referenced by undefined symbols that don't belong to any InputFile.
-; CHECK: define void @main()
+; CHECK: define dso_local void @main()
;; Check that the foo and bar functions are correctly internalized.
; CHECK: define internal void @bar()
@@ -25,7 +25,7 @@
;; Check that a bitcode symbol that is referenced by a regular object file isn't
;; internalized.
-; CHECK: define void @used_in_regular_obj()
+; CHECK: define dso_local void @used_in_regular_obj()
;; Check that a bitcode symbol that is defined in another bitcode file gets
;; internalized.
@@ -51,13 +51,13 @@
;; Note that only foo() gets internalized here; everything else that isn't
;; hidden must be exported.
-; DYN: @comm = common global
+; DYN: @comm = common dso_local global
; DYN: @comm_hide = internal global
-; DYN: define void @main()
-; DYN: define void @bar()
+; DYN: define dso_local void @main()
+; DYN: define dso_local void @bar()
; DYN: define internal void @foo()
-; DYN: define void @used_in_regular_obj()
-; DYN: define void @baz()
+; DYN: define dso_local void @used_in_regular_obj()
+; DYN: define dso_local void @baz()
; DYN-SYMS-DAG: (__TEXT,__text) external _bar
; DYN-SYMS-DAG: (__TEXT,__text) external _baz
Index: lld/test/MachO/lto-final-definition.ll
===================================================================
--- /dev/null
+++ lld/test/MachO/lto-final-definition.ll
@@ -0,0 +1,27 @@
+; REQUIRES: x86
+; RUN: rm -rf %t; mkdir %t
+; RUN: llvm-as %s -o %t/test.o
+; RUN: %lld -lSystem -dylib %t/test.o -o %t/test -save-temps
+; RUN: llvm-dis %t/test.0.2.internalize.bc -o - | FileCheck %s
+; RUN: %lld -lSystem -dylib %t/test.o -o %t/flat-namespace.dylib -save-temps \
+; RUN: -flat_namespace
+; RUN: llvm-dis %t/flat-namespace.dylib.0.2.internalize.bc -o - | FileCheck %s \
+; RUN: --check-prefix=NO-DSO-LOCAL
+
+;; f() is never dso_local since it is a weak external.
+; CHECK: define weak_odr void @f()
+; CHECK: define dso_local void @main()
+
+; NO-DSO-LOCAL: define weak_odr void @f()
+; NO-DSO-LOCAL: define void @main()
+
+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"
+
+define weak_odr void @f() {
+ ret void
+}
+
+define void @main() {
+ ret void
+}
Index: lld/MachO/LTO.cpp
===================================================================
--- lld/MachO/LTO.cpp
+++ lld/MachO/LTO.cpp
@@ -79,11 +79,15 @@
// be removed.
r.Prevailing = !objSym.isUndefined() && sym->getFile() == &f;
- if (const auto *defined = dyn_cast<Defined>(sym))
+ if (const auto *defined = dyn_cast<Defined>(sym)) {
r.ExportDynamic =
defined->isExternal() && !defined->privateExtern && exportDynamic;
- else if (const auto *common = dyn_cast<CommonSymbol>(sym))
+ r.FinalDefinitionInLinkageUnit =
+ !defined->isExternalWeakDef() && !defined->interposable;
+ } else if (const auto *common = dyn_cast<CommonSymbol>(sym)) {
r.ExportDynamic = !common->privateExtern && exportDynamic;
+ r.FinalDefinitionInLinkageUnit = true;
+ }
r.VisibleToRegularObj =
sym->isUsedInRegularObj || (r.Prevailing && r.ExportDynamic);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119506.415504.patch
Type: text/x-patch
Size: 3507 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220315/3a2f6735/attachment.bin>
More information about the llvm-commits
mailing list