theraven created this revision. Herald added a project: All. theraven requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
In the GNUstep v2 ABI (on ELF), we rely on the linker-inserted section start and stop markers. These only exist when binary has something in the relevant sections. To ensure that they exist, compilation units that omit one of the components emit an empty object into the section that it's not putting anything in. These empty objects are COMDATs and are merged in the final version. Unfortunately, there is a corner case where the entry exists in the code emitted by the front end but is then elided during optimisation. We already unconditionally emitted an empty selector to avoid this case for message sends but it was still a problem for constant strings. This change unconditionally emits these placeholders for everything. This results in very slightly larger .o files but ensures that any future optimisation that elides more things will not prevent compilation and so reduces fragility. Fixes #47536 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D157962 Files: clang/lib/CodeGen/CGObjCGNU.cpp Index: clang/lib/CodeGen/CGObjCGNU.cpp =================================================================== --- clang/lib/CodeGen/CGObjCGNU.cpp +++ clang/lib/CodeGen/CGObjCGNU.cpp @@ -1614,32 +1614,24 @@ if (!CGM.getTriple().isOSBinFormatCOFF()) { createNullGlobal(".objc_null_selector", {NULLPtr, NULLPtr}, sectionName<SelectorSection>()); - if (Categories.empty()) - createNullGlobal(".objc_null_category", {NULLPtr, NULLPtr, - NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr}, - sectionName<CategorySection>()); - if (!EmittedClass) { - createNullGlobal(".objc_null_cls_init_ref", NULLPtr, - sectionName<ClassSection>()); - createNullGlobal(".objc_null_class_ref", { NULLPtr, NULLPtr }, - sectionName<ClassReferenceSection>()); - } - if (!EmittedProtocol) - createNullGlobal(".objc_null_protocol", {NULLPtr, NULLPtr, NULLPtr, - NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr, - NULLPtr}, sectionName<ProtocolSection>()); - if (!EmittedProtocolRef) - createNullGlobal(".objc_null_protocol_ref", {NULLPtr}, - sectionName<ProtocolReferenceSection>()); - if (ClassAliases.empty()) - createNullGlobal(".objc_null_class_alias", { NULLPtr, NULLPtr }, - sectionName<ClassAliasSection>()); - if (ConstantStrings.empty()) { - auto i32Zero = llvm::ConstantInt::get(Int32Ty, 0); - createNullGlobal(".objc_null_constant_string", { NULLPtr, i32Zero, - i32Zero, i32Zero, i32Zero, NULLPtr }, - sectionName<ConstantStringSection>()); - } + createNullGlobal(".objc_null_category", {NULLPtr, NULLPtr, + NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr}, + sectionName<CategorySection>()); + createNullGlobal(".objc_null_cls_init_ref", NULLPtr, + sectionName<ClassSection>()); + createNullGlobal(".objc_null_class_ref", { NULLPtr, NULLPtr }, + sectionName<ClassReferenceSection>()); + createNullGlobal(".objc_null_protocol", {NULLPtr, NULLPtr, NULLPtr, + NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr, + NULLPtr}, sectionName<ProtocolSection>()); + createNullGlobal(".objc_null_protocol_ref", {NULLPtr}, + sectionName<ProtocolReferenceSection>()); + createNullGlobal(".objc_null_class_alias", { NULLPtr, NULLPtr }, + sectionName<ClassAliasSection>()); + auto i32Zero = llvm::ConstantInt::get(Int32Ty, 0); + createNullGlobal(".objc_null_constant_string", { NULLPtr, i32Zero, + i32Zero, i32Zero, i32Zero, NULLPtr }, + sectionName<ConstantStringSection>()); } ConstantStrings.clear(); Categories.clear();
Index: clang/lib/CodeGen/CGObjCGNU.cpp =================================================================== --- clang/lib/CodeGen/CGObjCGNU.cpp +++ clang/lib/CodeGen/CGObjCGNU.cpp @@ -1614,32 +1614,24 @@ if (!CGM.getTriple().isOSBinFormatCOFF()) { createNullGlobal(".objc_null_selector", {NULLPtr, NULLPtr}, sectionName<SelectorSection>()); - if (Categories.empty()) - createNullGlobal(".objc_null_category", {NULLPtr, NULLPtr, - NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr}, - sectionName<CategorySection>()); - if (!EmittedClass) { - createNullGlobal(".objc_null_cls_init_ref", NULLPtr, - sectionName<ClassSection>()); - createNullGlobal(".objc_null_class_ref", { NULLPtr, NULLPtr }, - sectionName<ClassReferenceSection>()); - } - if (!EmittedProtocol) - createNullGlobal(".objc_null_protocol", {NULLPtr, NULLPtr, NULLPtr, - NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr, - NULLPtr}, sectionName<ProtocolSection>()); - if (!EmittedProtocolRef) - createNullGlobal(".objc_null_protocol_ref", {NULLPtr}, - sectionName<ProtocolReferenceSection>()); - if (ClassAliases.empty()) - createNullGlobal(".objc_null_class_alias", { NULLPtr, NULLPtr }, - sectionName<ClassAliasSection>()); - if (ConstantStrings.empty()) { - auto i32Zero = llvm::ConstantInt::get(Int32Ty, 0); - createNullGlobal(".objc_null_constant_string", { NULLPtr, i32Zero, - i32Zero, i32Zero, i32Zero, NULLPtr }, - sectionName<ConstantStringSection>()); - } + createNullGlobal(".objc_null_category", {NULLPtr, NULLPtr, + NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr}, + sectionName<CategorySection>()); + createNullGlobal(".objc_null_cls_init_ref", NULLPtr, + sectionName<ClassSection>()); + createNullGlobal(".objc_null_class_ref", { NULLPtr, NULLPtr }, + sectionName<ClassReferenceSection>()); + createNullGlobal(".objc_null_protocol", {NULLPtr, NULLPtr, NULLPtr, + NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr, NULLPtr, + NULLPtr}, sectionName<ProtocolSection>()); + createNullGlobal(".objc_null_protocol_ref", {NULLPtr}, + sectionName<ProtocolReferenceSection>()); + createNullGlobal(".objc_null_class_alias", { NULLPtr, NULLPtr }, + sectionName<ClassAliasSection>()); + auto i32Zero = llvm::ConstantInt::get(Int32Ty, 0); + createNullGlobal(".objc_null_constant_string", { NULLPtr, i32Zero, + i32Zero, i32Zero, i32Zero, NULLPtr }, + sectionName<ConstantStringSection>()); } ConstantStrings.clear(); Categories.clear();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits