diff options
author | Aleksandr Urakov <xande8088@yandex.ru> | 2025-07-21 09:08:33 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-21 09:08:33 +0300 |
commit | c9cbd4e9d4025b3b5c9593f3c187e0d5e3471a89 (patch) | |
tree | 31930757e51b18fa166a5afca7648723c8dde63e /llvm/lib/Bitcode/Reader/BitcodeReader.cpp | |
parent | 6193dd55535460c347f8c0b794df7d7d52fa78c9 (diff) | |
download | llvm-c9cbd4e9d4025b3b5c9593f3c187e0d5e3471a89.zip llvm-c9cbd4e9d4025b3b5c9593f3c187e0d5e3471a89.tar.gz llvm-c9cbd4e9d4025b3b5c9593f3c187e0d5e3471a89.tar.bz2 |
[lld] Fix -ObjC load behavior with LTO for section names with whitespace (#146654)
This is a fix additional to #92162
In some cases, section names contain a whitespace between the segment
name and the actual section name (e.g. `__TEXT, __swift5_proto`). It is
confirmed by source code of the Swift compiler
This fix allows LTO to work correctly with the `-ObjC` flag in that rare
case when only a section with a whitespace in the name is present in the
linked bitcode module, but there are no sections containing
`__TEXT,__swift`
---------
Co-authored-by: Ураков Александр Сергеевич <a.urakov@tbank.ru>
Co-authored-by: Ellis Hoag <ellis.sparky.hoag@gmail.com>
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 66ecc69..6e93872 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -293,10 +293,18 @@ static Expected<bool> hasObjCCategoryInModule(BitstreamCursor &Stream) { std::string S; if (convertToString(Record, 0, S)) return error("Invalid section name record"); + // Check for the i386 and other (x86_64, ARM) conventions - if (S.find("__DATA,__objc_catlist") != std::string::npos || - S.find("__OBJC,__category") != std::string::npos || - S.find("__TEXT,__swift") != std::string::npos) + + auto [Segment, Section] = StringRef(S).split(","); + Segment = Segment.trim(); + Section = Section.trim(); + + if (Segment == "__DATA" && Section.starts_with("__objc_catlist")) + return true; + if (Segment == "__OBJC" && Section.starts_with("__category")) + return true; + if (Segment == "__TEXT" && Section.starts_with("__swift")) return true; break; } |