https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84861
Bug ID: 84861 Summary: -flto with asm() optimizes too much Product: gcc Version: lto Status: UNCONFIRMED Severity: normal Priority: P3 Component: inline-asm Assignee: unassigned at gcc dot gnu.org Reporter: dilyan.palauzov at aegee dot org Target Milestone: --- When compiling valgrind's coregrind/m_libcsetjmp.c (https://sourceware.org/git/?p=valgrind.git;a=blob;f=coregrind/m_libcsetjmp.c) with -lto the functions VG_MINIMAL_LONGJMP and VG_MINIMAL_SETJMP disappear on amd64 from the coregrind/libcoregrind_amd64_linux_a-m_libcsetjmp.o file: cd coregrind WITH LTO: $ make V=1 libcoregrind_amd64_linux_a-m_libcsetjmp.o gcc -DHAVE_CONFIG_H -I. -I.. -I.. -I../include -I../include -I../VEX/pub -I../VEX/pub -DVGA_amd64=1 -DVGO_linux=1 -DVGP_amd64_linux=1 -DVGPV_amd64_linux_vanilla=1 -I../coregrind -DVG_LIBDIR="\"/usr/local/lib/valgrind"\" -DVG_PLATFORM="\"amd64-linux\"" -m64 -O2 -finline-functions -g -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-declarations -Wcast-align -Wcast-qual -Wwrite-strings -Wempty-body -Wformat -Wformat-security -Wignored-qualifiers -Wmissing-parameter-type -Wlogical-op -Wold-style-declaration -fno-stack-protector -fno-strict-aliasing -fno-builtin -fomit-frame-pointer -DENABLE_LINUX_TICKET_LOCK -flto -MT libcoregrind_amd64_linux_a-m_libcsetjmp.o -MD -MP -MF .deps/libcoregrind_amd64_linux_a-m_libcsetjmp.Tpo -c -o libcoregrind_amd64_linux_a-m_libcsetjmp.o `test -f 'm_libcsetjmp.c' || echo './'`m_libcsetjmp.c mv -f .deps/libcoregrind_amd64_linux_a-m_libcsetjmp.Tpo .deps/libcoregrind_amd64_linux_a-m_libcsetjmp.Po $ nm libcoregrind_amd64_linux_a-m_libcsetjmp.o nm: libcoregrind_amd64_linux_a-m_libcsetjmp.o: no symbols (for the other coregrind/libcoregrind_amd64_linux_a-*.o files `nm` shows exported symbols). WITHOUT LTO: $ make V=1 libcoregrind_amd64_linux_a-m_libcsetjmp.o gcc -DHAVE_CONFIG_H -I. -I.. -I.. -I../include -I../include -I../VEX/pub -I../VEX/pub -DVGA_amd64=1 -DVGO_linux=1 -DVGP_amd64_linux=1 -DVGPV_amd64_linux_vanilla=1 -I../coregrind -DVG_LIBDIR="\"/usr/local/lib/valgrind"\" -DVG_PLATFORM="\"amd64-linux\"" -m64 -O2 -finline-functions -g -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-declarations -Wcast-align -Wcast-qual -Wwrite-strings -Wempty-body -Wformat -Wformat-security -Wignored-qualifiers -Wmissing-parameter-type -Wlogical-op -Wold-style-declaration -fno-stack-protector -fno-strict-aliasing -fno-builtin -fomit-frame-pointer -DENABLE_LINUX_TICKET_LOCK -MT libcoregrind_amd64_linux_a-m_libcsetjmp.o -MD -MP -MF .deps/libcoregrind_amd64_linux_a-m_libcsetjmp.Tpo -c -o libcoregrind_amd64_linux_a-m_libcsetjmp.o `test -f 'm_libcsetjmp.c' || echo './'`m_libcsetjmp.c mv -f .deps/libcoregrind_amd64_linux_a-m_libcsetjmp.Tpo .deps/libcoregrind_amd64_linux_a-m_libcsetjmp.Po $ nm libcoregrind_amd64_linux_a-m_libcsetjmp.o 0000000000000052 T VG_MINIMAL_LONGJMP 0000000000000000 T VG_MINIMAL_SETJMP The only difference is "-flto". It this a problem of LTO, or is the assembler supposed to be tweaked (how?) so that the symbols get exported? Having a file containing asm (""); does compile, but a file containing only: asm volatile (""); fails with "error: expected ‘(’ before ‘volatile’". Happens with gcc 8.0.1 20180306 (experimental).