[cfe-dev] clangd/libclang: how to emulate other compilers?

Milian Wolff via cfe-dev cfe-dev at lists.llvm.org
Thu Apr 19 05:56:55 PDT 2018

On Donnerstag, 19. April 2018 14:12:21 CEST Manuel Klimek wrote:

> Ah, sorry, I missed the neon part. So this works if we add
> -mcpu=cortex-a15. The problem is that the gcc cross compiler apparently has
> that configured at build time, and I'm not sure what the best way is to
> figure out the full settings for cpu / fpu and float-abi, but I think we'll
> need to find some way to gather them from the underlying cross compiler.

OK, thanks. This brings us one more step closer towards emulation and should 
be sufficient for the example I have given. So, we now end up with these 

#1: query the target compiler
$ ./gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-
gnueabihf-gcc -xc++ -E -v -dM - < /dev/null

#2: parse the output for the target:
Target: arm-linux-gnueabihf

#3: parse the default march GCC argument from:
COLLECT_GCC_OPTIONS='-E' '-v' '-dM' '-march=armv7-a' '-mtune=cortex-a9' '-
mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mthumb' '-mtls-dialect=gnu'

#4: parse the include paths:
#include <...> search starts here:

#5: exclude the GCC builtin include path, i.e.:

For now, this can be done by some heuristics, like checking whether the folder 
contains a "varargs.h" file.

#6: parse the defines and write all into a file that starts with `#pragma 
clang system_header`

#7 parse the file with clang:

clang -Xclang -ast-dump -fsyntax-only -xc++ \
  -target arm-linux-gnueabihf \ (from #2)
  -march=armv7-a \ (from #3)
  -isystem... \ (from #4, 5)
  -imacros... \ (from #6)

This seems to work! Thanks for the help Manuel!

Milian Wolff
mail at milianw.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180419/6a848584/attachment.sig>

More information about the cfe-dev mailing list