Engine fails to build on WSL2
Closed this issue · 6 comments
When attempting to make
engine under WSL2 (Ubuntu), the compiler throws an error.
/usr/bin/ld: main.o: in function `ace_main':
main.c:(.text.ace_main+0x32e): undefined reference to `__stack_chk_fail'
/usr/bin/ld: wadfile.o: in function `wad_init':
wadfile.c:(.text.wad_init+0x3f7): undefined reference to `__stack_chk_fail'
/usr/bin/ld: wadfile.o: in function `wad_name64':
wadfile.c:(.text.wad_name64+0x5f): undefined reference to `__stack_chk_fail'
/usr/bin/ld: wadfile.o: in function `wad_check_lump':
wadfile.c:(.text.wad_check_lump+0x9c): undefined reference to `__stack_chk_fail'
/usr/bin/ld: wadfile.o: in function `wad_handle_lump':
wadfile.c:(.text.wad_handle_lump+0xa8): undefined reference to `__stack_chk_fail'
/usr/bin/ld: ldr_texture.o:ldr_texture.c:(.text.cb_tx_count+0xab): more undefined references to `__stack_chk_fail' follow
/usr/bin/ld: saveload.o: in function `setup_save_slots':
saveload.c:(.text.setup_save_slots+0x148): undefined reference to `__strcpy_chk'
/usr/bin/ld: saveload.c:(.text.setup_save_slots+0x1fd): undefined reference to `__stack_chk_fail'
/usr/bin/ld: saveload.o: in function `svcb_thing':
saveload.c:(.text.svcb_thing+0x2b3): undefined reference to `__stack_chk_fail'
/usr/bin/ld: saveload.o: in function `do_save':
saveload.c:(.text.do_save+0x154): undefined reference to `__strcpy_chk'
/usr/bin/ld: saveload.c:(.text.do_save+0x170): undefined reference to `__strcpy_chk'
/usr/bin/ld: saveload.c:(.text.do_save+0xb02): undefined reference to `__stack_chk_fail'
/usr/bin/ld: saveload.o: in function `do_load':
saveload.c:(.text.do_load+0xd36): undefined reference to `__stack_chk_fail'
collect2: error: ld returned 1 exit status
make: *** [makefile:14: code] Error 1```
It's a weird stuff with GCC versions. Stack protector has to be off (-fno-stack-protector). Somehow it is off in my case without using this option. I will add this to makefile.
I use "gcc version 10.2.1 20210110". I would like to make this compilable on any version though.
As for issue with 'invalid opcode', i would need to see your output. Code and WAD.
There is not yet a decent documentation, so maybe it's just some misunderstanding.
Can you send me your generated WAD file ... somehow?
I'm apparently on 9.4.0
After updating to the newer commits and now it only errors on __strcpy_chk
I've also manually added -Wl,-fno-stack-protector -Wl,-shared
so that it gets added to the linker's arguments (-shared is there as ld says -f cannot be used
I've attached the .wad i've created using SLADE (replaced ACE_CODE with code.bin, original .wad worked prior to doing so)
It seems SLADE also changes the entry to some type named "Pod Archive".
Here is the .wad i've created
l2k6ace.zip
Your method for WAD assembly is correct. However your binary is broken. You can't use -shared
as that totally breaks relocations. Also, is -fno-stack-protector
a linker parameter?
As for __strcpy_chk
- try to use one of FORTIFY_SOURCE
methods mentioned here:
https://stackoverflow.com/questions/12201625/disable-using-sprintf-chk
You basically have to disable any extra protection that GCC tries to use.
I do not understand how is it so different between versions of GCC.
I've added -U_FORTIFY_SOURCE to CFLAGS and it seems to compile fine now, though it still crashes when trying to execute it with the same "invalid opcode" error, from a quick glances it seems EBX,EDX gets set and the exception occurs slightly later.
I've updated gcc to 10.3 and it still has the same issues, though the file size seems to increase (?)
the no-stack-protector was also a linker parameter but i've removed it due to it requiring -shared.
EDIT: Here's the screenshot with the updated .wad
l2k6ace.zip
Yeah. That's better. Your code is almost OK. Just for some reason compiler used endbr32 instruction, which is not supposed to be used in i486 and it does not work on real hardware. Replacing this with NOPs makes your code work.
It is yet another protection feature. I have already pushed new makefile, try if that fixes this for you.
It works now! Thanks you for your time.
Tested working with GCC 9.4 and 10.3, seems that SLADE has issue with importing over entries since it wouldn't work until i deleted and re-added the entry instead.