marler8997 / ziglibc

193 stars 19 forks source link

Linker errors on using C compilers apart from `zig cc` #10

Open Shinyzenith opened 1 year ago

Shinyzenith commented 1 year ago

Hi! First of all, this is a really cool project and I'd love to contribute! (Commit hash of ziglibc: d6b6959) I was wondering if it'd be possible to make ziglibc work in contexts outside of zig such as with clang or any system $CC?

Currently on attempting to link with clang I get the following linker errors:

clang -nostdlib -I ../../inc/libc -I ../../inc/posix/ -I ../../inc/linux/ -L. -static -lstart -lcguana main.c /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `target.Target.Cpu.Feature.feature_set_fns(target.x86.Feature).featureSet': /usr/lib/zig/std/target.zig:774: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/target.zig:778: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `target.Target.Cpu.Feature.Set.empty_workaround': /usr/lib/zig/std/target.zig:698: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `debug.panicExtra__anon_1050': /usr/lib/zig/std/debug.zig:294: undefined reference to `__zig_probe_stack' /usr/bin/ld: /usr/lib/zig/std/debug.zig:299: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `debug.resetSegfaultHandler': /usr/lib/zig/std/debug.zig:1888: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `os.linux.tls.initTLS': /usr/lib/zig/std/os/linux/tls.zig:200: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/os/linux/tls.zig:201: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/os/linux/tls.zig:202: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `debug.attachSegfaultHandler': /usr/lib/zig/std/debug.zig:1869: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `debug.getSelfDebugInfo': /usr/lib/zig/std/debug.zig:107: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/debug.zig:107: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `debug.openSelfDebugInfo': /usr/lib/zig/std/debug.zig:815: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/debug.zig:815: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `debug.DebugInfo.lookupModuleDl': /usr/lib/zig/std/debug.zig:1381: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/debug.zig:1381: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/debug.zig:1438: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `dwarf.DwarfInfo.parseAbbrevTable': /usr/lib/zig/std/dwarf.zig:1015: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:1024: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:1025: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:1025: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o):/usr/lib/zig/std/dwarf.zig:1028: more undefined references to `memcpy' follow /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `dwarf.DwarfInfo.scanAllFunctions': /usr/lib/zig/std/dwarf.zig:727: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:735: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:736: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:761: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:784: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:795: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:806: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `array_list.ArrayListAlignedUnmanaged(dwarf.Func,null).append': /usr/lib/zig/std/array_list.zig:562: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `dwarf.DwarfInfo.parseDie__anon_5615': /usr/lib/zig/std/dwarf.zig:1056: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o):/usr/lib/zig/std/dwarf.zig:1057: more undefined references to `memcpy' follow /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `dwarf.DwarfInfo.scanAllCompileUnits': /usr/lib/zig/std/dwarf.zig:868: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:876: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:877: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:902: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `array_list.ArrayListAlignedUnmanaged(dwarf.CompileUnit,null).append': /usr/lib/zig/std/array_list.zig:562: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `debug.readElfDebugInfo': /usr/lib/zig/std/debug.zig:911: undefined reference to `__zig_probe_stack' /usr/bin/ld: /usr/lib/zig/std/debug.zig:913: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/debug.zig:915: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/debug.zig:916: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/debug.zig:921: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/debug.zig:929: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o):/usr/lib/zig/std/debug.zig:955: more undefined references to `memcpy' follow /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `os.dl_iterate_phdr__anon_4931': /usr/lib/zig/std/os.zig:5387: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/os.zig:5388: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `fs.Dir.openFile': /usr/lib/zig/std/fs.zig:1093: undefined reference to `__zig_probe_stack' /usr/bin/ld: /usr/lib/zig/std/fs.zig:1101: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `debug.printLineFromFileAnyOs__anon_5636': /usr/lib/zig/std/debug.zig:1131: undefined reference to `__zig_probe_stack' /usr/bin/ld: /usr/lib/zig/std/debug.zig:1138: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `debug.printLineInfo__anon_5626': /usr/lib/zig/std/debug.zig:756: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `debug.ModuleDebugInfo__struct_4249.getSymbolAtAddress': /usr/lib/zig/std/debug.zig:1777: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `debug.getSymbolFromDwarf': /usr/lib/zig/std/debug.zig:1803: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/debug.zig:1805: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/debug.zig:1803: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o):/usr/lib/zig/std/debug.zig:1812: more undefined references to `memcpy' follow /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `dwarf.DwarfInfo.getLineNumberInfo': /usr/lib/zig/std/dwarf.zig:1090: undefined reference to `__zig_probe_stack' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:1095: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:1096: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:1096: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:1100: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:1101: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:1103: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:1107: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:1108: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:1113: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o):/usr/lib/zig/std/dwarf.zig:1114: more undefined references to `memcpy' follow /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `dwarf.DwarfInfo.getLineNumberInfo': /usr/lib/zig/std/dwarf.zig:1181: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:1154: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:1157: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:1159: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:1163: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:1165: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o):/usr/lib/zig/std/dwarf.zig:1166: more undefined references to `memcpy' follow /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `dwarf.DwarfInfo.getLineNumberInfo': /usr/lib/zig/std/dwarf.zig:1219: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:1220: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:1221: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:1224: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:1225: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:1229: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o):/usr/lib/zig/std/dwarf.zig:1230: more undefined references to `memcpy' follow /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `mem.Allocator.free__anon_5660': /usr/lib/zig/std/mem/Allocator.zig:494: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `array_list.ArrayListAligned(dwarf.FileEntry,null).append': /usr/lib/zig/std/array_list.zig:168: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `array_list.ArrayListAligned(dwarf.FileEntry,null).appendAssumeCapacity': /usr/lib/zig/std/array_list.zig:176: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `dwarf.LineNumberProgram.init': /usr/lib/zig/std/dwarf.zig:438: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:438: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:438: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:438: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/dwarf.zig:438: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o):/usr/lib/zig/std/dwarf.zig:438: more undefined references to `memset' follow /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `debug.SymbolInfo.deinit': /usr/lib/zig/std/debug.zig:66: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `Thread.Futex.LinuxImpl.wait': /usr/lib/zig/std/Thread/Futex.zig:246: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `debug.handleSegfaultPosix': /usr/lib/zig/std/debug.zig:1933: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/debug.zig:1940: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `fmt.formatInt__anon_6086': /usr/lib/zig/std/fmt.zig:1428: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `fmt.formatInt__anon_6198': /usr/lib/zig/std/fmt.zig:1428: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `os.linux.sigaction': /usr/lib/zig/std/os/linux.zig:1149: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/os/linux.zig:1150: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/os/linux.zig:1157: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `debug.panicExtra__anon_6214': /usr/lib/zig/std/debug.zig:294: undefined reference to `__zig_probe_stack' /usr/bin/ld: /usr/lib/zig/std/debug.zig:299: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `mem.Allocator.allocAdvancedWithRetAddr__anon_6376': /usr/lib/zig/std/mem/Allocator.zig:308: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `os.toPosixPath': /usr/lib/zig/std/os.zig:5494: undefined reference to `__zig_probe_stack' /usr/bin/ld: /usr/lib/zig/std/os.zig:5496: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/os.zig:5498: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/os.zig:5501: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/os.zig:5501: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `fs.file.File.stat': /usr/lib/zig/std/fs/file.zig:344: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `array_list.ArrayListAligned(dwarf.AbbrevAttr,null).allocatedSlice': /usr/lib/zig/std/array_list.zig:436: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `mem.Allocator.free__anon_6438': /usr/lib/zig/std/mem/Allocator.zig:494: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `array_list.ArrayListAligned(dwarf.AbbrevTableEntry,null).allocatedSlice': /usr/lib/zig/std/array_list.zig:436: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `mem.Allocator.free__anon_6439': /usr/lib/zig/std/mem/Allocator.zig:494: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `mem.Allocator.allocAdvancedWithRetAddr__anon_6468': /usr/lib/zig/std/mem/Allocator.zig:308: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `mem.Allocator.allocAdvancedWithRetAddr__anon_6481': /usr/lib/zig/std/mem/Allocator.zig:308: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `array_list.ArrayListAligned(u8,null).allocatedSlice': /usr/lib/zig/std/array_list.zig:436: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `debug.panicExtra__anon_6644': /usr/lib/zig/std/debug.zig:294: undefined reference to `__zig_probe_stack' /usr/bin/ld: /usr/lib/zig/std/debug.zig:299: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `os.fstat': /usr/lib/zig/std/os.zig:4142: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/os.zig:4137: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/os.zig:4137: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/os.zig:4140: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/os.zig:4141: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `io.reader.Reader(*io.fixed_buffer_stream.FixedBufferStream([]const u8),error{},(function 'read')).readVarInt__anon_7010': /usr/lib/zig/std/io/reader.zig:300: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `fmt.formatInt__anon_7060': /usr/lib/zig/std/fmt.zig:1428: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `mem.Allocator.alignedShrinkWithRetAddr__anon_7071': /usr/lib/zig/std/mem/Allocator.zig:480: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `mem.Allocator.free__anon_7077': /usr/lib/zig/std/mem/Allocator.zig:494: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `hash.wyhash.WyhashStateless.hash': /usr/lib/zig/std/hash/wyhash.zig:120: undefined reference to `__zig_probe_stack' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `mem.zeroes__anon_7210': /usr/lib/zig/std/mem.zig:274: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `array_list.ArrayListAligned(dwarf.FileEntry,null).allocatedSlice': /usr/lib/zig/std/array_list.zig:436: undefined reference to `memcpy' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `mem.Allocator.reallocAdvancedWithRetAddr__anon_7526': /usr/lib/zig/std/mem/Allocator.zig:407: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/mem/Allocator.zig:417: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/mem/Allocator.zig:419: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `hash_map.HashMapUnmanaged(usize,*debug.ModuleDebugInfo__struct_4249,hash_map.AutoContext(usize),80).deinit': /usr/lib/zig/std/hash_map.zig:890: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `hash_map.HashMapUnmanaged(usize,*debug.ModuleDebugInfo__struct_4249,hash_map.AutoContext(usize),80).initMetadatas': /usr/lib/zig/std/hash_map.zig:1444: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `mem.Allocator.reallocAdvancedWithRetAddr__anon_7551': /usr/lib/zig/std/mem/Allocator.zig:407: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/mem/Allocator.zig:417: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/mem/Allocator.zig:419: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `fmt.formatInt__anon_7558': /usr/lib/zig/std/fmt.zig:1428: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `fmt.formatInt__anon_7575': /usr/lib/zig/std/fmt.zig:1428: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `mem.Allocator.reallocAdvancedWithRetAddr__anon_7672': /usr/lib/zig/std/mem/Allocator.zig:407: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/mem/Allocator.zig:417: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/mem/Allocator.zig:419: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `mem.Allocator.reallocAdvancedWithRetAddr__anon_7673': /usr/lib/zig/std/mem/Allocator.zig:407: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/mem/Allocator.zig:417: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/mem/Allocator.zig:419: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `mem.Allocator.reallocAdvancedWithRetAddr__anon_7674': /usr/lib/zig/std/mem/Allocator.zig:407: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/mem/Allocator.zig:417: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/mem/Allocator.zig:419: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `mem.Allocator.free__anon_7676': /usr/lib/zig/std/mem/Allocator.zig:494: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `mem.Allocator.reallocAdvancedWithRetAddr__anon_7687': /usr/lib/zig/std/mem/Allocator.zig:407: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/mem/Allocator.zig:417: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/mem/Allocator.zig:419: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `mem.Allocator.reallocAdvancedWithRetAddr__anon_7688': /usr/lib/zig/std/mem/Allocator.zig:407: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/mem/Allocator.zig:417: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/mem/Allocator.zig:419: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `mem.Allocator.reallocAdvancedWithRetAddr__anon_7710': /usr/lib/zig/std/mem/Allocator.zig:407: undefined reference to `memset' /usr/bin/ld: /usr/lib/zig/std/mem/Allocator.zig:417: undefined reference to `memcpy' /usr/bin/ld: /usr/lib/zig/std/mem/Allocator.zig:419: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `mem.Allocator.free__anon_7712': /usr/lib/zig/std/mem/Allocator.zig:494: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `mem.Allocator.free__anon_7725': /usr/lib/zig/std/mem/Allocator.zig:494: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `mem.Allocator.allocAdvancedWithRetAddr__anon_7754': /usr/lib/zig/std/mem/Allocator.zig:308: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o): in function `mem.Allocator.free__anon_7761': /usr/lib/zig/std/mem/Allocator.zig:494: undefined reference to `memset' /usr/bin/ld: ./libstart.a(/home/aakash/compilers/ziglibc/zig-cache/o/a79729c21a815cb7337aa0e37699b441/libstart.a.o):/usr/lib/zig/std/mem/Allocator.zig:494: more undefined references to `memset' follow /usr/bin/ld: /tmp/main-e17d34.o: in function `main': main.c:(.text+0xe): undefined reference to `printf' clang: error: linker command failed with exit code 1 (use -v to see invocation)

