Skip to content

Investigate why the UEFI targets produce executables with DLLImport annotations #101656

Closed
@nicholasbishop

Description

@nicholasbishop
Contributor

This is a followup to #101377.

Originally posted by @dvdhrm in #101377 (comment):

It feels wrong to produce executables with DLLImport annotations, knowing that UEFI loaders will never read .idata sections. While technically they could, I am not aware of any such implementations and the spec clearly states All other linkage to and from an UEFI image is done programmatically.

Activity

changed the title [-]Investigate why the UEFI targets produce executables with `DLLImport` annotatiosn[/-] [+]Investigate why the UEFI targets produce executables with `DLLImport` annotations[/+] on Sep 10, 2022
added
A-linkageArea: linking into static, shared libraries and binaries
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Sep 10, 2022
dvdhrm

dvdhrm commented on Nov 21, 2022

@dvdhrm
Contributor

I tracked this down. The error we get is in the LLVM IR verification. Globals (code, data, ...) are called GlobalValue in the IR and can have a set of attributes. One of those is called dso_local (the linker / lto-compiler can rely on the symbol to be local and not interposable), another is called dllimport which just tells the compiler to use indirect-calls as is common for dll imports.

The llvm-codegen always marks rust symbols from crates other than the current compilation as DllImport (search for DllImport in compiler/rustc_codegen_llvm/src/consts.rs). This allows dynamic linking between rust crates, while relying on the linker to correctly fix things up when linking statically.

At the same time, when dropping PIC and using the static relocation model, all symbols in a compilation are marked as dso_local, because the assumption is that nothing is ever linked dynamically. LLVM now correctly complains that the combination makes no sense.

I think the underlying issue is that LLVM does not silently ignore DllImport, while rustc assumes that it is safe to set DllImport even when linking statically. One possible solution would be to never set DllImport if the target uses a static relocation model. This should fix the issue, but... I don't have enough insight into the LLVM codegen right now to evaluate whether this is the correct approach. I will try to file a PR and then we can continue discussion there.

added 2 commits that reference this issue on Nov 23, 2022

Rollup merge of rust-lang#104679 - dvdhrm:rw/dso, r=petrochenkov

9c91297

Rollup merge of rust-lang#104679 - dvdhrm:rw/dso, r=petrochenkov

b69a9f0
added a commit that references this issue on Nov 30, 2022

Auto merge of rust-lang#104679 - dvdhrm:rw/dso, r=petrochenkov

dvdhrm

dvdhrm commented on Nov 30, 2022

@dvdhrm
Contributor

This is now fixed with a0771bd (issue #104679). @nicholasbishop you want to close this?

nicholasbishop

nicholasbishop commented on Nov 30, 2022

@nicholasbishop
ContributorAuthor

Closing, thanks for fixing that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesO-UEFIUEFIT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @dvdhrm@nicholasbishop@bjorn3

        Issue actions

          Investigate why the UEFI targets produce executables with `DLLImport` annotations · Issue #101656 · rust-lang/rust