Skip to content

ABI differs when generated by different architecture compilers #29235

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

Closed
alexcrichton opened this issue Oct 22, 2015 · 4 comments
Closed

ABI differs when generated by different architecture compilers #29235

alexcrichton opened this issue Oct 22, 2015 · 4 comments
Labels
A-codegen Area: Code generation T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@alexcrichton
Copy link
Member

For example, given this file:

// foo.rs
#![crate_type = "lib"]   
pub fn foo() {}          

We get compiles looking like this:

# Using an i686-unknown-linux-gnu host rustc
$ rustc foo.rs --emit obj
$ nm -g foo.o
00000000 T _ZN3foo20hcfee31b285b97994eaaE

# Using an x86_64-unknown-linux-gnu host rustc
$ rustc foo.rs --emit obj
$ nm -g foo.o
0000000000000000 T _ZN3foo20hf85c4a4e2bec9df7eaaE

The relevant parts being:

_ZN3foo20hcfee31b285b97994eaaE
_ZN3foo20hf85c4a4e2bec9df7eaaE

Surprisingly enough, the symbols are different!

This doesn't have too many implications today, the major one I can think of is #29228 which means that libraries generated by an x86_64 compiler cannot be used as plugins to an i686 compiler. I don't think there's any fundamental reason this is happening today, it just sounds like a bug where our hashing is architecture dependent somewhere.

@alexcrichton alexcrichton added the A-codegen Area: Code generation label Oct 22, 2015
@alexcrichton
Copy link
Member Author

I'll also note that the only place I know of where hashing is pointer-size-dependent is when hashing usize, so there's probably just one of those or a slice/string somewhere along the road which we're hashing (the length could probably just be a u32 in this case).

@huonw huonw added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 22, 2015
@sorear
Copy link
Contributor

sorear commented Oct 28, 2015

I found one of the places this happens a couple weeks ago as part of what I did to #10389:

https://github.com/sorear/vow-rs/blob/master/src/main.rs#L121

hash!(inner.len());

@chordowl
Copy link
Contributor

chordowl commented Mar 28, 2017

Triage: seems fixed on stable
With the same file as in the original report. I get the following on stable-{i686,x86_64}-pc-windows-gnu:

# Using an i686-pc-windows-gnu host rustc
$ rustc foo.rs --emit obj
$ nm -g foo.o
00000000 T __ZN3foo3foo17h83583f8ff17ec21aE
# Using a x86_64-pc-windows-gnu host rustc
$ rustc foo.rs --emit obj
$ nm -g foo.o
0000000000000000 T _ZN3foo3foo17h83583f8ff17ec21aE

The relevant parts are identical now, save for the usual additional underscore on i686:

__ZN3foo3foo17h83583f8ff17ec21aE
 _ZN3foo3foo17h83583f8ff17ec21aE
Meta
rustc 1.16.0 (30cf806ef 2017-03-10)
binary: rustc
commit-hash: 30cf806ef8881c41821fbd43e5cf3699c5290c16
commit-date: 2017-03-10
host: i686-pc-windows-gnu
release: 1.16.0
LLVM version: 3.9

rustc 1.16.0 (30cf806ef 2017-03-10)
binary: rustc
commit-hash: 30cf806ef8881c41821fbd43e5cf3699c5290c16
commit-date: 2017-03-10
host: x86_64-pc-windows-gnu
release: 1.16.0
LLVM version: 3.9

@arielb1
Copy link
Contributor

arielb1 commented Mar 28, 2017

I don't think that symbols depending on the target ABI is a problem - different target ABIs are, well, ABI-incompatible.

@arielb1 arielb1 closed this as completed Mar 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants