-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[LLD] dtNeeded name should consistent with soNames #72857
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-lld @llvm/pr-subscribers-lld-elf Author: Longsheng Mou (CoTinker) ChangesIf dtNeeded name is inconsistent with soNames, lld can not report error right. demolibhave.so
libuse.so
mainmain.c
can report errorclang case/use.c -o exe/libuse.so -lhave -Lexe --shared -fPIC clang case/use.c -o exe/libuse.so exe/libhave.so --shared -fPIC can not report errorclang case/ususe.c -o exe/libuseo exe/libhave.so --shared -fPIC clang case/ususe.c -o exe/libuseo -lhave -Lexe --shared -fPIC We can see that if dtNeeded name is inconsistent with soNames, lld can not report error right. llvm-project/lld/ELF/Writer.cpp Lines 2019 to 2036 in 4594d5b
Full diff: https://github.com/llvm/llvm-project/pull/72857.diff 1 Files Affected:
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 7ac737dab0519a8..05b9dc2d5474170 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -1439,7 +1439,7 @@ template <class ELFT> void SharedFile::parse() {
uint64_t val = dyn.getVal();
if (val >= this->stringTable.size())
fatal(toString(this) + ": invalid DT_NEEDED entry");
- dtNeeded.push_back(this->stringTable.data() + val);
+ dtNeeded.push_back(path::filename(this->stringTable.data() + val));
} else if (dyn.d_tag == DT_SONAME) {
uint64_t val = dyn.getVal();
if (val >= this->stringTable.size())
@@ -1452,7 +1452,7 @@ template <class ELFT> void SharedFile::parse() {
DenseMap<CachedHashStringRef, SharedFile *>::iterator it;
bool wasInserted;
std::tie(it, wasInserted) =
- symtab.soNames.try_emplace(CachedHashStringRef(soName), this);
+ symtab.soNames.try_emplace(CachedHashStringRef(path::filename(soName)), this);
// If a DSO appears more than once on the command line with and without
// --as-needed, --no-as-needed takes precedence over --as-needed because a
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
I'm finding your examples a bit hard to follow. Can you clarify a few things:
|
|
92dc3ac
to
69b001a
Compare
If dtNeeded name is inconsistent with soNames, lld can not report error right.
I suspect that you have an incorrect use case, but the case is not clearly described and I cannot verify. FYI I place all needed files in a directory and run
The |
Thank you, the core problem is probably shared object does not have DT_SONAME. |
If dtNeeded name is inconsistent with soNames, lld can not report error right.
demo
can report error
$ ld.lld main.o ref.so ./def.so
dtNeeded name =
./def.so
, soName =./def.so
, consistent.can not report error
$ ld.lld main.o ref.so def.so
dtNeeded name =
./def.so
, soName =def.so
, inconsistent.We can see that if dtNeeded name is inconsistent with soNames, lld can not report error right.
llvm-project/lld/ELF/Writer.cpp
Lines 2019 to 2036 in 4594d5b