-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add the relocation_model to the cfg #113966
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
Conversation
r? @b-naber (rustbot has picked a reviewer for you, use r? to override) |
These commits modify compiler targets. |
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 just thought of a possible issue. There is no guarantee in which crate a function is codegened, but |
The information is mainly useful to correctly consume symbols made available via |
If you have //- lib.rs compileflags:-Crelocation-model=static -Clto=yes --edition 2021
static FOO: u8 = 42;
pub unsafe fn foo() {
#[cfg(relocation_model = "static")]
core::arch::asm!("mov dword ptr [{}], 43", sym FOO);
#[cfg(relocation_model = "pic")]
core::arch::asm!("mov dword ptr [rip + {}], 43", sym FOO);
}
//- bar.rs compileflags:-Crelocation-model=pic -Clto=yes --extern lib=liblib.rlib --edition 2021
fn main() {
unsafe { lib::foo(); }
} Then |
In most cases |
clang and gcc with any bit of inline asm with "m" constraint have to deal with it already, what do they do? |
For LTO I think just accept that it happens and for inline and generic functions in C and C++ you need to include the header file, which will evaluate the |
the equivalent C code is // lib.c - cc -c lib.c -fno-lto -flto -o lib.o
unsigned char FOO = 42;
void foo() {
#ifdef __PIC__
...
#else
...
#endif
} // main.c - cc -c main.c -flto -fPIC -o main.o
void foo();
int main() {
foo();
return 0;
}
The linker simply bails. (here the test https://gist.github.com/lu-zero/d4188ed4837c112d6584a5b4de67bca6) |
Generally you would never have a library that is "less PIC" than the binary using it. So this case should never happen in practice if you using a build system like Cargo. |
r? compiler |
r? @bjorn3 |
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 will need a test.
3118552
to
045bb9e
Compare
@bors r+ |
📌 Commit 045bb9e0ae5e8ea323be05a75c31c547aa08641b has been approved by It is now in the queue for this repository. |
⌛ Testing commit 045bb9e0ae5e8ea323be05a75c31c547aa08641b with merge 01e78a6c25d3590b98677fd03ae1a13333875b18... |
@bors r+ |
📌 Commit 443d1e3819cf34786f91a1156d9818a9bbf59244 has been approved by It is now in the queue for this repository. |
⌛ Testing commit 443d1e3819cf34786f91a1156d9818a9bbf59244 with merge cf492d9ce554381760e95851e23874a8d846db6f... |
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
443d1e3
to
28ebdf6
Compare
Looks like you did something wrong when rebasing. There are a couple of unrelated commits. |
This comment has been minimized.
This comment has been minimized.
28ebdf6
to
c7dedf7
Compare
Let see if manually rebasing fixes it. |
Hopefully no other targets are pic-impossible. |
This comment has been minimized.
This comment has been minimized.
This way is possible to write inline assembly code aware of it.
c7dedf7
to
c0394c8
Compare
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (82c5732): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 634.076s -> 635.189s (0.18%) |
This way is possible to write inline assembly code aware of it.