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

Martin Papik <mp8191mp at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mp8191mp at gmail dot com

--- Comment #17 from Martin Papik <mp8191mp at gmail dot com> ---

Hello, I found a bug, which I think is a duplicate of this one, but am not 100%
sure.

Below is a minimal piece of code which triggers the bug. All versions of gcc
seem to be affected, as seen on compiler explorer,
https://godbolt.org/z/jFMj8b, which also shows a difference in gimple, the
templated version is missing the explicit naming attributes.

Is this the same bug? If so, is there some technical reason why a clear
miscompilation persists for as long as it seems to? What I mean is this, if a
bug like this persists for this long, it could be taken to mean that the bug is
too big for a casual volunteer. Would that be the case? Can someone familiar
with the code base tell me what I'd need to know to fix this, e.g. what's wrong
with the patch, is it better to fix the patch or start from scratch.


$ cat bug.cpp
#define DEMONSTRABLY_IDENTICAL                                  \
        long ret;                                               \
        register long r10 __asm__("r10") = (long)a4;            \
        __asm__ __volatile__ ("syscall"                         \
                : "=a"(ret)                                     \
                : "a"(n), "D"(a1), "S"(a2), "d"(a3), "r"(r10)   \
                : "rcx", "r11", "memory"                        \
                );
enum class sysnr : long {
        // accept4 has enough parameters to require extra registers and trigger
the bug
        accept4 = 0x120
};
static __inline long sys_01(long n, long a1, long a2, long a3, long a4)
{
        DEMONSTRABLY_IDENTICAL
        return ret;
}
template <sysnr SYS_NR, typename RET, typename T1, typename T2, typename T3,
typename T4>
RET sys_02(T1 a1, T2 a2, T3 a3, T4 a4) {
        constexpr long n = (long) SYS_NR;
        DEMONSTRABLY_IDENTICAL
        return (RET)ret;
}
void test_01 () {
        sys_01( (long)sysnr::accept4, 0xfeed01, 0xfeed02, 0xfeed03, 0xfeed04 );
}
void test_02() {
        sys_02<sysnr::accept4, long>( 0xfeed01, 0xfeed02, 0xfeed03, 0xfeed04 );
}
void test_03() {
        sys_02<sysnr::accept4, long, long, long, long, long>( 0xfeed01,
0xfeed02, 0xfeed03, 0xfeed04 );
}

$ g++ -std=c++11 -O1 bug.cpp -c -o bug.c
$ objdump -Cd bug.o 

bug.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <test_01()>:
   0:   41 ba 04 ed fe 00       mov    $0xfeed04,%r10d
   6:   b8 20 01 00 00          mov    $0x120,%eax
   b:   bf 01 ed fe 00          mov    $0xfeed01,%edi
  10:   be 02 ed fe 00          mov    $0xfeed02,%esi
  15:   ba 03 ed fe 00          mov    $0xfeed03,%edx
  1a:   0f 05                   syscall 
  1c:   c3                      retq   

000000000000001d <test_02()>:
  1d:   b8 20 01 00 00          mov    $0x120,%eax
  22:   bf 01 ed fe 00          mov    $0xfeed01,%edi
  27:   be 02 ed fe 00          mov    $0xfeed02,%esi
  2c:   ba 03 ed fe 00          mov    $0xfeed03,%edx
  31:   41 b8 04 ed fe 00       mov    $0xfeed04,%r8d
  37:   0f 05                   syscall 
  39:   c3                      retq   

000000000000003a <test_03()>:
  3a:   b8 20 01 00 00          mov    $0x120,%eax
  3f:   bf 01 ed fe 00          mov    $0xfeed01,%edi
  44:   be 02 ed fe 00          mov    $0xfeed02,%esi
  49:   ba 03 ed fe 00          mov    $0xfeed03,%edx
  4e:   41 b8 04 ed fe 00       mov    $0xfeed04,%r8d
  54:   0f 05                   syscall 
  56:   c3                      retq

Reply via email to