diff options
author | Michael Trent <mtrent@apple.com> | 2019-01-24 20:59:44 +0000 |
---|---|---|
committer | Michael Trent <mtrent@apple.com> | 2019-01-24 20:59:44 +0000 |
commit | f4c902bd77b7c1cac6e24074262466b448bd0997 (patch) | |
tree | 91aea2bf2ea631935acc096adbd163397ca0e9c0 /llvm/lib/Object/MachOObjectFile.cpp | |
parent | 7fca260dc8f624791970b04c5a0cb16e3644bde8 (diff) | |
download | bcm5719-llvm-f4c902bd77b7c1cac6e24074262466b448bd0997.tar.gz bcm5719-llvm-f4c902bd77b7c1cac6e24074262466b448bd0997.zip |
Limit dyld image suffixes guessed by guessLibraryShortName()
Summary:
guessLibraryShortName() separates a full Mach-O dylib install name path
into a short name and a dyld image suffix. The short name is the name
of the dylib without its path or extension. The dyld image suffix is a
string used by dyld to load variants of dylibs if available at runtime;
for example, "when binding this process, load 'debug' variants of all
required dylibs." dyld knows exactly what the image suffix is, but
by convention diagnostic tools such as llvm-nm attempt to guess suffix
names by looking at the install name path.
These dyld image suffixes are separated from the short name by a '_'
character. Because the '_' character is commonly used to separate words
in filenames guessLibraryShortName() cannot reliably separate a dylib's
short name from an arbitrary image suffix; imagine if both the short
name and the suffix contains an '_' character! To better deal with this
ambiguity, guessLibraryShortName() will recognize only "_debug" and
"_profile" as valid Suffix values. Calling code needs to be tolerant of
guessLibraryShortName() guessing incorrectly.
The previous implementation of guessLibraryShortName() did not allow
'_' characters to appear in short names. When present, the short name
would be truncated, e.g., "libcompiler_rt" => "libcompiler". This
change allows "libcompiler_rt" and "libcompiler_rt_debug" to both be
recognized as "libcompiler_rt".
rdar://47412244
Reviewers: kledzik, lhames, pete
Reviewed By: pete
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D56978
llvm-svn: 352104
Diffstat (limited to 'llvm/lib/Object/MachOObjectFile.cpp')
-rw-r--r-- | llvm/lib/Object/MachOObjectFile.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index a1cbef2c281..69e69bdcf93 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -2241,9 +2241,18 @@ uint8_t MachOObjectFile::getRelocationLength(DataRefImpl Rel) const { // one of the two following forms: // libFoo.A.dylib // libFoo.dylib +// // The library may have a suffix trailing the name Foo of the form: // libFoo_profile.A.dylib // libFoo_profile.dylib +// These dyld image suffixes are separated from the short name by a '_' +// character. Because the '_' character is commonly used to separate words in +// filenames guessLibraryShortName() cannot reliably separate a dylib's short +// name from an arbitrary image suffix; imagine if both the short name and the +// suffix contains an '_' character! To better deal with this ambiguity, +// guessLibraryShortName() will recognize only "_debug" and "_profile" as valid +// Suffix values. Calling code needs to be tolerant of guessLibraryShortName() +// guessing incorrectly. // // The Name of the dynamic library is also recognized as a library name if it // has the following form: @@ -2251,7 +2260,6 @@ uint8_t MachOObjectFile::getRelocationLength(DataRefImpl Rel) const { // // If the Name of the dynamic library is none of the forms above then a NULL // StringRef is returned. -// StringRef MachOObjectFile::guessLibraryShortName(StringRef Name, bool &isFramework, StringRef &Suffix) { @@ -2271,7 +2279,10 @@ StringRef MachOObjectFile::guessLibraryShortName(StringRef Name, Idx = Foo.rfind('_'); if (Idx != Foo.npos && Foo.size() >= 2) { Suffix = Foo.slice(Idx, Foo.npos); - Foo = Foo.slice(0, Idx); + if (Suffix != "_debug" && Suffix != "_profile") + Suffix = StringRef(); + else + Foo = Foo.slice(0, Idx); } // First look for the form Foo.framework/Foo @@ -2332,10 +2343,14 @@ guess_library: else b = b+1; // ignore any suffix after an underbar like Foo_profile.A.dylib - Idx = Name.find('_', b); + Idx = Name.rfind('_'); if (Idx != Name.npos && Idx != b) { Lib = Name.slice(b, Idx); Suffix = Name.slice(Idx, a); + if (Suffix != "_debug" && Suffix != "_profile") { + Suffix = StringRef(); + Lib = Name.slice(b, a); + } } else Lib = Name.slice(b, a); |