error on invalid macho section specifier#155065
error on invalid macho section specifier#155065folkertdev wants to merge 4 commits intorust-lang:mainfrom
Conversation
|
Some changes occurred in compiler/rustc_hir/src/attrs cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_passes/src/check_attr.rs cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_attr_parsing |
|
just in case we're doing something weird that never got built or linked @bors try jobs=aarch64-apple |
This comment has been minimized.
This comment has been minimized.
error on invalid macho section specifier try-job: aarch64-apple
This comment has been minimized.
This comment has been minimized.
35e0a3f to
c90d31f
Compare
We're trying to move as many checks as possible to attribute parsing, with the "parse, don't validate" mentality, so if an attribute gets through parsing you can assume it is correct. Therefore I'd like this to be in the attribute parser |
|
Reminder, once the PR becomes ready for a review, use |
This comment has been minimized.
This comment has been minimized.
|
💔 Test for 3e6930f failed: CI. Failed job:
|
This comment has been minimized.
This comment has been minimized.
c90d31f to
30b9c6e
Compare
This comment has been minimized.
This comment has been minimized.
30b9c6e to
db42ae2
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
…, r=JonathanBrouwer error on invalid macho section specifier The macho section specifier used by `#[link_section = "..."]` is more strict than e.g. the one for elf. LLVM will error when you get it wrong, which is easy to do if you're used to elf. So, provide some guidance for the simplest mistakes, based on the LLVM validation. Currently compilation fails with an LLVM error, see https://godbolt.org/z/WoE8EdK1K. The LLVM validation logic is at https://github.com/llvm/llvm-project/blob/a0f0d6342e0cd75b7f41e0e6aae0944393b68a62/llvm/lib/MC/MCSectionMachO.cpp#L199-L203 LLVM validates the other components of the section specifier too, but it feels a bit fragile to duplicate those checks. If you get that far, hopefully the LLVM errors will be sufficient to get unstuck. --- sidequest from rust-lang#147811 r? JonathanBrouwer specifically, is this the right place for this sort of validation? `rustc_attr_parsing` also does some validation.
a5691b8 to
896d75e
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@bors try jobs=aarch64-apple |
This comment has been minimized.
This comment has been minimized.
error on invalid macho section specifier try-job: aarch64-apple
| pub(crate) struct LinkSectionParser; | ||
|
|
||
| fn check_link_section_macho(name: Symbol) -> Result<(), InvalidMachoSectionReason> { | ||
| let mut parts = name.as_str().split(',').map(|s| s.trim()); |
There was a problem hiding this comment.
Does LLVM also trim? I don't trim in cg_clif when parsing section names.
There was a problem hiding this comment.
|
💔 Test for 5c7f2d3 failed: CI. Failed job:
|
This comment has been minimized.
This comment has been minimized.
896d75e to
3f4778b
Compare
|
@bors try jobs=aarch64-apple |
This comment has been minimized.
This comment has been minimized.
error on invalid macho section specifier try-job: aarch64-apple
|
💔 Test for b88cc98 failed: CI. Failed job:
|
This comment has been minimized.
This comment has been minimized.
3f4778b to
7aeba4e
Compare
|
These commits modify Please ensure that if you've changed the output:
|
|
@bors try jobs=aarch64-apple |
This comment has been minimized.
This comment has been minimized.
error on invalid macho section specifier try-job: aarch64-apple
|
btw there is some discussion at #t-lang > error on invalid macho section about whether we should FCW this first. This change might break projects that use an invalid section specifier for a symbol that never gets linked. Currently LLVM's codegen would never see that symbol, but with this change |
View all comments
The macho section specifier used by
#[link_section = "..."]is more strict than e.g. the one for elf. LLVM will error when you get it wrong, which is easy to do if you're used to elf. So, provide some guidance for the simplest mistakes, based on the LLVM validation.Currently compilation fails with an LLVM error, see https://godbolt.org/z/WoE8EdK1K.
The LLVM validation logic is at
https://github.com/llvm/llvm-project/blob/a0f0d6342e0cd75b7f41e0e6aae0944393b68a62/llvm/lib/MC/MCSectionMachO.cpp#L199-L203
LLVM validates the other components of the section specifier too, but it feels a bit fragile to duplicate those checks. If you get that far, hopefully the LLVM errors will be sufficient to get unstuck.
sidequest from #147811
r? JonathanBrouwer
specifically, is this the right place for this sort of validation?
rustc_attr_parsingalso does some validation.