This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Use ld64's LC_LINKER_OPTIONS behavior by default
ClosedPublic

Authored by keith on Dec 21 2022, 12:06 PM.

Details

Reviewers
int3
Group Reviewers
Restricted Project
Commits
rGd6cd8d6b1987: [lld-macho] Use ld64's LC_LINKER_OPTIONS behavior by default
Summary

By default ld64 ignores invalid LC_LINKER_OPTIONS unless the link fails,
in which case it prints a warning. Originally lld chose to be strict
about these, but it has uncovered that many of these exist in open
source projects today, since before developers never would have noticed
this issue. In order to make adoption of lld easier, this mirrors ld64's
behavior, while also adding a --strict-auto-link-options flag if
projects want to audit their libraries for these invalid options.

More discussion on https://reviews.llvm.org/D140225
Fixes https://github.com/llvm/llvm-project/issues/59627

Diff Detail

Event Timeline

keith created this revision.Dec 21 2022, 12:06 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptDec 21 2022, 12:06 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
keith requested review of this revision.Dec 21 2022, 12:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 21 2022, 12:06 PM

Alternatively in this patch we could not include --strict-auto-link-options and we could remove --ignore-auto-link-option

int3 added a subscriber: int3.Dec 22 2022, 1:10 PM

Alternatively in this patch we could not include --strict-auto-link-options and we could remove --ignore-auto-link-option

Nah I think this current solution is good (:

lld/MachO/Driver.cpp
1903–1904

would be nice to include the file where the error originated from, in the format mentioned here: https://reviews.llvm.org/D140225#inline-1357058

lld/MachO/Options.td
107

how do you feel about just calling this strict-auto-link? I don't think there's any other source of auto-linking, so there should be no potential confusion here

(same for the corresponding variable names)

lld/test/MachO/lc-linker-option.ll
151

nit: usually we use hyphens instead of underscores for these (to match the -NEXT etc suffixes)

keith updated this revision to Diff 484959.Dec 22 2022, 1:53 PM
keith marked 3 inline comments as done.

Rename CLI arg, add file path to warning / error

int3 accepted this revision.Dec 22 2022, 3:23 PM

lgtm

lld/MachO/Driver.cpp
412

refLoc seems kind of confusing since we already have a struct Location that represents a file + offset. How about refFile, or originFile?

430

personally I try to defer string building until we know we have to emit the warning. But I guess this code path occurs fairly rarely so there's not much of a perf concern (so this is fine)

lld/test/MachO/lc-linker-option.ll
155–157

could you hyphenate these too?

This revision is now accepted and ready to land.Dec 22 2022, 3:23 PM
keith updated this revision to Diff 484983.Dec 22 2022, 4:03 PM
keith marked 2 inline comments as done.

Improve variable naming, require originFile existance

This revision was landed with ongoing or failed builds.Dec 22 2022, 4:04 PM
This revision was automatically updated to reflect the committed changes.