Change:
printWords "''${ldflagsBefore[@]}" > $out/nix-support/libc-ldflags-before '') <ins> + optionalString stdenv.targetPlatform.isMacOS '' # Ensure consistent LC_VERSION_MIN_MACOSX and remove LC_UUID. echo "-macosx_version_min 10.12 -sdk_version 10.12 -no_uuid" >> $out/nix-support/libc-ldflags-before '' </ins> + optionalString (!nativeTools) '' ## ## User env support

Discussion:
Describe the bug I was trying to build a Linux cross compiler on Darwin, but it fails when configuring glibc. To Reproduce Steps to reproduce the behavior: Expected behavior Cross-compiled glibc should be built. Additional context I believe this is related to . Commendable work has been done there, but the passing of macOS-specific linker options in appears to be problematic for cross builds. I am not knowledgeable enough about Nix’ cross compilation infrastructure to fully diagnose the problem, let alone suggest a fix. But I think should not be passed to linkers targeting non-Darwin platforms, because they would not understand the options. Metadata system: host os: multi-user?: sandbox: version: channels(Michael): nixpkgs:
Yeah, I'm not sure the best way to deal with this. Perhaps we can set instead of . /cc
I guess that might make sense if dyld isn't used as the linker in that case. Could run and post the output of a cross compiled binary?
I think we have to separate between binaries being hosted on the local platform, but targetting the cross platform and those already intended to run on the cross platform. The Linux linker falls into the first category. It creates Linux executables, but runs on macOS. It is linked like this: would fall in the second category. To build , the Linux linker is invoked with macOS-specific linker flags from , which it does not understand. Therefore, fails in the configure step.
I'm looking for the output of the lowecase flag.
Sorry. Stupid me. I’m on a different machine now, and here I have a version of the x8664 Linux Linker. I hope that’s OK for you. <details<summaryCommand Output</summary/nix/store/ayc7d1h0alm1y2pysr2hbv183g7d6ji7-x8664-unknown-linux-gnu-binutils-2.31.1/bin/x8664-unknown-linux-gnu-ld: Mach header magic cputype cpusubtype caps filetype ncmds sizeofcmds flags 0xfeedfacf 3 0x80 2 18 2192 0x00200085 Load command 0 cmd LCSEGMENT64 cmdsize 72 segname PAGEZERO vmaddr 0x0000000000000000 vmsize

0x0000000100000000 fileoff 0 filesize 0 maxprot 0x00000000 initprot 0x00000000 nsects 0 flags 0x0 Load command 1 cmd LCSEGMENT64 cmdsize 552 segname TEXT vmaddr 0x0000000100000000 vmsize 0x0000000000164000 fileoff 0 filesize maxprot 0x00000007 initprot 0x00000005 nsects 6 flags 0x0 Section sectname text segname TEXT addr 0x0000000100000d70 size 0x0000000000040113 offset 3440 align 2^4 (16) reloff 0 nreloc 0 flags 0x80000400 reserved1 0 reserved2 0 Section sectname stubs segname TEXT addr 0x0000000100040e84 size 0x0000000000000492 offset align 2^1 (2) reloff 0 nreloc 0 flags 0x80000408 reserved1 0 (index into indirect symbol table) reserved2 6 (size of stubs) Section sectname stubhelper segname TEXT addr 0x0000000100041318 size 0x00000000000007ae offset align 2^2 (4) reloff 0 nreloc 0 flags 0x80000400 reserved1 0 reserved2 0 Section sectname cstring segname TEXT addr 0x0000000100041ac6 size 0x0000000000118403 offset align 2^0 (1) reloff 0 nreloc 0 flags 0x00000002 reserved1 0 reserved2 0 Section sectname const segname TEXT addr 0x0000000100159ed0 size 0x0000000000009c30 offset align 2^4 (16) reloff 0 nreloc 0 flags 0x00000000 reserved1 0 reserved2 0 Section sectname unwindinfo segname TEXT addr 0x0000000100163b00 size 0x00000000000004f4 offset align 2^2 (4) reloff 0 nreloc 0 flags 0x00000000 reserved1 0 reserved2 0 Load command 2

cmd LCSEGMENT64 cmdsize 632 segname DATA vmaddr 0x0000000100164000 vmsize 0x0000000000007000 fileoff filesize maxprot 0x00000007 initprot 0x00000003 nsects 7 flags 0x0 Section sectname nlsymbolptr segname DATA addr 0x0000000100164000 size 0x0000000000000010 offset align 2^3 (8) reloff 0 nreloc 0 flags 0x00000006 reserved1 195 (index into indirect symbol table) reserved2 0 Section sectname got segname DATA addr 0x0000000100164010 size 0x0000000000000078 offset align 2^3 (8) reloff 0 nreloc 0 flags 0x00000006 reserved1 197 (index into indirect symbol table) reserved2 0 Section sectname lasymbolptr segname DATA addr 0x0000000100164088 size 0x0000000000000618 offset align 2^3 (8) reloff 0 nreloc 0 flags 0x00000007 reserved1 212 (index into indirect symbol table) reserved2 0 Section sectname const segname DATA addr 0x00000001001646a0 size 0x0000000000004230 offset align 2^4 (16) reloff 0 nreloc 0 flags 0x00000000 reserved1 0 reserved2 0 Section sectname data segname DATA addr 0x00000001001688d0 size 0x00000000000010b0 offset align 2^4 (16) reloff 0 nreloc 0 flags 0x00000000 reserved1 0 reserved2 0 Section sectname bss segname DATA addr 0x0000000100169980 size 0x0000000000000d00 offset 0 align 2^4 (16) reloff 0 nreloc 0 flags 0x00000001 reserved1 0 reserved2 0 Section sectname common segname DATA addr 0x000000010016a680 size 0x0000000000000454 offset 0 align 2^3 (8) reloff 0 nreloc

