abseil/abseil-cpp

[Bug]: absl::StrFormat doesn't produce correct output under mipsel platform

Closed this issue · 8 comments

Describe the issue

I am replacing chromium's StringPrintf with absl::StrFormat but it doesn't produce correct output under mipsel platform (glibc).

Steps to reproduce the problem

Use latest clang and target it at mipsel (glibc).
Use code

    std::string http_response_hdr2 = absl::StrFormat(
      "HTTP/1.1 200 OK\r\n"
      "Server: asio/1.0.0\r\n"
      "Content-Type: application/octet-stream\r\n"
      "Content-Length: %llu\r\n"
      "Connection: close\r\n\r\n", static_cast<unsigned long long>(g_send_buffer.length()));

where g_send_buffer.length() is 1048576. It outputs 104576

HTTP/1.1 200 OK
Server: asio/1.0.0
Content-Type: application/octet-stream
Content-Length: 104576
Connection: close

What version of Abseil are you using?

Tried both of 20230802.rc2 and b841db22f8d1d9cdbaacecf2e7c87ce270f8d96f (shipped with chromium 120)

What operating system and version are you using?

Linux (Gentoo and Ubuntu 20.04)

What compiler and version are you using?

clang version 18.0.0 (https://chromium.googlesource.com/a/external/github.com/llvm/llvm-project 10664813fca8d5ccbfd90bae9e791b7062dabd7c)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/hky/yass/./third_party/llvm-build/Release+Asserts/bin
Selected GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/13
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

What build system are you using?

cmake version 3.27.7

CMake suite maintained and supported by Kitware (kitware.com/cmake).

Additional context

See more at Chilledheart/yass#454.

Additional context

I am using qemu user emulation under x86_64 to run and verify the code.

export SDK_ROOT=$PWD/debian_sid_mipsel-sysroot
qemu-mipsel-static -L $SDK_ROOT $PWD/build-linux-mipsel/yass_test --no_exec_proc_tests

Compiler is download from https://commondatastorage.googleapis.com/chromium-browser-clang/Linux_x64/clang-llvmorg-18-init-9505-g10664813-1.tar.xz

I did not try this, but I think this is unlikely to be a bug in Abseil. There is a previous StrFormat bug report that turned out to be a glibc issue: #1369

The mipsel linux sysroot I used is coming from some snapshot on stable branch of debian (not that recent version of glibc, unlike gentoo or fedora). It is late night here and I will post the details of sysroot once I come to the office tomorrow.

It is 2.31

debian_sid_mipsel-sysroot/lib/mipsel-linux-gnu/libc-2.31.so: ELF 32-bit LSB shared object, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, BuildID[sha1]=71d1472a54cd9638567e4ecc79b29c3fdf72b1c0, for GNU/Linux 3.2.0, stripped

I tried another sysroot from chromium v119.0.6045.66 buildbed (debian bullseye) and still failed with libc-2.31.so.

https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/1b857baabd7999ff0d6949a8973f896836ac45ac/debian_bullseye_mipsel_sysroot.tar.xz

I also tried with different versions of clang compiler (namely 16.0.6 and 17.0.5). 16.0.6 didn't work but 17.0.5 works.

It seems to be a bug with compiler implementation. I don't have a chance to run gcc because the cross-compiling setting up.

The compiler below works.

/home/hky/clang+llvm-17.0.5-x86_64-linux-gnu-ubuntu-22.04/bin/clang: /lib64/libtinfo.so.6: no version information available (required by /home/hky/clang+llvm-17.0.5-x86_64-linux-gnu-ubuntu-22.04/bin/clang)
clang version 17.0.5 (https://github.com/llvm/llvm-project 98bfdac5ce82d1679f8af9a57501471812ab68d7)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/hky/clang+llvm-17.0.5-x86_64-linux-gnu-ubuntu-22.04/bin
Selected GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/13
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

The compiler doesn't work

clang version 16.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm/16/bin
Configuration file: /etc/clang/clang.cfg
System configuration file directory: /etc/clang
Selected GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/13
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

The compiler doesn't work as well:

clang version 18.0.0 (https://chromium.googlesource.com/a/external/github.com/llvm/llvm-project 10664813fca8d5ccbfd90bae9e791b7062dabd7c)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/hky/yass/./third_party/llvm-build/Release+Asserts/bin
Selected GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/13
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

Tried with newer compiler with chromium 120, the bug went out.

clang version 18.0.0 (https://chromium.googlesource.com/a/external/github.com/llvm/llvm-project 74cdb8e6f8c88b97204f540601a553b412d1cd56)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/hky/yass/./third_party/llvm-build/Release+Asserts/bin
Selected GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/13
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64