[PATCH] D133107: [COFF] Don't generate -exclude-symbols for dllexported symbols

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 1 06:02:53 PDT 2022


mstorsjo created this revision.
mstorsjo added reviewers: rnk, mati865, MaskRay.
Herald added subscribers: StephenFan, pengfei, hiraditya.
Herald added a project: All.
mstorsjo requested review of this revision.
Herald added a project: LLVM.

A symbol can end up both with hidden visibility and a dllexport
attribute (in builds that set global flags like -fvisibility=hidden
or similar). In such cases, the hidden visibility doesn't have any
effect, as the dllexport directives take precedence, and no
autoexporting of all eligible symbols take place.

Therefore, it's entirely redundant to produce both -export: and
-exclude-symbols: for such a symbol - only produce export.

Even if an object file does contain one or more -export: directives,
it's relevant to include -exclude-symbols: for all other hidden
symbols though, because the linker could be invoked with
--export-all-symbols.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133107

Files:
  llvm/lib/IR/Mangler.cpp
  llvm/test/CodeGen/X86/mingw-hidden.ll


Index: llvm/test/CodeGen/X86/mingw-hidden.ll
===================================================================
--- llvm/test/CodeGen/X86/mingw-hidden.ll
+++ llvm/test/CodeGen/X86/mingw-hidden.ll
@@ -17,6 +17,11 @@
 	ret void
 }
 
+; CHECK: .globl _exportedHidden
+define hidden dllexport void @exportedHidden() {
+	ret void
+}
+
 ; CHECK: .globl _f2
 define hidden void @f2() unnamed_addr {
 	ret void
@@ -67,9 +72,12 @@
 ; NOTEXPORTED-NOT: :notHidden
 ; NOTEXPORTED-NOT: :notDefined
 
-; CHECK-MSVC-NOT: .section .drectve
+; CHECK-MSVC: .section .drectve
+; CHECK-MSVC: .ascii " /EXPORT:_exportedHidden"
 ; CHECK-MINGW: .section .drectve
 ; CHECK-MINGW: .ascii " -exclude-symbols:f1"
+; CHECK-MINGW: .ascii " -export:exportedHidden"
+; CHECK-MINGW-NOT: -exclude-symbols:exportedHidden
 ; CHECK-MINGW: .ascii " -exclude-symbols:f2"
 ; CHECK-MINGW: .ascii " -exclude-symbols:stdfun at 0"
 ; CHECK-MINGW: .ascii " -exclude-symbols:lnk1"
Index: llvm/lib/IR/Mangler.cpp
===================================================================
--- llvm/lib/IR/Mangler.cpp
+++ llvm/lib/IR/Mangler.cpp
@@ -241,8 +241,8 @@
       else
         OS << ",data";
     }
-  }
-  if (GV->hasHiddenVisibility() && !GV->isDeclaration() && TT.isOSCygMing()) {
+  } else if (GV->hasHiddenVisibility() && !GV->isDeclaration() &&
+             TT.isOSCygMing()) {
 
     OS << " -exclude-symbols:";
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133107.457245.patch
Type: text/x-patch
Size: 1375 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220901/c8dfb8fc/attachment-0001.bin>


More information about the llvm-commits mailing list