!ayCRiZriCVtuCUpeLp:nixos.org

Nix Cross Compiling

582 Members
127 Servers

Load older messages


SenderMessageTime
26 Mar 2025
@stephen:crabsin.spacen3tcatLike so that I have access to an m68k cross compiler for my C code19:07:02
@k900:0upti.meK900We don't have an m68k-unknown-elf platform do we19:07:08
@k900:0upti.meK900 Then something like

let pkgsCrossM68k = import inputs.nixpkgs { system = "x86_64-linux"; cross-system = "m68k-unknown-none-elf"; }; in pkgs.mkShell { ... packages = [ pkgsCrossM68k.stdenv.cc ]; }
19:08:12
@stephen:crabsin.spacen3tcatahh I see19:08:38
@stephen:crabsin.spacen3tcatthank you this is super helpful19:08:43
@stephen:crabsin.spacen3tcat Should that override cc? cc -march=68000 mandelbrot.c says the arch isn't supported. I'm not seeing anything under m68k-* either 19:13:57
@k900:0upti.meK900Uhh19:19:46
@k900:0upti.meK900Can you post the whole thing19:19:48
@k900:0upti.meK900It should be prefixed19:19:56
@stephen:crabsin.spacen3tcat
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils?ref=main";
  };

  outputs =
    inputs:
    inputs.flake-utils.lib.eachDefaultSystem (
      system:
      let
        pkgs = inputs.nixpkgs.legacyPackages.${system};
        pkgsCrossM68k = import "/home/stephen/src/k900/nixpkgs" {
          system = "x86_64-linux"; cross-system = "m68k-unknown-none-elf";
        };
      in
        {
          devShells.default = pkgs.mkShell {
            packages = (
              with pkgs; [
                minipro
                gnumake
                xxd

                pkgsCrossM68k.stdenv.cc
              ]
            );
          };
        }
    );
}

I'm doing nix develop --impure for now. I'll fix the path once things are good

19:20:59
@k900:0upti.meK900 It's crossSystem 19:22:02
@k900:0upti.meK900And yes it takes arbitrary args don't ask19:22:09
@stephen:crabsin.spacen3tcatwell it's hanging and my cpu is at 100% so it's probably building19:26:57
@stephen:crabsin.spacen3tcatyippee this is cool19:27:05
@stephen:crabsin.spacen3tcat

Okay so it seems to be installed! Ty again!
I am unable to use it though. This may not be related to NixOS but I am pretty sure I used this build command on Arch (w/ a custom cross compiler) without issue

m68k-unknown-none-elf-gcc -T Linker.ld -o os.bin -O2 -m68000 -Wall -Wextra -nostdlib start.o main.o -fno-PIE drivers/screen.o drivers/serial.o cpu/interrupt.o cpu/interrupts.o libc/stdlib.o libc/string.o prog/mandelbrot.o prog/memtest.o prog/tty.o   -ffreestanding `m68k-unknown-none-elf-gcc -m68000 -print-libgcc-file-name -ffreestanding`

/nix/store/fmdkz68rg2al0ds776246wkzc12kva5q-m68k-unknown-none-elf-binutils-2.40/bin/m68k-unknown-none-elf-ld: main.o: in function `kmain':
main.c:(.text+0x6): undefined reference to `_GLOBAL_OFFSET_TABLE_'
/nix/store/fmdkz68rg2al0ds776246wkzc12kva5q-m68k-unknown-none-elf-binutils-2.40/bin/m68k-unknown-none-elf-ld: cpu/interrupt.o: in function `error_handler':
interrupt.c:(.text+0x2e): undefined reference to `__stack_chk_guard'
19:57:54
@stephen:crabsin.spacen3tcatThe assembler does work though FYI (:19:58:05
@k900:0upti.meK900
In reply to @stephen:crabsin.space
The assembler does work though FYI (:
Oof it's probably cc-wrapper
20:06:25
@k900:0upti.meK900 Try -fno-stack-protector 20:07:39
@k900:0upti.meK900Or maybe disabling some or most of these 20:08:12
@k900:0upti.meK900 https://github.com/NixOS/nixpkgs/blob/4f61fd53997f76c8d33b01e24dc56c9e9796d811/pkgs/build-support/cc-wrapper/add-hardening.sh#L54 20:08:13
@stephen:crabsin.spacen3tcathmm20:23:09
@stephen:crabsin.spacen3tcatI added the -fno-stack-protector and it unfortunately didn't help any of the errors as far as I can tell20:23:26
@stephen:crabsin.spacen3tcatshould I continue trying to remove more hardening options?20:23:32
@k900:0upti.meK900 Try to just set hardeningDisable = "all" in your shell 20:24:08
@stephen:crabsin.spacen3tcat
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils?ref=main";
  };

  outputs =
    inputs:
    inputs.flake-utils.lib.eachDefaultSystem (
      system:
      let
        pkgs = inputs.nixpkgs.legacyPackages.${system};
        pkgsCrossM68k = import "/home/stephen/src/k900/nixpkgs" {
          system = "x86_64-linux"; crossSystem = "m68k-unknown-none-elf";
        };
      in
        {
          devShells.default = pkgs.mkShell {
            packages = (
              with pkgs; [
                minipro
                gnumake
                xxd

                pkgsCrossM68k.stdenv.cc
              ]
            );

            hardeningDisable = ["all"];
          };
        }
    );
}

This is what my flake.nix looks like now but I'm still getting the same errors when building

20:27:15
@stephen:crabsin.spacen3tcat

I am not sure if this helps or not, but I also tried the following:

	/nix/store/ix4mrsayc4i5d61ar59fh1p33nkxchqv-m68k-unknown-none-elf-gcc-13.2.0/bin/m68k-unknown-none-elf-gcc -T Linker.ld -o os.bin -O2 -m68000 -Wall -Wextra -nostdlib start.o main.o -fno-PIE ${OBJ} -ffreestanding `/nix/store/ix4mrsayc4i5d61ar59fh1p33nkxchqv-m68k-unknown-none-elf-gcc-13.2.0/bin/m68k-unknown-none-elf-gcc -m68000 -print-libgcc-file-name -ffreestanding`

I think this skips the wrapper, but I'm still getting the same error messages

20:31:31
@k900:0upti.meK900Hm 20:33:11
@k900:0upti.meK900Are you sure this is the unwrapped one? 20:33:24
@stephen:crabsin.spacen3tcat

I did

bat /nix/store/9j1jlb4921jrl730rlxjk0sba7d415ni-m68k-unknown-none-elf-gcc-wrapper-13.2.0/bin/m68k-unknown-none-elf-gcc

Which had the following: 28 │ [[ "/nix/store/ix4mrsayc4i5d61ar59fh1p33nkxchqv-m68k-unknown-none-elf-gcc-13.2.0/bin/m68k-unknown-none-elf-gcc" = *++ ]] && isCxx=1 || isCxx=0

So I stole the path from there

20:34:48
@k900:0upti.meK900Oh yeah that makes sensd20:35:18

Show newer messages


Back to Room ListRoom Version: 6