-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use RelocModel::Pic for UEFI targets #101413
Use RelocModel::Pic for UEFI targets #101413
Conversation
r? @estebank (rust-highfive has picked a reviewer for you, use r? to override) |
|
CCing some folks from #100537: @petrochenkov @dvdhrm @oli-obk |
This comment has been minimized.
This comment has been minimized.
6470745
to
bfac442
Compare
I wonder why is there a DLLImport if dynamic linking is not supported on this target. |
This comment has been minimized.
This comment has been minimized.
bfac442
to
86c0cc7
Compare
@@ -146,9 +146,6 @@ impl Target { | |||
if self.position_independent_executables && !triple.ends_with("-linuxkernel") { | |||
assert_eq!(self.relocation_model, RelocModel::Pic); | |||
} | |||
if self.relocation_model == RelocModel::Pic { | |||
assert!(self.dynamic_linking || self.position_independent_executables); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assert should not be removed in general, you can add an exception for UEFI with an explanation instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should uefi set position_independent_executables and static_position_independent_executables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should uefi set position_independent_executables and static_position_independent_executables?
Hard to tell by reading the in-code docs what these exactly control. But I think codegen_ssa is the only user and it simply causes PIC output requests to be silently converted to NoPIC output requests. In that case, I think UEFI should set both since PIC is technically supported, though not required nor used by anyone I know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this assertion is misleading. UEFI does not support dynamic linking, nor are PIC-executables really necessary. However, it still requires a PIC'ish-reloc-model to allow the custom UEFI loaders to relocate the images during load.
I already mentioned this in #100537, it is not clear to me what effect RelocModel::Static
has. The LLVM docs are basically non-existant. If it causes .reloc
to be stripped from PE32 binaries, then it is not applicable to UEFI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static_position_independent_executables is for when there is no dynamic linker.
Well, yeah, sure, but my question was rather what exactly it controls? Does it make rustc refuse compilation of non-pic? does it enforce static-pic regardless of what the caller chose? Does it mean pic is mandatory, or just supported?
Maybe there is no clear definition like this, and it just controls the one knob we currently have in codegen_ssa. That would be fine with me. In that case, UEFI should probably set this to true
.
it is not clear to me what effect RelocModel::Static has.
AFAIK it fixes a specific load location at link time (eg 0x10000, depends on the linker) as opposed to allowing it to be loaded anywhere at runtime as with RelocModel::Pic.
I see. This likely means on PE32 .reloc
is stripped and relocation is not supported? In that case, I think the assertion is wrong and needs to go. A relocatable binary should not imply dynamic-linking or position-independen-code. Since reloc and PIC are different things on UEFI (and also on Windows).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, yeah, sure, but my question was rather what exactly it controls? Does it make rustc refuse compilation of non-pic? does it enforce static-pic regardless of what the caller chose? Does it mean pic is mandatory, or just supported?
It controls if pic compilation is supported or not. It doesn't make it mandatory. In the linker code for the msvc linker it doesn't distinguish between pic and non-pic executables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested adding this into uefi_msvc_base
:
position_independent_executables: true,
static_position_independent_executables: true,
and it doesn't seem to cause any problem, at least in the simple test I did. Do you want me to add that to this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Friendly ping -- should I add the above lines to this PR? Or should we stick to the existing changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure.
86c0cc7
to
c52e25d
Compare
Looks good to me! As mentioned on the linked bug-report, I think we need to investigate why we end up with |
r? @petrochenkov |
In rust-lang#100537, the relocation model for UEFI targets was changed from PIC (the default value) to static. There was some dicussion of this change here: rust-lang#100537 (comment) It turns out that this can cause compilation to fail as described in rust-lang#101377, so switch back to PIC. Fixes rust-lang#101377
c52e25d
to
54d9ba8
Compare
@rustbot review |
@bors r+ rollup |
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#101413 (Use RelocModel::Pic for UEFI targets) - rust-lang#101595 (Fix ICE report flags display.) - rust-lang#101616 (Adapt test for msan message change) - rust-lang#101624 (rustdoc: remove unused CSS `#search { position: relative }`) - rust-lang#101633 (Rustdoc-Json: Correcty handle intra-doc-links to items without HTML page) - rust-lang#101634 (Rustdoc-Json Tests: Use ``@is`` and ``@ismany`` more often.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
FYI I've filed a followup ticket here: #101656 |
In #100537, the relocation model for UEFI targets was changed from PIC (the default value) to
static. There was some dicussion of this change here: #100537 (comment)
It turns out that this can cause compilation to fail as described in #101377, so switch back to PIC.
Fixes #101377