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

(staging) systemd fails to cross compile to arm #86644

Closed
sorki opened this issue May 3, 2020 · 5 comments
Closed

(staging) systemd fails to cross compile to arm #86644

sorki opened this issue May 3, 2020 · 5 comments
Labels
0.kind: bug Something is broken 6.topic: cross-compilation Building packages on a different platform than they will be used on

Comments

@sorki
Copy link
Member

sorki commented May 3, 2020

Describe the bug

Building systemd-boot with EFI support uses host cc and ld correctly but with target arch set to arm resulting in

/nix/store/k930l9lckxjf4zmafv4aapvdbd2sibmj-gcc-wrapper-9.3.0/bin/ld -o src/boot/efi/systemd_boot.so -T /nix/store/zkghrargax07rq16d6wa4r68wa1d7p30-gnu-efi-3.0.11-armv7l-unknown-linux-gnueabihf/lib/elf_arm_efi.lds -shared -Bsymbolic -nostdlib -znocombreloc -L /nix/store/zkghrargax07rq16d6wa4r68wa1d7p30-gnu-efi-3.0.11-armv7l-unknown-linux-gnueabihf/lib /nix/store/zkghrargax07rq16d6wa4r68wa1d7p30-gnu-efi-3.0.11-armv7l-unknown-linux-gnueabihf/lib/crt0-efi-arm.o --defsym=EFI_SUBSYSTEM=0xa src/boot/efi/disk.c.o src/boot/efi/graphics.c.o src/boot/efi/measure.c.o src/boot/efi/pe.c.o src/boot/efi/util.c.o src/boot/efi/boot.c.o src/boot/efi/console.c.o src/boot/efi/crc32.c.o src/boot/efi/random-seed.c.o src/boot/efi/sha256.c.o src/boot/efi/shim.c.o -lefi -lgnuefi /nix/store/ppbczakh03k4ag97v966bh5aw6ps7dqr-armv7l-unknown-linux-gnueabihf-stage-final-gcc-debug-9.3.0/lib/gcc/armv7l-unknown-linux-gnueabihf/9.3.0/libgcc.a
/nix/store/3b3ighb83nhifa1v4n7855hlbdl1mhf9-binutils-2.31.1/bin/ld: cannot represent machine `arm'

Workaround is to disable EFI completely by adding the following to mesonFlags

(if stdenv.hostPlatform != stdenv.targetPlatform then "-Defi=false" else "")

but I would like to fix this correctly.

There's also -Defi-ld flag which can be used to pass another ld but I'm not sure if using target's ld is the right approach here.

To Reproduce

Cross-build to armv7l with current staging.

nixpkgs.crossSystem.system = "armv7l-linux";

Notify maintainers

Ping cross gurus @Mic92 @Ericson2314 @matthewbauer

@sorki sorki added 0.kind: bug Something is broken 6.topic: cross-compilation Building packages on a different platform than they will be used on labels May 3, 2020
@sorki
Copy link
Member Author

sorki commented May 3, 2020

Hm, the workaround doesn't seem to be enough and I've switched it to

    #(if !stdenv.hostPlatform.isEfi then "-Dgnu-efi=false" else "-Dgnu-efi=true")
    "-Defi=false"

@sorki
Copy link
Member Author

sorki commented May 4, 2020

Looks like #72802 adds support for withEfi flag.

@russetrob
Copy link

Firstly, I assume you did check the resulting package runs on arm? I'd be suspicious it's not cross-compiling at all!
You could approach the problem the other way, and get efi linked into the arm build.
For this you'd need to find out why your linker can't understand "arm" as machine name. For instance on a mingw build of ld to cross compile to arm, ld accepts machine of "arm".
You might need to hack the linker command to take option "-marmelf".
It might help take the linker and run "/nix/store/k930l9lckxjf4zmafv4aapvdbd2sibmj-gcc-wrapper-9.3.0/bin/ld --help" the output should specify emulations and output formats supported (Probably a good idea to paste it here, for cross-compile experts to mull over).

@sorki
Copy link
Member Author

sorki commented May 10, 2020

Thanks, the only problem is the EFI (systemd-boot) part, it does cross-compile and works correctly it without it.

Trouble (for me :)) is expressing your suggestion using pkgs.buildPackages or similar. Will take a look at hacking the linker option but my suspicion is that it's not using the correct linker. 🐱 is interefering with my github buttons.

@sorki sorki closed this as completed May 10, 2020
@sorki sorki reopened this May 10, 2020
@sorki
Copy link
Member Author

sorki commented Sep 5, 2020

Fixed by a239864

@sorki sorki closed this as completed Sep 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken 6.topic: cross-compilation Building packages on a different platform than they will be used on
Projects
None yet
Development

No branches or pull requests

2 participants