This is an archive of the discontinued LLVM Phabricator instance.

[ELF] -Map --why-extract=: print despite errors
ClosedPublic

Authored by MaskRay on Jan 7 2022, 2:07 PM.

Details

Summary

Fix https://github.com/llvm/llvm-project/issues/53073

In case of a relocation error, GNU ld's link map includes
the archive member extraction information but not output sections.

Our -Map and --why-extract= are currently no-op in case of an error.
This change makes the two options work.

Diff Detail

Event Timeline

MaskRay created this revision.Jan 7 2022, 2:07 PM
MaskRay requested review of this revision.Jan 7 2022, 2:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 7 2022, 2:08 PM
MaskRay updated this revision to Diff 398235.Jan 7 2022, 2:08 PM
MaskRay retitled this revision from [ELF] -Map --why-extract=: print despite errors Fix https://github.com/llvm/llvm-project/issues/53073 In case of a relocation error, GNU ld's link map includes the archive member extraction information but not the section layout. This change... to [ELF] -Map --why-extract=: print despite errors.
MaskRay edited the summary of this revision. (Show Details)
This comment was removed by MaskRay.
MaskRay edited the summary of this revision. (Show Details)Jan 7 2022, 2:09 PM

The output of --why-extract looks useful indeed, but does the map file without output sections make much sense?

Presumably the relocation error is detected early, and not one detected late during writeTo()? I suspect that a late error would lead to a more complete map file being produced. In Arm's proprietary linker the ability to write a map file when a relocation out of range error has been detected has been really useful to debug problems in the thunk creation logic. I think it should be possible to detect if the OutputSections are incomplete, if that is the case it may be worth suppressing the OutputSections in the map file, or maybe putting a warning in the map file to state that output is incomplete.

Definitely support the idea of outputting as much diagnostics as possible, even when there is an error though.

MaskRay updated this revision to Diff 398715.Jan 10 2022, 11:59 AM
MaskRay edited the summary of this revision. (Show Details)

delete another if (errorCount()) return; to make addresses available in case of an error

peter.smith accepted this revision.Jan 11 2022, 9:04 AM

Thanks for the update LGTM on my side. It could be worth adding a comment after finalizeAddressDependentContent() just before the error check, to say something like All information needed for OutputSection part of Map file available. That might help someone that adds an extra error check and sees a test fail.

This revision is now accepted and ready to land.Jan 11 2022, 9:04 AM
MaskRay updated this revision to Diff 398979.Jan 11 2022, 9:13 AM
MaskRay edited the summary of this revision. (Show Details)

Add All information needed for OutputSection part of Map file is available.

Thanks for the suggestion!

ikudrin added inline comments.Jan 11 2022, 10:59 PM
lld/ELF/LinkerScript.cpp
566–567 ↗(On Diff #398979)

There is no test that covers this change. And maybe it'll be better to fix the issue directly in DynamicSection<ELFT>::computeContents()?

MaskRay marked an inline comment as done.Jan 12 2022, 12:29 AM
MaskRay added inline comments.
lld/ELF/LinkerScript.cpp
566–567 ↗(On Diff #398979)

discard-section-err.s covers this. Without the change `discard-section-err.s segfaults.

MaskRay marked an inline comment as done.Jan 12 2022, 12:37 AM
ikudrin added inline comments.Jan 12 2022, 12:49 AM
lld/ELF/LinkerScript.cpp
566–567 ↗(On Diff #398979)

Well, for some reason, it passed on Windows in the Release build.

When you look at the code without the knowledge of all other parts of the linker, it is a bit puzzling that mainPart->relrDyn is reset while in.shStrTab is not. It either deserves an explanatory comment or in.shStrTab should be cleared, too, so that the code looks more consistent. Or maybe both.

MaskRay updated this revision to Diff 399264.Jan 12 2022, 2:07 AM

update comment

MaskRay marked an inline comment as done.Jan 12 2022, 2:07 AM
MaskRay updated this revision to Diff 399266.Jan 12 2022, 2:10 AM

allow discarding .relr.dyn

ikudrin accepted this revision.Jan 12 2022, 6:19 AM

LGTM.

Changes in LinkerScript.cpp and discard-section-err.s should be committed separately.

LGTM.

Changes in LinkerScript.cpp and discard-section-err.s should be committed separately.

Agree, the unified diff is for an easier overview. I will push it separately.

MaskRay updated this revision to Diff 399379.Jan 12 2022, 10:39 AM
MaskRay edited the summary of this revision. (Show Details)

rebase

This revision was landed with ongoing or failed builds.Jan 12 2022, 10:40 AM
This revision was automatically updated to reflect the committed changes.