Skip to content
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

Merged

Conversation

nicholasbishop
Copy link
Contributor

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

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 4, 2022
@rust-highfive
Copy link
Collaborator

r? @estebank

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive
Copy link
Collaborator

⚠️ Warning ⚠️

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 4, 2022
@nicholasbishop
Copy link
Contributor Author

CCing some folks from #100537: @petrochenkov @dvdhrm @oli-obk

@rust-log-analyzer

This comment has been minimized.

@petrochenkov
Copy link
Contributor

GlobalValue with DLLImport Storage is dso_local!

I wonder why is there a DLLImport if dynamic linking is not supported on this target.
(I'm ok with partially reverting #100537 if this needs to be fixed fast.)

@rust-log-analyzer

This comment has been minimized.

@@ -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);
}
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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).

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure.

@dvdhrm
Copy link
Contributor

dvdhrm commented Sep 5, 2022

Looks good to me! As mentioned on the linked bug-report, I think we need to investigate why we end up with DLLImport, though. This should not happen as EFI loaders will ignore .idata sections.

@petrochenkov
Copy link
Contributor

r? @petrochenkov
r=me after small cleanup (#101413 (comment)).
@rustbot author

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 9, 2022
@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Sep 9, 2022
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
@nicholasbishop
Copy link
Contributor Author

@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 10, 2022
@petrochenkov
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Sep 10, 2022

📌 Commit 54d9ba8 has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 10, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 10, 2022
…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
@bors bors merged commit 857a43d into rust-lang:master Sep 10, 2022
@rustbot rustbot added this to the 1.65.0 milestone Sep 10, 2022
@nicholasbishop nicholasbishop deleted the bishop-remove-uefi-static-reloc branch September 10, 2022 15:16
@nicholasbishop
Copy link
Contributor Author

FYI I've filed a followup ticket here: #101656

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-UEFI UEFI S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Regression] GlobalValue with DLLImport Storage is dso_local!
10 participants