This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Rework mergeFlag to closer mimic what LD64 does.
ClosedPublic

Authored by oontvoo on Jun 9 2021, 9:14 AM.

Details

Summary

Details:

I've been getting a few weird errors similar to the following from our internal tests:

ld64.lld.darwinnew: error: Cannot merge section __eh_frame (type=0x0) into __eh_frame (type=0xB): inconsistent types
ld64.lld.darwinnew: error: Cannot merge section __eh_frame (flags=0x0) into __eh_frame (flags=0x6800000B): strict flags differ
ld64.lld.darwinnew: error: Cannot merge section __eh_frame (type=0x0) into __eh_frame (type=0xB): inconsistent types
ld64.lld.darwinnew: error: Cannot merge section __eh_frame (flags=0x0) into __eh_frame (flags=0x6800000B): strict flags differ

Diff Detail

Event Timeline

oontvoo created this revision.Jun 9 2021, 9:14 AM
Herald added a reviewer: gkm. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a reviewer: Restricted Project. · View Herald Transcript
oontvoo requested review of this revision.Jun 9 2021, 9:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 9 2021, 9:14 AM
int3 added a comment.Jun 9 2021, 9:34 AM

Could you add a test?

Could you add a test?

Yup, I'll try to simplify the test case we had that tripped over this.

But can we first agree on the logic? If the flag is not set, then it should not be a flag or type conflict. Does that make sense?

(also the comment on top of this function is ... interesting :-) " this is most likely wrong; ...The logic presented here was written without any form of informed research.". )

int3 added a comment.Jun 11 2021, 2:01 PM

It makes sense, yes. Always good to cross-check it with what ld64 is doing though.

(also the comment on top of this function is ... interesting :-)

I didn't write that :P adding some informed research here would definitely be appreciated!

int3 added a comment.Jun 16 2021, 6:57 PM

Bump. Are you going to finish this? I've stumbled onto some programs that need it :)

Bump. Are you going to finish this? I've stumbled onto some programs that need it :)

Sorry for the delay, was OOO earlier this week for a surgery.
Anyway, ld64 had a slightly different approach - instead of trying to "merge" input and output flags, it had an elaborate switch-case to decide what the "final" set of flags should be.
We could do just that?

oontvoo updated this revision to Diff 352709.Jun 17 2021, 6:58 AM

rework mergeFlag to closer minic what ld64 does.

oontvoo updated this revision to Diff 352727.Jun 17 2021, 7:50 AM

fixed typos

oontvoo updated this revision to Diff 352735.Jun 17 2021, 8:04 AM

fixed type-conversions warnings

oontvoo retitled this revision from [lld-macho] Don't check for flag-mismatch if flag isn't set. to [lld-macho] Rework mergeFlag to closer mimic what LD64 does..Jun 17 2021, 8:08 AM
oontvoo edited the summary of this revision. (Show Details)
int3 added a comment.Jun 17 2021, 8:11 AM

Sorry for the delay, was OOO earlier this week for a surgery.

Sorry to hear that, hope you're recovering well!

So after examining all the cases... I think that perhaps all this checking logic is not needed after all, and we should just do a bitwise-or merge for now?

lld/MachO/ConcatOutputSection.cpp
336–353

all these seem relevant only if we are re-emitting object files, which we probably won't bother with for a while. In particular, I think S_ATTR_NO_DEAD_STRIP is only relevant as input to the linker, and ___compact_unwind gets converted to __unwind info as part of the usual link process. IMO we can just leave a FIXME comment for now for whomever wants to add object file support

369

we're not likely to support kexts in the foreseeable future, so I don't think it's worth checking for here

370

I don't think this is right, ld64's equivalent check is for static executables, and we only ever emit dynamic ones

373–375

I don't believe any ConcatInputSection should have S_SYMBOL_STUBS set. But our StubsSection does have these three flags set, so I think we're good here

(I think the same applies for S_NON_LAZY_SYMBOL_POINTERS above -- we shouldn't have ConcatInputSections with that flag set, at least as far as arm64/x86_64 is concerned. I think arm32 explicitly encodes some of these stubs in the input, so that's a whole other problem for another day)

376–377

hm, I think this is also only relevant if we are emitting object files

oontvoo marked 5 inline comments as done.Jun 17 2021, 8:41 AM

So after examining all the cases... I think that perhaps all this checking logic is not needed after all, and we should just do a bitwise-or merge for now?

I've updated the switch to simplify the logic - (still looks like we can't simply merge the type.... )

lld/MachO/ConcatOutputSection.cpp
369

Right, this is checking for that cases that are *not* kext :)

370

fixed logic

oontvoo updated this revision to Diff 352742.Jun 17 2021, 8:41 AM
oontvoo marked 2 inline comments as done.

updated diff

oontvoo updated this revision to Diff 352749.Jun 17 2021, 9:05 AM

updated tests

int3 added inline comments.Jun 17 2021, 9:22 AM
lld/MachO/ConcatOutputSection.cpp
369

Right, this is checking for that cases that are *not* kext :)

yes I understood that... my point is that it's never going to be kext, so the check is redundant

I don't believe any ConcatInputSection should have S_SYMBOL_STUBS set. But our StubsSection does have these three flags set, so I think we're good here

(I think the same applies for S_NON_LAZY_SYMBOL_POINTERS above

I don't think you addressed this :)

oontvoo marked an inline comment as done.Jun 17 2021, 9:36 AM
oontvoo added inline comments.
lld/MachO/ConcatOutputSection.cpp
369

done (for real this time)

oontvoo updated this revision to Diff 352762.Jun 17 2021, 9:36 AM
oontvoo marked an inline comment as done.

updated diff

int3 accepted this revision.Jun 17 2021, 10:51 AM

Thanks!

lld/MachO/ConcatOutputSection.cpp
353

since S_REGULAR is zero, there's no need to do the bitwise or for the default case

This revision is now accepted and ready to land.Jun 17 2021, 10:51 AM
oontvoo updated this revision to Diff 352791.Jun 17 2021, 10:54 AM
oontvoo marked an inline comment as done.

updated diff per request

This revision was landed with ongoing or failed builds.Jun 17 2021, 11:23 AM
This revision was automatically updated to reflect the committed changes.