This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho]Ensure canonicalization happen even for "skipped" referent sections.
ClosedPublic

Authored by oontvoo on May 31 2023, 11:25 AM.

Diff Detail

Event Timeline

oontvoo created this revision.May 31 2023, 11:25 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 31 2023, 11:25 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
oontvoo requested review of this revision.May 31 2023, 11:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 31 2023, 11:25 AM
oontvoo updated this revision to Diff 527168.May 31 2023, 12:45 PM

added test case

@int3 @thakis Any thought on this? :)

smeenai added a subscriber: smeenai.Jun 2 2023, 9:05 AM

I might not be understanding this diff correctly, but it seems like the code change just ensures that referent section canonicalization occurs for the UNSIGNED relocation following a SUBTRACTOR relocation. Is that the gist of the issue, and if so, could you update the summary to explain where such relocations are used in the unwind data and why it fixes the bug?

The test case is missing any assertions.

lld/test/MachO/fold-dwarf-lsda.s
5

Maybe use an explicit version in the triple which we know to not have compact unwind?

int3 added a comment.Jun 3 2023, 4:11 PM

+1 to what @smeenai said

Also re your commit message:

With assertion turned-off, lld would produce "bad" binary in which the gcc_except_table* got folded but not the related functions:

Is this actually a problem? Does the unwinder not like it when otherwise identical functions at two separate addresses share the same gcc_except_table?

lld/MachO/Writer.cpp
680–681

this is now being done in scanSymbols (I'm aware this was from an existing comment)

692

I think just copypasting the call to canonicalize() here would be cleaner -- no need for the skipNext state + would take fewer lines of code too

oontvoo updated this revision to Diff 528489.Jun 5 2023, 10:04 AM
oontvoo marked an inline comment as done.

addressed review comments

oontvoo marked an inline comment as done and an inline comment as not done.Jun 5 2023, 10:05 AM

+1 to what @smeenai said

I've updated the tests to add more assertions. But originally, the fact that the test didn't crash was sort of enough to cover to bug this aimed to fix.

Also re your commit message:

With assertion turned-off, lld would produce "bad" binary in which the gcc_except_table* got folded but not the related functions:

Is this actually a problem? Does the unwinder not like it when otherwise identical functions at two separate addresses share the same gcc_except_table?

Actually, the most serious issue here was that the linker crashed on the assertion (stacktrace attached in the bug report).
The rest of the symptoms are probably not as alarming. (the description/commit message was jsut trying to point out that the entries were pointing at the bad address).
Anyway, I've updated the tests with more assertions - hopefully that would make it a bit clearer.

Thanks!

lld/MachO/Writer.cpp
680–681

updated comment

692

couldn't simply copy the canonicalize() call here because we want to call it on the "next" entry (ie., the "skipped" one) as well.

In other words this it++ would have skipped over it .

oontvoo updated this revision to Diff 528491.Jun 5 2023, 10:07 AM

removed extraneous NLs

int3 added inline comments.Jun 5 2023, 4:56 PM
lld/MachO/Writer.cpp
692

I understand, but I meant like

++it;
if (auto *referentIsec = it->referent.dyn_cast<InputSection *>())
  it->referent = referentIsec->canonical();
continue;
lld/test/MachO/fold-dwarf-lsda.s
3
6
44

can the test case be made smaller? e.g. are the .cfi_personality directives necessary?

48

.cfi_def_cfa_register probably isn't necessary either

oontvoo updated this revision to Diff 528879.Jun 6 2023, 8:23 AM
oontvoo marked 6 inline comments as done.

Addressed review comments.

int3 accepted this revision.Jun 6 2023, 9:37 AM

lgtm. Could you update the commit message to reflect the main problem too? Thanks!

This revision is now accepted and ready to land.Jun 6 2023, 9:37 AM
oontvoo retitled this revision from [lld-macho]Fixed bug folding LSDA incorrectly to [lld-macho]Ensure canonicalization happen even for "skipped" referent sections..Jun 6 2023, 9:52 AM
oontvoo edited the summary of this revision. (Show Details)
oontvoo updated this revision to Diff 528910.Jun 6 2023, 9:53 AM
oontvoo edited the summary of this revision. (Show Details)

rebase + edit commit message

This revision was landed with ongoing or failed builds.Jun 6 2023, 9:54 AM
This revision was automatically updated to reflect the committed changes.