llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
26.82k stars 11k forks source link

[clang][preprocessor][ARM] `--target=thumb` should imply `-mthumb` #96566

Open nickdesaulniers opened 2 weeks ago

nickdesaulniers commented 2 weeks ago

I guess I was surprised to find that --target=thumbv7-linux-gnueabihf did not imply the same preprocessor defines that -mthumb does. This requires llvm-libc to set -mthumb in addition to --target=thumbv7-linux-gnueabihf, which is obnoxious.

See also #96550. cc @kbeyls @smithp35 @rengolin @DanielKristofKiss

llvmbot commented 2 weeks ago

@llvm/issue-subscribers-clang-driver

Author: Nick Desaulniers (paternity leave) (nickdesaulniers)

I guess I was surprised to find that `--target=thumbv7-linux-gnueabihf` did not imply the same preprocessor defines that `-mthumb` does. This requires llvm-libc to set `-mthumb` in addition to `--target=thumbv7-linux-gnueabihf`, which is obnoxious. See also #96550. cc @kbeyls @smithp35 @rengolin @DanielKristofKiss
smithp35 commented 1 week ago

Would it be possible to say which preprocessor defines these are, or an example of one? Would help speed up any investigation.

I can only see three uses of -mthumb OPT_mthumb in the clang driver. Two in Driver/Toolchains/Arch/ARM.cpp and one in Driver/Toolchains/GNU.cpp , none look related to pre-processor macros though. I can only assume that some macros are being defined prior to the triple being normalised?

nickdesaulniers commented 1 week ago
$ comm -3 <(clang --target=thumbv7-linux-gnueabihf -dM -E -x c - < /dev/null | sort ) <(clang --target=thumbv7-linux-gnueabihf -dM -E -mthumb -x c - < /dev/null | sort )
    #define __thumb__ 1
    #define __thumb2__ 1
    #define __THUMBEL__ 1
smithp35 commented 1 week ago

Thank you!

efriedma-quic commented 1 week ago

The clang driver canonicalizes the triple, so you're not actually producing thumb code at all. The defines reflect this.

Arguably --target=thumbv7-linux-gnueabihf should imply -mthumb.

smithp35 commented 1 week ago

I could have sworn that --target=thumbv7-*-*-* implied -mthumb, but it seems like I'm remembering llvm-mc --triple=thumbv7-a. I agree that --target=thumbv7-linux-gnueabihf should imply -mthumb (presumably in the absence of -marm)