-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[Object][COFF] Avoid underscore prefix for forwarding exports #135433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-lld @llvm/pr-subscribers-lld-coff Author: Jacek Caban (cjacek) ChangesFixes #132411. Full diff: https://github.com/llvm/llvm-project/pull/135433.diff 3 Files Affected:
diff --git a/lld/test/COFF/export-alias.test b/lld/test/COFF/export-alias.test
new file mode 100644
index 0000000000000..a13fdf1504fb2
--- /dev/null
+++ b/lld/test/COFF/export-alias.test
@@ -0,0 +1,16 @@
+; REQUIRES: x86
+
+; RUN: echo > %t.s
+; RUN: llvm-mc -filetype=obj -triple=i686-windows %t.s -o %t.obj
+; RUN: lld-link -machine:x86 -dll -noentry -safeseh:no -out:%t.dll -def:%s %t.obj
+; RUN: llvm-readobj --coff-exports %t.dll | FileCheck %s
+
+; CHECK: Export {
+; CHECK-NEXT: Ordinal: 1
+; CHECK-NEXT: Name: func
+; CHECK-NEXT: ForwardedTo: other.dll.func
+; CHECK-NEXT: }
+
+LIBRARY test.dll
+EXPORTS
+ func = other.dll.func
diff --git a/llvm/lib/Object/COFFModuleDefinition.cpp b/llvm/lib/Object/COFFModuleDefinition.cpp
index 82c18539658e8..67b0dc4fa2976 100644
--- a/llvm/lib/Object/COFFModuleDefinition.cpp
+++ b/llvm/lib/Object/COFFModuleDefinition.cpp
@@ -238,7 +238,10 @@ class Parser {
}
if (AddUnderscores) {
- if (!isDecorated(E.Name, MingwDef))
+ // Don't add underscore if the name is already mangled or if it's a
+ // forward target.
+ if (!isDecorated(E.Name, MingwDef) &&
+ (E.ExtName.empty() || !StringRef(E.Name).contains(".")))
E.Name = (std::string("_").append(E.Name));
if (!E.ExtName.empty() && !isDecorated(E.ExtName, MingwDef))
E.ExtName = (std::string("_").append(E.ExtName));
diff --git a/llvm/test/tools/llvm-lib/underscore.test b/llvm/test/tools/llvm-lib/underscore.test
new file mode 100644
index 0000000000000..61eee00bcf9bc
--- /dev/null
+++ b/llvm/test/tools/llvm-lib/underscore.test
@@ -0,0 +1,23 @@
+; RUN: llvm-lib -machine:x86 -out:%t.lib -def:%s
+; RUN: llvm-readobj %t.lib | FileCheck %s
+
+; CHECK: File: test.dll
+; CHECK-NEXT: Format: COFF-import-file-i386
+; CHECK-NEXT: Type: code
+; CHECK-NEXT: Name type: noprefix
+; CHECK-NEXT: Export name: func
+; CHECK-NEXT: Symbol: __imp__func
+; CHECK-NEXT: Symbol: _func
+; CHECK-EMPTY:
+; CHECK-NEXT: File: test.dll
+; CHECK-NEXT: Format: COFF-import-file-i386
+; CHECK-NEXT: Type: code
+; CHECK-NEXT: Name type: noprefix
+; CHECK-NEXT: Export name: test.func
+; CHECK-NEXT: Symbol: __imp__test.func
+; CHECK-NEXT: Symbol: _test.func
+
+LIBRARY test.dll
+EXPORTS
+ func
+ test.func
|
@llvm/pr-subscribers-llvm-binary-utilities Author: Jacek Caban (cjacek) ChangesFixes #132411. Full diff: https://github.com/llvm/llvm-project/pull/135433.diff 3 Files Affected:
diff --git a/lld/test/COFF/export-alias.test b/lld/test/COFF/export-alias.test
new file mode 100644
index 0000000000000..a13fdf1504fb2
--- /dev/null
+++ b/lld/test/COFF/export-alias.test
@@ -0,0 +1,16 @@
+; REQUIRES: x86
+
+; RUN: echo > %t.s
+; RUN: llvm-mc -filetype=obj -triple=i686-windows %t.s -o %t.obj
+; RUN: lld-link -machine:x86 -dll -noentry -safeseh:no -out:%t.dll -def:%s %t.obj
+; RUN: llvm-readobj --coff-exports %t.dll | FileCheck %s
+
+; CHECK: Export {
+; CHECK-NEXT: Ordinal: 1
+; CHECK-NEXT: Name: func
+; CHECK-NEXT: ForwardedTo: other.dll.func
+; CHECK-NEXT: }
+
+LIBRARY test.dll
+EXPORTS
+ func = other.dll.func
diff --git a/llvm/lib/Object/COFFModuleDefinition.cpp b/llvm/lib/Object/COFFModuleDefinition.cpp
index 82c18539658e8..67b0dc4fa2976 100644
--- a/llvm/lib/Object/COFFModuleDefinition.cpp
+++ b/llvm/lib/Object/COFFModuleDefinition.cpp
@@ -238,7 +238,10 @@ class Parser {
}
if (AddUnderscores) {
- if (!isDecorated(E.Name, MingwDef))
+ // Don't add underscore if the name is already mangled or if it's a
+ // forward target.
+ if (!isDecorated(E.Name, MingwDef) &&
+ (E.ExtName.empty() || !StringRef(E.Name).contains(".")))
E.Name = (std::string("_").append(E.Name));
if (!E.ExtName.empty() && !isDecorated(E.ExtName, MingwDef))
E.ExtName = (std::string("_").append(E.ExtName));
diff --git a/llvm/test/tools/llvm-lib/underscore.test b/llvm/test/tools/llvm-lib/underscore.test
new file mode 100644
index 0000000000000..61eee00bcf9bc
--- /dev/null
+++ b/llvm/test/tools/llvm-lib/underscore.test
@@ -0,0 +1,23 @@
+; RUN: llvm-lib -machine:x86 -out:%t.lib -def:%s
+; RUN: llvm-readobj %t.lib | FileCheck %s
+
+; CHECK: File: test.dll
+; CHECK-NEXT: Format: COFF-import-file-i386
+; CHECK-NEXT: Type: code
+; CHECK-NEXT: Name type: noprefix
+; CHECK-NEXT: Export name: func
+; CHECK-NEXT: Symbol: __imp__func
+; CHECK-NEXT: Symbol: _func
+; CHECK-EMPTY:
+; CHECK-NEXT: File: test.dll
+; CHECK-NEXT: Format: COFF-import-file-i386
+; CHECK-NEXT: Type: code
+; CHECK-NEXT: Name type: noprefix
+; CHECK-NEXT: Export name: test.func
+; CHECK-NEXT: Symbol: __imp__test.func
+; CHECK-NEXT: Symbol: _test.func
+
+LIBRARY test.dll
+EXPORTS
+ func
+ test.func
|
Exporting names with dots is a bit unusual, but MSVC’s lib.exe allows it. So, comparing to the original version I posted in the issue, I’ve added a check that CC @lhmouse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/52/builds/7525 Here is the relevant piece of the build log for the reference
|
Fixes #132411.