Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UBSan complains on aarch32 #1103

Open
ettom opened this issue Dec 12, 2024 · 1 comment
Open

UBSan complains on aarch32 #1103

ettom opened this issue Dec 12, 2024 · 1 comment

Comments

@ettom
Copy link

ettom commented Dec 12, 2024

This might be a compiler bug/sanitizer false positive, but I get the following UBSan error on a simple test program for v2.4.2 and seemingly everything down to v1.6.0. Compilation failed for older versions, so I'm not sure about those.

CLI11.hpp:5465:94: runtime error: reference binding to misaligned address 0x0007d571 for type '<unknown>', which requires 2 byte alignment
0x0007d571: note: pointer points here
 0f 7b 6a  2d e9 f0 4f ad f5 01 7d  00 af c7 f8 34 01 c7 f8  30 11 c7 f8 2c 21 d7 f8  2c 21 d7 f8 2c
              ^ 
/opt/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/include/c++/13.3.1/bits/std_function.h:449:36: runtime error: reference binding to misaligned address 0x0007d571 for type 'type', which requires 2 byte alignment
0x0007d571: note: pointer points here
 0f 7b 6a  2d e9 f0 4f ad f5 01 7d  00 af c7 f8 34 01 c7 f8  30 11 c7 f8 2c 21 d7 f8  2c 21 d7 f8 2c
              ^ 
/opt/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/include/c++/13.3.1/bits/move.h:71:36: runtime error: reference binding to misaligned address 0x0007d571 for type '<unknown>', which requires 2 byte alignment
0x0007d571: note: pointer points here
 0f 7b 6a  2d e9 f0 4f ad f5 01 7d  00 af c7 f8 34 01 c7 f8  30 11 c7 f8 2c 21 d7 f8  2c 21 d7 f8 2c
              ^ 
/opt/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/include/c++/13.3.1/bits/std_function.h:215:15: runtime error: reference binding to misaligned address 0x0007d571 for type 'type', which requires 2 byte alignment
0x0007d571: note: pointer points here
 0f 7b 6a  2d e9 f0 4f ad f5 01 7d  00 af c7 f8 34 01 c7 f8  30 11 c7 f8 2c 21 d7 f8  2c 21 d7 f8 2c
              ^ 
/opt/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/include/c++/13.3.1/bits/std_function.h:152:59: runtime error: reference binding to misaligned address 0x0007d571 for type 'type', which requires 2 byte alignment
0x0007d571: note: pointer points here
 0f 7b 6a  2d e9 f0 4f ad f5 01 7d  00 af c7 f8 34 01 c7 f8  30 11 c7 f8 2c 21 d7 f8  2c 21 d7 f8 2c
              ^ 

To reproduce:

  • Download the cross compiler from here, I used arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-linux-gnueabihf. But I also tested with 14.2.rel1 and 11.3rel1, which exhibit the same behaviour.
  • Unpack to /opt
  • Run this script from a level below the CLI11 repository:
#!/bin/sh -ue
cd CLI11
rm -rf build
mkdir build
cd build
cmake .. -DCLI11_SINGLE_FILE=1 -DCLI11_BUILD_TESTS=0 -DCLI11_BUILD_EXAMPLES=0 \
   -DCLI11_BUILD_DOCS=0 -DCLI11_BUILD_EXAMPLES_JSON=0 -DCLI11_SINGLE_FILE_TESTS=0

make -j"$(nproc)" all
cd single-include || cd include

cat <<EOF >./test.cpp
#include "CLI11.hpp"
#include <string>

int main(int argc, char** argv) {
   CLI::App app{"App description"};

   std::string filename = "default";
   app.add_option("-f,--file", filename, "A help string");

   CLI11_PARSE(app, argc, argv);
   return 0;
}
EOF


/opt/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-g++ \
   -Wall -std=c++11 -g -fno-omit-frame-pointer -fsanitize=undefined test.cpp

qemu-arm -L /opt/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/libc ./a.out

QEMU needs to be installed. I can confirm that this happens even when running the binary natively on an arm machine.

@phlptp
Copy link
Collaborator

phlptp commented Dec 22, 2024

I have seen some misalignment warnings on some other platforms, usually the processors handle that just fine, but I might dig a bit deeper at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants