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

            Bug ID: 122538
           Summary: [SPARC64] GCC uses the wrong source registers for
                    R_SPARC_GOTDATA_OP relocations
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: koachan+gccbugs at protonmail dot com
  Target Milestone: ---

Created attachment 62696
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62696&action=edit
Preprocessed source file (compressed; the original is over the upload size
limit)

In the reproducer file, after compiling, the R_SPARC_GOTDATA_OP for
_ZTHN4llvm8parallel11threadIndexE in the
_ZZN12_GLOBAL__N_154ConcurrentHashTableTest_AddStringMultiplueEntries_Test8TestBodyEvENKUlvE_clEv
function is lowered to something like:

   8:   05 00 00 00     sethi  %hi(0), %g2
                        8: R_SPARC_GOTDATA_OP_HIX22    
_ZTHN4llvm8parallel11threadIndexE
   c:   84 18 a0 00     xor  %g2, 0, %g2
                        c: R_SPARC_GOTDATA_OP_LOX10    
_ZTHN4llvm8parallel11threadIndexE
  74:   fa 5d c0 01     ldx  [ %l7 + %g1 ], %i5
                        74: R_SPARC_GOTDATA_OP 
_ZTHN4llvm8parallel11threadIndexE

In the ldx instruction, %l7 is the address of the GOT, but it uses the wrong
register (%g1 instead of %g2) for the index part. This causes the wrong data to
be loaded to %i5, which later on will cause crashes during runtime.

GCC command used to compile the file is:
/usr/bin/c++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS
-D_GLIBCXX_USE_CXX11_ABI=1 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-I/home/k/llvm-debug/src/llvm-project/out-mold/unittests/ADT
-I/home/k/llvm-debug/src/llvm-project/llvm/unittests/ADT
-I/home/k/llvm-debug/src/llvm-project/out-mold/include
-I/home/k/llvm-debug/src/llvm-project/llvm/include
-I/home/k/llvm-debug/src/llvm-project/third-party/unittest/googletest/include
-I/home/k/llvm-debug/src/llvm-project/third-party/unittest/googlemock/include
-fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time
-Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual
-Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough
-Wno-maybe-uninitialized -Wno-nonnull -Wno-class-memaccess
-Wno-dangling-reference -Wno-redundant-move -Wno-pessimizing-move
-Wno-array-bounds -Wno-stringop-overread -Wno-noexcept-type
-Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment
-Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color
-ffunction-sections -fdata-sections -O3 -DNDEBUG -std=c++17  -Wno-dangling-else
-Wno-variadic-macros -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG
-Wno-suggest-override -MD -MT
unittests/ADT/CMakeFiles/ADTTests.dir/ConcurrentHashtableTest.cpp.o -MF
unittests/ADT/CMakeFiles/ADTTests.dir/ConcurrentHashtableTest.cpp.o.d -o
unittests/ADT/CMakeFiles/ADTTests.dir/ConcurrentHashtableTest.cpp.o -c
/home/k/llvm-debug/src/llvm-project/llvm/unittests/ADT/ConcurrentHashtableTest.cpp

This is a case I found when building LLVM with GCC and linking it with mold.
The comment in the mold issue report where we found this issue is at
https://github.com/rui314/mold/issues/1529#issuecomment-3478989452, for further
reference.
  • [Bug target/122538] New... koachan+gccbugs at protonmail dot com via Gcc-bugs

Reply via email to