https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122507

            Bug ID: 122507
           Summary: undefined reference using inline assembly with LTO
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: lto
          Assignee: unassigned at gcc dot gnu.org
          Reporter: peter0x44 at disroot dot org
  Target Milestone: ---

For the following code:

#include <stdio.h>

extern int my_add(int x, int y);

__asm__(
".text  \n"
".def my_add; .scl 3; .type 32; .endef  \n"
//".globl my_add  \n" ////////////////////////
"my_add:  \n"
"  lea eax, [rcx + rdx]  \n"
"  ret  \n"
);

int
main(void)
  {
    printf("my_add(42, 1) = %d\n", my_add(42, 1));
  }

compiled with:

x86_64-w64-mingw32-gcc test.c -flto -O2 -masm=intel

gives this undefined reference:
/home/peter/wintoolchain/lib/gcc/x86_64-w64-mingw32/16.0.0/../../../../x86_64-w64-mingw32/bin/ld:
/tmp/cc3Ozpev.ltrans0.ltrans.o:<artificial>:(.text.startup+0x14): undefined
reference to `my_add'
collect2: error: ld returned 1 exit status

reverting e7e91a83b85e1189e513ad14edb5e69d5bd25871 fixes it.

as does uncommenting:
//".globl my_add  \n" ////////////////////////

or removing LTO.

Reply via email to