Skip to content

Instantly share code, notes, and snippets.

@steveklabnik
Last active September 26, 2016 16:12
Embed
What would you like to do?

Can I compile a 32-bit .a and then link it into a 64-bit application? This is x86 specifically.

At the moment, I have a file written in assembly, with nasm, that uses BITS 32 to ensure that it's only generating x86 stuff. I then link it into my x86-64 code generated from Rust. I'd like to port that asm to Rust. (which will of course also need some inline asm but that's a distraction). I have that compiling into a .a, but when I try to link that into my x86-64 code, ld isn't happy:

note: /usr/bin/ld: skipping incompatible ./libboot.a when searching for -lboot

Any thoughts?

(This is specifically doing the "GRUB dumps you in protected mode and I need to transition to long mode" code.)

@mkpankov
Copy link

Don't think it's possible without ugly hacks, no. It looks at ELF headers and finds the objects in .a are 32-bit. You can check if that's the case with readelf -h .

@steveklabnik
Copy link
Author

@mkpankov ah yeah, ELF32. Hmmmmmmmmmmm

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