!ayCRiZriCVtuCUpeLp:nixos.org

Nix Cross Compiling

581 Members
127 Servers

Load older messages


SenderMessageTime
28 Mar 2025
@k900:0upti.meK900github.com/NixOS/nixpkgs/pull/39365515:27:58
@k900:0upti.meK900* https://github.com/NixOS/nixpkgs/pull/39365515:28:02
@k900:0upti.meK900(on native)15:28:07
@scottytheengineer:matrix.orgscottytheengineer joined the room.18:15:50
@stephen:crabsin.spacen3tcat

K900 Alright this may be a NixOS related cross compiling question but maybe not.

I have a very simple C program that looks like this:

void _start() {
  volatile long *a = (long *)0x1FFA0;
  volatile long *b = (long *)0x1FFA8;
  volatile long *c = (long *)0x1FFB0;

  *c = *b / *a;

  for(;;) {}
}

This relies on doing software division (the actual hardware instruction can only do 32 bit / 16 bit -> 16 bit or something like that). So it calls __divsi3.

__divsi3 seems to be compiled incorrectly. It tries to use a BSR.L instruction, which doesn't exist on the m68k. It only has the BSR.W and BSR.B instructions. I am wondering what I would need to do to fix this

20:16:07
@k900:0upti.meK900 Maybe you need the right -march? 20:16:52
@stephen:crabsin.spacen3tcat I'm using -m68000 and I've tried playing around with the -march flags. It seems like my actual code compiles just fine but it's almost like the __whatever helpers are being compiled for the wrong CPU 20:17:27
@stephen:crabsin.spacen3tcat
test.bin: test.o Linker.ld
	m68k-unknown-none-elf-gcc -T Linker.ld -o test.bin -O2 -m68000 -Wall -Wextra -nostdlib test.o -ffreestanding -lgcc

%.o: %.c
	m68k-unknown-none-elf-gcc -m68000 -c $< -o $@ -ffreestanding -nostdlib -O0 -Wall -Wextra -fno-PIC -static-libgcc

Here's my makefile btw

20:17:43
@k900:0upti.meK900Oh 20:18:27
@k900:0upti.meK900Yeah that could be it 20:18:31
@k900:0upti.meK900If those are coming from newlib 20:18:37
@k900:0upti.meK900 And newlib is using a wrong -march too 20:18:44
@k900:0upti.meK900And you're just linking an already built newlib20:18:58
@stephen:crabsin.spacen3tcat I think they might be? I am not entirely sure what -lgcc and -static-libgcc do - I assume they link into newlib 20:19:12
@k900:0upti.meK900No, that's libgcc20:19:31
@k900:0upti.meK900But it could be the same thing 20:19:45
@k900:0upti.meK900Uhh there is a setting for this 20:20:37
@k900:0upti.meK900Somewhere 20:20:39
@stephen:crabsin.spacen3tcatLike for choosing how libgcc is compiled?20:20:57
@k900:0upti.meK900Like you can set march in the platform definition 20:20:59
@k900:0upti.meK900Somewhere 20:21:08
@k900:0upti.meK900 OK so here's the way I remember this can work 20:23:09
@stephen:crabsin.spacen3tcatwould this be a gcc setting or a nix setting? I am struggling to find anything20:23:09
@k900:0upti.meK900 You can use lib.systems.elaborate "m68k-unknown-none-elf" 20:23:32
@k900:0upti.meK900In a REPL or something 20:23:38
@k900:0upti.meK900That will shit out a huge attrset 20:23:44
@k900:0upti.meK900 That you can take and pass to crossSystem instead of just the triple 20:24:04
@k900:0upti.meK900And hopefully that attrset will have a place to put the right march value in 20:24:27
@k900:0upti.meK900That will hopefully be obvious from the name 20:24:35
@stephen:crabsin.spacen3tcat Sick! I have never used the nix repl before, do I have to do something to define lib? 20:24:42

Show newer messages


Back to Room ListRoom Version: 6