0 flags 0x00000001 reserved1 0 reserved2 0 Load command 3 cmd LCSEGMENT64 cmdsize 72 segname LINKEDIT vmaddr 0x000000010016b000 vmsize 0x000000000000c814 fileoff filesize maxprot 0x00000007 initprot 0x00000001 nsects 0 flags 0x0 Load command 4 cmd LCDYLDINFOONLY cmdsize 48 rebaseoff rebasesize 800 bindoff bindsize 304 weakbindoff 0 weakbindsize 0 lazybindoff lazybindsize 4600 exportoff exportsize 7256 Load command 5 cmd LCSYMTAB cmdsize 24 symoff nsyms 1022 stroff strsize Load command 6 cmd LCDYSYMTAB cmdsize 80 ilocalsym 0 nlocalsym 470 iextdefsym 470 nextdefsym 346 iundefsym 816 nundefsym 206 tocoff 0 ntoc 0 modtaboff 0 nmodtab 0 extrefsymoff 0 nextrefsyms 0 indirectsymoff nindirectsyms 407 extreloff 0 nextrel 0 locreloff 0 nlocrel 0 Load command 7 cmd LCLOADDYLINKER cmdsize 32 name /usr/lib/dyld (offset 12) Load command 8 cmd LCVERSIONMINMACOSX cmdsize 16 version 10.12 sdk 10.12 Load command 9 cmd LCSOURCEVERSION cmdsize 16 version 0.0 Load command 10 cmd LCMAIN cmdsize 24 entryoff stacksize 0 Load command 11 cmd LCLOADDYLIB cmdsize 184 name /nix/store/ayc7d1h0alm1y2pysr2hbv183g7d6ji7-x8664-unknown-linux-gnu-binutils-2.31.1/x8664-apple-darwin/x8664-unknown-linux-gnu/lib/libbfd- (offset 24) time stamp 2 Thu Jan 1 01:00:02 1970 current version 0.0.0 compatibility version 0.0.

0 Load command 12 cmd LCLOADDYLIB cmdsize 112 name /nix/store/fxvxl64g1b336ayhzsrqdcv541zpb6lx-Libsystem-osx- (offset 24) time stamp 2 Thu Jan 1 01:00:02 1970 current version 1226.10.1 compatibility version 1.0.0 Load command 13 cmd LCLOADDYLIB cmdsize 96 name /nix/store/ww5azqlhhp064brjqi7k2c6s30qsi0bg-zlib- (offset 24) time stamp 2 Thu Jan 1 01:00:02 1970 current version 1.2.11 compatibility version 1.0.0 Load command 14 cmd LCLOADDYLIB cmdsize 104 name /nix/store/rb3m0xyx1l1jg2bl837w11jhm6ax1yrs-gettext- (offset 24) time stamp 2 Thu Jan 1 01:00:02 1970 current version 10.6.0 compatibility version 10.0.0 Load command 15 cmd LCRPATH cmdsize 96 path /nix/store/dbs6flb7c6rbvb3n4q4i6ad0nmhw1iaj-swift-corefoundation/Library/Frameworks (offset 12) Load command 16 cmd LCFUNCTIONSTARTS cmdsize 16 dataoff datasize 840 Load command 17 cmd LCDATAIN_CODE cmdsize 16 dataoff datasize 288 </details
Great, looks like the flags are not relevant in that case. I'll make it conditional.
Actually, I'm not sure how to conditionalize this.
I have not tried, this is just a guess: Would it work to set instead of ?
I don't think so, it shouldn't happen for both darwin-linux as well as linux-darwin and that would only handle one of those. It also seems brittle, the infiix salt is an implementation detail of the ld wrappers. Perhaps somebody with more knowledge of the cross infrastructure has an idea on how to add this without polluting stdenv/generic with these details.

This is kind of the problem I'm running into
If I diagnose the problem correctly, only the Apple’s linker understands these flags, the GNU binutils do not. Do you think this is correct? If so, wouldn’t it make more sense to add these linker flags to the package instead of ?
Now that is merged, this should be fixed and can be closed, right?
I tried testing this, but the fix has been merged to and I am not sure what is needed for this to propagate to the Nixpkgs channel. Trying to cross-compile on fails for me with errors unrelated to this issue here, so I have trouble confirming that the fix works. From all I have seen, I would assume it does, though.