Created attachment 596184 [details, diff] fix compilation with -flto flag Due to name mangling, gcc seems to have issues with referencing static functions in inline assembly sections when compiling with -flto. The included patch disables LTO when compiling the dosemu source file cpatch.c. This allows dosemu to be compiled when the -flto flag is included in CFLAGS.
-fno-lto is an unportable workaround. I would prefer making the symbol directly usable for assembly. There should be a few ways to do it. With CFLAGS='-flto -O2' CXXFLAGS='-flto -O2' the build failure looks like that: x86_64-pc-linux-gnu-gcc -Wl,-warn-common -Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu -rdynamic -o ../1.4.0.8/bin/dosemu.bin emu.o \ -Wl,--whole-archive lib/libenv_video.a lib/libbase.a lib/libbase_async.a lib/libarch_linux_async.a lib/libarch_linux_mapping.a lib/libbase_misc.a lib/libbase_misc_libpcl.a lib/libbase_dev_misc.a lib/libemu-i386.a lib/libemu-i386_simx86.a lib/libenv.a lib/libbase_speaker.a lib/libbase_dev_pic.a lib/libdosext_dpmi.a lib/libdosext_mfs.a lib/libdosext_misc.a lib/libbase_init.a lib/libbase_serial.a lib/libbase_mouse.a lib/libbase_dev_dma.a lib/libarch_linux_debugger.a lib/libdosext_net_net.a lib/libdosext_sound.a lib/libarch_linux_dosext_sound.a lib/libbase_dev_sb16.a lib/libbase_sound.a lib/libdosext_drivers.a lib/libbase_bios.a lib/libplugin_translate.a lib/libplugin_translate_charsets.a lib/libplugin_term.a lib/libplugin_sdl.a lib/libplugin_midimisc.a lib/libplugin_kbd_unicode.a lib/libplugin_gpm.a lib/libplugin_fluidsynth.a lib/libplugin_extra_charsets.a lib/libplugin_commands.a lib/libplugin_alsa.a lib/libplugin_X.a -Wl,--no-whole-archive -lrt -ldl -lm /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/dosemu.bin.h8Y59G.ltrans0.ltrans.o: in function `stub_rep__': <artificial>:(.text+0xe): undefined reference to `rep_movs_stos' /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/dosemu.bin.h8Y59G.ltrans0.ltrans.o: in function `stub_stk_16__': <artificial>:(.text+0x25): undefined reference to `stk_16' /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/dosemu.bin.h8Y59G.ltrans0.ltrans.o: in function `stub_stk_32__': <artificial>:(.text+0x3a): undefined reference to `stk_32' /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/dosemu.bin.h8Y59G.ltrans0.ltrans.o: in function `stub_wri_8__': <artificial>:(.text+0x4c): undefined reference to `wri_8' /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/dosemu.bin.h8Y59G.ltrans0.ltrans.o: in function `stub_wri_16__': <artificial>:(.text+0x5a): undefined reference to `wri_16' /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/dosemu.bin.h8Y59G.ltrans0.ltrans.o: in function `stub_wri_32__': <artificial>:(.text+0x68): undefined reference to `wri_32' /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/dosemu.bin.h8Y59G.ltrans0.ltrans.o: in function `stub_movsb__': <artificial>:(.text+0x7f): undefined reference to `wri_8' /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/dosemu.bin.h8Y59G.ltrans0.ltrans.o: in function `stub_movsw__': <artificial>:(.text+0x9a): undefined reference to `wri_16' /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/dosemu.bin.h8Y59G.ltrans0.ltrans.o: in function `stub_movsl__': <artificial>:(.text+0xb3): undefined reference to `wri_32' /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/dosemu.bin.h8Y59G.ltrans0.ltrans.o: in function `stub_stosb__': <artificial>:(.text+0xcb): undefined reference to `wri_8' /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/dosemu.bin.h8Y59G.ltrans0.ltrans.o: in function `stub_stosw__': <artificial>:(.text+0xe4): undefined reference to `wri_16' /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/dosemu.bin.h8Y59G.ltrans0.ltrans.o: in function `stub_stosl__': <artificial>:(.text+0xfc): undefined reference to `wri_32' collect2: error: ld returned 1 exit status
The bug has been closed via the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=328509762ae5fa834d72e58858252200ed52f6a8 commit 328509762ae5fa834d72e58858252200ed52f6a8 Author: Sergei Trofimovich <slyfox@gentoo.org> AuthorDate: 2019-11-15 12:30:08 +0000 Commit: Sergei Trofimovich <slyfox@gentoo.org> CommitDate: 2019-11-15 12:31:00 +0000 app-emulation/dosemu: fix LTO build, bug #700126 Reported-by: Robert Gill Closes: https://bugs.gentoo.org/700126 Package-Manager: Portage-2.3.79, Repoman-2.3.18 Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org> .../dosemu/dosemu-1.4.1_pre20130107-r5.ebuild | 1 + .../files/dosemu-1.4.1_pre20130107-lto.patch | 27 ++++++++++++++++++++++ 2 files changed, 28 insertions(+)
(In reply to Sergei Trofimovich from comment #1) > -fno-lto is an unportable workaround. I would prefer making the symbol > directly usable for assembly. There should be a few ways to do it. I'm attaching another patch that's pretty hacky and I'm not at all sure if it's any more portable, but it allows the concerned functions to be included in LTO. -fno-lto is unnecessary. You may use it as an alternative to the previous patch.
Created attachment 596302 [details, diff] fix compilation with -flto flag (alternative)
Whoops, didn't bother looking at the commit. I guess exporting the symbols is the cleanest way to go.