Page MenuHomePhabricator

[lld/macho] Fixes the -ObjC flag
ClosedPublic

Authored by tt on May 9 2022, 11:26 AM.

Details

Reviewers
keith
int3
thevinster
Group Reviewers
Restricted Project
Commits
rGd64bad8ff126: [lld/macho] Fixes the -ObjC flag
Summary

When checking the segment name for Swift symbols, we should be checking that they start with __swift instead of checking for equality

Fixes the issue https://github.com/llvm/llvm-project/issues/55355

Diff Detail

Event Timeline

tt created this revision.May 9 2022, 11:26 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 9 2022, 11:26 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
tt requested review of this revision.May 9 2022, 11:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 9 2022, 11:26 AM
keith added a subscriber: keith.May 9 2022, 12:01 PM

Which sections specifically hit this? can you add a test?

tt added a comment.EditedMay 9 2022, 1:13 PM

I see this happening for __swift5_proto but yes, will add a test

There are several __swift* sections, in fact, I haven't run into a __swift section at all.
For e.g. compiling the following code results into sections:

protocol Blah {}
extension Blah {
    func foobar() {
    }
}
func noop() {}
/tmp/Blah.o:	file format mach-o 64-bit x86-64

Sections:
Idx Name             Size     VMA              Type
  0 __text           00000026 0000000000000000 TEXT
  1 __swift5_entry   00000004 0000000000000028 DATA
  2 __swift5_typeref 0000000b 000000000000002c DATA
  3 __swift5_fieldmd 00000010 0000000000000038 DATA
  4 __const          0000002e 0000000000000048 DATA
  5 __swift5_protos  00000004 0000000000000078 DATA
  6 __swift_modhash  00000010 000000000000007c DATA
  7 __objc_imageinfo 00000008 000000000000008c DATA
  8 __compact_unwind 00000060 0000000000000098 DATA
  9 __eh_frame       00000090 00000000000000f8 DATA

SYMBOL TABLE:
0000000000000028 l     O __TEXT,__swift5_entry l_entry_point
0000000000000038 l     O __TEXT,__swift5_fieldmd _$s4BlahAA_pMF
0000000000000048 l     O __TEXT,__const l___unnamed_1
0000000000000078 l     O __TEXT,__swift5_protos l_protocols
000000000000007c l     O __LLVM,__swift_modhash l_llvm.swift_module_hash
0000000000000020 g     F __TEXT,__text _$s4Blah4noopyyF
000000000000005c g     O __TEXT,__const _$s4BlahAAMp
0000000000000010 g     F __TEXT,__text _$s4BlahAAPAAE6foobaryyF
0000000000000050  w    O __TEXT,__const _$s4BlahMXM
0000000000000074  w    O __TEXT,__const ___swift_reflection_version
0000000000000000 g     F __TEXT,__text _main
000000000000002c  w    O __TEXT,__swift5_typeref _symbolic $s4BlahAAP
tt updated this revision to Diff 428494.May 10 2022, 2:05 PM

Add test

keith accepted this revision as: keith.May 10 2022, 2:40 PM
This revision is now accepted and ready to land.May 10 2022, 2:40 PM
rmaz added a reviewer: int3.May 10 2022, 3:42 PM
keith added inline comments.May 11 2022, 12:06 PM
lld/MachO/ObjC.cpp
41

Do you need this? it seems like using section_names::swift in the startswith below works as well?

tt added inline comments.May 11 2022, 3:52 PM
lld/MachO/ObjC.cpp
41

Whoops, yes don't need this. Autocomplete didn't suggest me startswith with a cstring. I guess autocomplete doesn't suggest me functions when there are implicit conversations.

tt updated this revision to Diff 428796.May 11 2022, 3:52 PM

Simplify

thevinster accepted this revision.May 11 2022, 4:04 PM
thevinster added a subscriber: thevinster.

LGTM

tt updated this revision to Diff 428808.May 11 2022, 4:27 PM

Remove empty line

This revision was landed with ongoing or failed builds.May 11 2022, 5:03 PM
Closed by commit rGd64bad8ff126: [lld/macho] Fixes the -ObjC flag (authored by tt, committed by keith). · Explain Why
This revision was automatically updated to reflect the committed changes.