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

            Bug ID: 93190
           Summary: Failure to link with .note.GNU-stack in inline
                    assembly
           Product: gcc
           Version: 9.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: inline-asm
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ian.s.mcinerney at ieee dot org
  Target Milestone: ---

Created attachment 47601
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47601&action=edit
Example program

When compiling inline assembly that contains the line ".section
.note.GNU-stack,"",%progbits", sometimes the linker fails with the error:
"`.note.GNU-stack' referenced in section `.text' of /tmp/ccKoiXRb.o: defined in
discarded section `.note.GNU-stack' of /tmp/ccKoiXRb.o"

I have narrowed this down to the example in the attached main.cpp. When the
iostream header is included the linking fails, but when it is commented out the
linking works.

It appears that there are some cases when the .note.GNU-stack section is being
referenced inside the .text section of the created object file (taken from the
compiled main.o of the failed linking) even though it is a discarded section in
the linker:

Relocation section '.rela.text' at offset 0x470 contains 9 entries:
  Offset          Info           Type           Sym. Value    Sym. Name +
Addend
000000000036  000e00000004 R_X86_64_PLT32    0000000000000000 Add2 - 4
000000000043  00080000000a R_X86_64_32       0000000000000000 .note.GNU-stack +
0
00000000004d  001000000004 R_X86_64_PLT32    0000000000000000 printf - 4
000000000076  00040000000a R_X86_64_32       0000000000000000 .bss + 0
00000000007b  001100000004 R_X86_64_PLT32    0000000000000000
_ZNSt8ios_base4InitC1E - 4
000000000080  00120000000a R_X86_64_32       0000000000000000 __dso_handle + 0
000000000085  00040000000a R_X86_64_32       0000000000000000 .bss + 0
00000000008a  00130000000a R_X86_64_32       0000000000000000
_ZNSt8ios_base4InitD1E + 0
00000000008f  001400000004 R_X86_64_PLT32    0000000000000000 __cxa_atexit - 4



The successful compilation produces a .text section that doesn't reference it:

Relocation section '.rela.text' at offset 0x250 contains 3 entries:
  Offset          Info           Type           Sym. Value    Sym. Name +
Addend
000000000036  000900000004 R_X86_64_PLT32    0000000000000000 Add2 - 4
000000000043  00060000000a R_X86_64_32       0000000000000000 .rodata + 0
00000000004d  000b00000004 R_X86_64_PLT32    0000000000000000 printf - 4



This inconsistent behavior is very problematic. Ideally it should always
compile/link fine with this included in the inline assembly.

I have tested this using 9.2.1 from Fedora 31, and also 7.4.0 from Ubuntu 18.04
and it is present in both versions.

Reply via email to