On closer inspection of the linker calls in zig cc I noticed the following:

LLD Link... ld.lld --error-limit=0 -O0 -z stack-size=16777216 --gc-sections --eh-frame-hdr -znow -m elf_x86_64 -static -o a.out -L . -L /usr/local/lib64 -L /usr/local/lib -L /usr/lib/x86_64-linux-gnu -L /lib64 -L /lib -L /usr/lib64 -L /usr/lib -L /lib/x86_64-linux-gnu ./libstart.a ./libcguana.a /home/aakash/.cache/zig/o/4fb5a973d613ccf9f7dc5a047f0f1159/main.o /home/aakash/.cache/zig/o/e4671609f1123341b50f8763536d1e8f/libc.a /home/aakash/.cache/zig/o/b57549dbd24cf4df24f109a7abd88042/libcompiler_rt.a --as-needed

Naturally I assumed the above errors with clang introduced due to not linking with compiler_rt and attempted to compile a simple hello world main.c into main.o and then used a zig compiled libcompiler_rt.o file and it indeed reduced my errors with clang significantly to the following:

clang -nostdlib -I ../../inc/libc -I ../../inc/posix/ -I ../../inc/linux/ -L. -lstart libcguana.a /home/aakash/.cache/zig/o/b57549dbd24cf4df24f109a7abd88042/libcompiler_rt.a main.o -static
/usr/bin/ld: main.o: in function `main':
main.c:(.text+0x13): undefined reference to `puts'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

