Skip to content

IRGen: Rename the section pointing to rodata of generic classes to __objc_clsrolist #74178

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

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/AST/IRGenOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ class IRGenOptions {
EnableGlobalISel(false), VirtualFunctionElimination(false),
WitnessMethodElimination(false), ConditionalRuntimeRecords(false),
InternalizeAtLink(false), InternalizeSymbols(false),
EmitGenericRODatas(false), NoPreallocatedInstantiationCaches(false),
EmitGenericRODatas(true), NoPreallocatedInstantiationCaches(false),
DisableReadonlyStaticObjects(false), CollocatedMetadataFunctions(false),
ColocateTypeDescriptors(true), UseRelativeProtocolWitnessTables(false),
UseFragileResilientProtocolWitnesses(false),
Expand Down
4 changes: 2 additions & 2 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,9 +1172,9 @@ void IRGenModule::emitGlobalLists() {
if (IRGen.Opts.EmitGenericRODatas) {
emitGlobalList(
*this, GenericRODatas, "generic_ro_datas",
GetObjCSectionName("__swift_rodatas", "regular"),
GetObjCSectionName("__objc_clsrolist", "regular"),
llvm::GlobalValue::InternalLinkage, Int8PtrTy, /*isConstant*/ false,
/*asContiguousArray*/ true, /*canBeStrippedByLinker*/ true);
/*asContiguousArray*/ true, /*canBeStrippedByLinker*/ false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/canBeStrippedByLinker/ false

Is this about the symbol name or dead code stripping?

Copy link
Contributor Author

@aschwaighofer aschwaighofer Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This boolean decides whether llvm.used or llvm.compiler.used is used.

This will influence whether llvm's LTO can assume that the variable is unused if there are no other uses (that would happen with llvm.compiler.used i.e /canBeStrippedByLinker/ true) but will also cause the emission of .no_dead_strip _generic_ro_datas.

As in:

        .section        __LD,__objc_clsrolist
        .p2align        3, 0x0
_generic_ro_datas:
        .quad   ___unnamed_1+40
        .quad   ___unnamed_1+112
 ...
 .no_dead_strip  _generic_ro_datas

I assumed that is okay since the linker will know it is to remove that section at the point it uses it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, right we need this for LTO. It means older linkers that don't know about the section won't be able to dead strip it. That's maybe fine though? I assume this won't be too big, and it's only a problem when building with new Swift compiler but using an older linker.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will be one entry per generic class definition. Yes, I assume this to be a marginal problem that if it turns out to be a problem for an individual project that uses a new compiler with an old linker can turn this off via compiler flags.

}

// Objective-C class references go in a variable with a meaningless
Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/generic_class_rodata_list.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// CHECK: .quad 0
// CHECK: .quad __CLASS_METHODS__TtC25generic_class_rodata_list9Somethin

// CHECK: .section __DATA,__swift_rodatas
// CHECK: .section __DATA,__objc_clsrolist
// CHECK: .p2align 3
// CHECK:_generic_ro_datas:
// CHECK: .quad ___unnamed_1+40
Expand Down