Skip to content

[LLD][COFF] Use parentName for import files in toString. #106104

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

Merged
merged 1 commit into from
Aug 26, 2024

Conversation

cjacek
Copy link
Contributor

@cjacek cjacek commented Aug 26, 2024

No description provided.

@cjacek cjacek requested review from mstorsjo, zmodem and aganea August 26, 2024 17:02
@cjacek
Copy link
Contributor Author

cjacek commented Aug 26, 2024

Inspired by @zmodem's comment in #102738. We currently explicitly ignore parentName for import files in toString, which makes error/warning messages less expressive than they would otherwise be.

I tracked the check in toString down to https://reviews.llvm.org/D54802. It looks like this commit set ParentName on import files, so I guess the change was about preserving previous behaviour. However, using it seems reasonable to me. It looks like toString is already used only by error, warnings and logs, so it seems to be a good fit.

@llvmbot
Copy link
Member

llvmbot commented Aug 26, 2024

@llvm/pr-subscribers-lld-coff
@llvm/pr-subscribers-platform-windows

@llvm/pr-subscribers-lld

Author: Jacek Caban (cjacek)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/106104.diff

4 Files Affected:

  • (modified) lld/COFF/InputFiles.cpp (+1-1)
  • (modified) lld/test/COFF/delayimports-error.test (+1-1)
  • (modified) lld/test/COFF/duplicate.test (+1-1)
  • (modified) lld/test/COFF/implib-machine.s (+2-2)
diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp
index f9a22b0a7a5f0f..3ecd4d241f2cd4 100644
--- a/lld/COFF/InputFiles.cpp
+++ b/lld/COFF/InputFiles.cpp
@@ -61,7 +61,7 @@ static StringRef getBasename(StringRef path) {
 std::string lld::toString(const coff::InputFile *file) {
   if (!file)
     return "<internal>";
-  if (file->parentName.empty() || file->kind() == coff::InputFile::ImportKind)
+  if (file->parentName.empty())
     return std::string(file->getName());
 
   return (getBasename(file->parentName) + "(" + getBasename(file->getName()) +
diff --git a/lld/test/COFF/delayimports-error.test b/lld/test/COFF/delayimports-error.test
index cced9fb65e6142..5f45083cf5e613 100644
--- a/lld/test/COFF/delayimports-error.test
+++ b/lld/test/COFF/delayimports-error.test
@@ -8,7 +8,7 @@
 # RUN:   /alternatename:__delayLoadHelper2=main /opt:noref >& %t.log
 # RUN: FileCheck %s < %t.log
 
-# CHECK: cannot delay-load foo.dll due to import of data: __declspec(dllimport) datasym
+# CHECK: cannot delay-load foo.lib(foo.dll) due to import of data: __declspec(dllimport) datasym
 
 --- !COFF
 header:
diff --git a/lld/test/COFF/duplicate.test b/lld/test/COFF/duplicate.test
index 76c88b070ff375..11e5aa06318fe0 100644
--- a/lld/test/COFF/duplicate.test
+++ b/lld/test/COFF/duplicate.test
@@ -13,5 +13,5 @@ RUN: not lld-link /out:gamma.exe /subsystem:console /entry:mainCRTStartup gamma.
 
 CHECK-GAMMA: error: duplicate symbol: __declspec(dllimport) f
 CHECK-GAMMA: defined at {{.*}}gamma.obj
-CHECK-GAMMA: defined at alpha.dll
+CHECK-GAMMA: defined at alpha.lib(alpha.dll)
 
diff --git a/lld/test/COFF/implib-machine.s b/lld/test/COFF/implib-machine.s
index 32deff0fc25f89..92f01bbc72799b 100644
--- a/lld/test/COFF/implib-machine.s
+++ b/lld/test/COFF/implib-machine.s
@@ -6,10 +6,10 @@
 # RUN: llvm-mc -triple x86_64-windows-msvc %t.dir/test.s -filetype=obj -o %t.dir/test64.obj
 
 # RUN: not lld-link -dll -noentry -out:%t32.dll %t.dir/test32.obj %t.dir/test64.lib 2>&1 | FileCheck --check-prefix=ERR32 %s
-# ERR32: error: test.dll: machine type x64 conflicts with x86
+# ERR32: error: test64.lib(test.dll): machine type x64 conflicts with x86
 
 # RUN: not lld-link -dll -noentry -out:%t64.dll %t.dir/test64.obj %t.dir/test32.lib 2>&1 | FileCheck --check-prefix=ERR64 %s
-# ERR64: error: test.dll: machine type x86 conflicts with x64
+# ERR64: error: test32.lib(test.dll): machine type x86 conflicts with x64
 
 #--- test.s
         .def     @feat.00;

Copy link
Member

@aganea aganea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good because some libraries have members all named the same (ie.Microsoft) and it it’s not always clear from which archive the symbol comes from. Thanks for the change, LGTM!

Copy link
Collaborator

@zmodem zmodem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice improvement for users. Thanks!

@cjacek cjacek merged commit e1cf849 into llvm:main Aug 26, 2024
12 checks passed
@cjacek cjacek deleted the import-tostring branch August 26, 2024 20:08
@cjacek
Copy link
Contributor Author

cjacek commented Aug 26, 2024

Merged, thanks for reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants