This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Set the SG_READ_ONLY flag on __DATA_CONST
ClosedPublic

Authored by BertalanD on Aug 31 2022, 3:53 AM.

Details

Summary

This flag instructs dyld to mark the segment read-only after fixups have
been performed.

I'm not sure why this flag is needed, as on macOS 13 beta at least,
__DATA_CONST is read-only even without this flag, but ld64 sets it as
well.

Diff Detail

Event Timeline

BertalanD created this revision.Aug 31 2022, 3:53 AM
Herald added a reviewer: MaskRay. · View Herald Transcript
Herald added a reviewer: ributzka. · View Herald Transcript
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
Herald added a subscriber: rupprecht. · View Herald Transcript
BertalanD requested review of this revision.Aug 31 2022, 3:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 31 2022, 3:53 AM
int3 accepted this revision.Aug 31 2022, 5:32 AM
int3 added a subscriber: int3.

lgtm

llvm/tools/llvm-objdump/MachODump.cpp
8862

I assume by "this inconsistency" you mean the inclusion of SG_ prefix in the output? Would be nice to spell it out, took me a sec :)

This revision is now accepted and ready to land.Aug 31 2022, 5:32 AM
thakis accepted this revision.Aug 31 2022, 6:04 AM
thakis added a subscriber: thakis.

lg

lld/MachO/OutputSegment.cpp
48

ld64 checks this:

	// but not for shared cache dylibs (because __objc_const is not read-only)
	return ( fUseDataConstSegment && (strcmp(name, "__DATA_CONST") == 0) && (!fSharedRegionEligible || (fOutputKind == Options::kDyld)) );

I think we only end up with dataConst segments if config->dataConst (the first check) (…or if users use that segment name explicitly, but then they kind of ask for this treatment, so that seems fine).

We don't implement neither -dylinker nor -add_split_seg_info / -not_for_dyld_shared_cache (not sure why the positive and negative forms of that have different names…), and it's unlikely we'll add them (seems they're only needed for the linker used to link the OS), so we don't really have to worry about the second part. But maybe this could grow a comment around the lines of "If we ever implement shared cache output support, don't set this for shared cache dylibs".

(Or not. As-is is fine too, up to you.)

llvm/tools/llvm-objdump/MachODump.cpp
8862

+1, took me a bit too.

BertalanD updated this revision to Diff 456947.Aug 31 2022, 6:32 AM

Improved comments.

This revision was automatically updated to reflect the committed changes.