From c9cbd4e9d4025b3b5c9593f3c187e0d5e3471a89 Mon Sep 17 00:00:00 2001 From: Aleksandr Urakov Date: Mon, 21 Jul 2025 09:08:33 +0300 Subject: [lld] Fix -ObjC load behavior with LTO for section names with whitespace (#146654) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Ураков Александр Сергеевич Co-authored-by: Ellis Hoag --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') 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 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; } -- cgit v1.1