When updating faerie I get a linker error on linux
bjorn3 opened this issue · 10 comments
error: linking with `cc` failed: exit code: 1
|
= note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/bjorn/Documenten/rustc_codegen_cranelift/build_sysroot/target/x86_64-unknown-linux-gnu/debug/deps/std.dummy_name.rcgu.o" "-o" "/home/bjorn/Documenten/rustc_codegen_cranelift/build_sysroot/target/x86_64-unknown-linux-gnu/debug/deps/libstd.so" "/home/bjorn/Documenten/rustc_codegen_cranelift/build_sysroot/target/x86_64-unknown-linux-gnu/debug/deps/std.allocator_shim.rcgu.o" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/home/bjorn/Documenten/rustc_codegen_cranelift/build_sysroot/target/x86_64-unknown-linux-gnu/debug/deps" "-L" "/home/bjorn/Documenten/rustc_codegen_cranelift/build_sysroot/target/debug/deps" "-L" "sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-ldl" "-lrt" "-lpthread" "-Wl,-Bstatic" "-Wl,--whole-archive" "/tmp/rustc5pSiro/libpanic_abort-ebe895f026b5ad95.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc5pSiro/libunwind-9bf4ad135fcef4eb.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc5pSiro/librustc_demangle-47343bf5c05ad1ab.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc5pSiro/liblibc-46063ca8474f398d.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc5pSiro/librustc_std_workspace_core-96d00f6d22747389.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc5pSiro/liballoc-8684167332e0bd28.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc5pSiro/libcore-1958aff3d7d300b8.rlib" "-Wl,--no-whole-archive" "/tmp/rustc5pSiro/libcompiler_builtins-2fce88ecd3031979.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-lutil" "-shared"
= note: /tmp/rustc5pSiro/libpanic_abort-ebe895f026b5ad95.rlib: member /tmp/rustc5pSiro/libpanic_abort-ebe895f026b5ad95.rlib(dummy_namercgu) in archive is not an object
collect2: error: ld returned 1 exit status
Repro at https://github.com/bjorn3/rustc_codegen_cranelift/tree/link_error
Got another error:
error: linking with `cc` failed: exit code: 1
|
= note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/bjorn/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "target/out/arbitrary_self_types_pointers_and_wrappers.dummy_name.rcgu.o" "-o" "target/out/arbitrary_self_types_pointers_and_wrappers" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "target/out" "-L" "/home/bjorn/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/bjorn/Documenten/rustc_codegen_cranelift/target/out/libmini_core.rlib" "-Wl,-Bdynamic" "-lc"
= note: /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
According to readelf
main
does exist.
I wish github had better support for attaching binary files. It’s easier to just look at the files in the link line manually and try to reconstruct why the linker doesn’t like it
Simplified command (removed unused -L
flags and adapted to expect every file in current dir):
"cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "arbitrary_self_types_pointers_and_wrappers.dummy_name.rcgu.o" "-o" "arbitrary_self_types_pointers_and_wrappers" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "target/out" "-Wl,-Bstatic" "libmini_core.rlib" "-Wl,-Bdynamic" "-lc"
Should have included it immediately.
@pchickey ^^^
that commit looks ok? but i haven't fully deep dived into it though :/ we should definitely add more regression tests, these kind of bugs are very annoying to fix/track down after the fact
weird gdb is ok with it, so is file, bingrep, objdump, nm
(gdb) disass /r main
Dump of assembler code for function main:
0x0000000000000df0 <+0>: 40 55 rex push %rbp
0x0000000000000df2 <+2>: 48 89 e5 mov %rsp,%rbp
0x0000000000000df5 <+5>: e8 00 00 00 00 callq 0xdfa <main+10>
0x0000000000000dfa <+10>: 40 5d rex pop %rbp
0x0000000000000dfc <+12>: c3 retq
End of assembler dump.
just linking it works for 2/3 of my linkers; i think lld might give a clue as to whats wrong here?
m4b@efrit :: [ ~/Downloads/target/out ] ld arbitrary_self_types_pointers_and_wrappers.dummy_name.rcgu.o -o arbitrary_self_types_pointers_and_wrappers -fPIC -zrelro -Bstatic libmini_core.rlib -Bdynamic -shared -lc
m4b@efrit :: [ ~/Downloads/target/out ] ./arbitrary_self_types_pointers_and_wrappers
Segmentation fault (core dumped)
m4b@efrit :: [ ~/Downloads/target/out ] ld.gold arbitrary_self_types_pointers_and_wrappers.dummy_name.rcgu.o -o arbitrary_self_types_pointers_and_wrappers -fPIC -zrelro -Bstatic libmini_core.rlib -Bdynamic -shared -lc
m4b@efrit :: [ ~/Downloads/target/out ] ./arbitrary_self_types_pointers_and_wrappers
Segmentation fault (core dumped)
m4b@efrit :: [ ~/Downloads/target/out ] ld.lld arbitrary_self_types_pointers_and_wrappers.dummy_name.rcgu.o -o arbitrary_self_types_pointers_and_wrappers -zrelro -Bstatic libmini_core.rlib -Bdynamic -shared
ld.lld: error: arbitrary_self_types_pointers_and_wrappers.dummy_name.rcgu.o: broken object: getLocalSymbols returns a non-local symbol
if we trust @philipc 's bisect, i wonder if this is sh_info local delimiter issue again?
I think this might be it:
sh_name: 9 sh_type SHT_SYMTAB sh_flags: 0x0 sh_addr: 0x0 sh_offset: 0x30de sh_size: 0x720 sh_link: 0x1 sh_info: 0x49 sh_addralign 0x8 sh_entsize 0x18,
2 .symt… SHT_SYMTAB 0x30de 0x0 0x720 .strt…(1) 0x18 0x8
Syms(76):
Addr Bind Type Symbol Size Section Other
which means sh_info = 0x49 = 73 which places global symbols just past main.
EDIT had = 76 before, past the symbol table size, which was wrong, and explains below
Continuing along with my stream of consciousness debugging, the correct sh_info value is suspiciously close to current sh_info value 73 - ndebug sections = 5
:
0 LOCAL SECTION 0x0 .debu…(31) 0x0
0 LOCAL SECTION 0x0 .debu…(32) 0x0
0 LOCAL SECTION 0x0 .debu…(33) 0x0
0 LOCAL SECTION 0x0 .debu…(34) 0x0
0 LOCAL SECTION 0x0 .debu…(35) 0x0
are the debug sections being counted twice somehow?
aha! just saw this. you already solved it. yes, debug sections are being counted towards locals now, even though they do not define a symbol. I was able to remove the special case code for debug sections in this refactor but I didn't put the right predicate on the self.nlocals += 1