EDIT: After some experimentation, linking with libcompiler_rt.a using-fuse-ld=lld/-fuse-ld=mold while using the above command fixes the issues but I'm still intrigued as to why that's the case.

Shinyzenith commented 1 year ago

Would it be possible to remove the dependency on compiler_rt?

mgord9518 commented 1 year ago

@Shinyzenith to my knowledge "compiler_rt" is necessary for Zig, executables just happen to automatically build it in while it doesn't when you build a library. You should be able to add '-fcompiler_rt' to zig build in order to resolve those symbols

Shinyzenith commented 1 year ago

Ok, I tried zig build -fcompiler_rt and it seems to not recognize it as a flag. Any suggestions?

Shinyzenith commented 1 year ago

Edited the build.zig to add .bundle_compiler_rt it seems to work fine now but I still receive the same errors when I pass clang as the cc. Atleast the compiler_rt errors are gone for now. I'll send a patch upstream if Jonathan is interested

matu3ba commented 1 year ago

Would it be possible to remove the dependency on compiler_rt?

See src/main.zig, if you prefer clangs or gccs compiler_rt implementation:

    \\  -fcompiler-rt                  Always include compiler-rt symbols in output
    \\  -fno-compiler-rt               Prevent including compiler-rt symbols in output

What is your minimal c program and what is your target system?