Skip to content

Assembly implementation of functions does not work for x32 #499

@hvdijk

Description

@hvdijk

The x86_64-linux-gnux32 target uses 64-bit mode, but 32-bit pointers. In this mode, the same assembly as for 64-bit pointers is used, but it does not work.

harald@debian:~/BLAKE3/c/build$ cmake -G Ninja -DCMAKE_C_COMPILER=x86_64-linux-gnux32-gcc -DCMAKE_CXX_COMPILER=x86_64-linux-gnux32-g++ .. -DBLAKE3_TESTING=ON -DBLAKE3_TESTING_CI=ON
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.10 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
  to tell CMake that the project requires at least <min> but has been updated
  to work with policies introduced by <max> or earlier.


-- The C compiler identification is GNU 14.2.0
-- The CXX compiler identification is GNU 14.2.0
-- The ASM compiler identification is GNU
-- Found assembler: /usr/bin/x86_64-linux-gnux32-gcc
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/x86_64-linux-gnux32-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/x86_64-linux-gnux32-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- BLAKE3 SIMD configuration:
--
 * AMD64 assembly, The library uses hand written amd64 SIMD assembly.

-- Configuring done (0.2s)
-- Generating done (0.0s)
-- Build files have been written to: /home/harald/BLAKE3/c/build
$ ninja
[18/18] Linking C executable /home/harald/BLAKE3/c/blake3
/usr/lib/gcc-cross/x86_64-linux-gnux32/14/../../../../x86_64-linux-gnux32/bin/ld: libblake3-testing.a(blake3.c.o): warning: relocation in read-only section `.text'
/usr/lib/gcc-cross/x86_64-linux-gnux32/14/../../../../x86_64-linux-gnux32/bin/ld: warning: creating DT_TEXTREL in a PIE
$ ../test.py
[...]
Testing 0x00000001
AddressSanitizer:DEADLYSIGNAL
=================================================================
==2960174==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x56677684 bp 0xffc2ff08 sp 0xffc2fd80 T0)
==2960174==The signal is caused by a READ memory access.
==2960174==Hint: this fault was caused by a dereference of a high value address (see register values below).  Disassemble the provided pc to learn which register was used.
    #0 0x56677684  (/home/harald/BLAKE3/c/blake3+0x33684) (BuildId: b29eaa3421c54467f1c5ee0737ed62280558be2c)

==2960174==Register values:
rax = 0x0000000000000001  rbx = 0x00000000ffc30940  rcx = 0x00000000f5e00060  rdx = 0x0000000000000040
rdi = 0x00000000ffc30000  rsi = 0x0000000000000002  rbp = 0x00000000ffc2ff08  rsp = 0x00000000ffc2fd80
 r8 = 0xf4affc00f4aff800   r9 = 0x42704bb100000008  r10 = 0x00000000ffc30940  r11 = 0x0000000000000000
r12 = 0x0000000000000002  r13 = 0x0000000000000000  r14 = 0x0000000000000001  r15 = 0x0000000000000400
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/home/harald/BLAKE3/c/blake3+0x33684) (BuildId: b29eaa3421c54467f1c5ee0737ed62280558be2c)
==2960174==ABORTING
Traceback (most recent call last):
  File "/home/harald/BLAKE3/c/build/../test.py", line 97, in <module>
    main()
    ~~~~^^
  File "/home/harald/BLAKE3/c/build/../test.py", line 48, in main
    test_hash = run_blake3([], input)
  File "/home/harald/BLAKE3/c/build/../test.py", line 14, in run_blake3
    output = subprocess.run([path.join(HERE, "blake3")] + args,
                            input=input,
                            stdout=subprocess.PIPE,
                            check=True)
  File "/usr/lib/python3.13/subprocess.py", line 577, in run
    raise CalledProcessError(retcode, process.args,
                             output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['/home/harald/BLAKE3/c/build/../blake3']' returned non-zero exit status 1.

I will submit a PR fixing this shortly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions