[SAoC] 'DPP with Linux kernel headers' Project Thread
Cristian Becerescu
cristian.becerescu at yahoo.com
Fri Oct 4 16:38:52 UTC 2019
Sorry for not updating this thread in a while.
I've managed to do some progress on this project, but from now on
I'll have more time, considering I finished my internship.
Here are some updates and things I found out during those weeks:
1. Yes, as Atila said, I can pass flags to clang through dpp by
using --clang-option. The only inconvenience with this is that
every clang flag needs to be preceeded by a --clang-option flag
(this becomes unmanageable when dealing with tens of compiler
flags, e.g. for compiling kernel headers).
This is not a problem which affects the capabilities of d++, but
it impacts the ease of use and increases the chances of
mistyping, forgetting to add the flag or adding it in a wrong
place.
Solution #1 would be defining arraySep="," so that the getOpt()
function (used for parsing the command line) could accept
multiple flags at once for clang-options:
--clang-options=-D__KERNEL__,-Werror,-Wextra).
Solution #2 could be providing a string containing all clang
options: --clang-options "-D__KERNEL__ -Werror -Wextra", which
would be more convenient when copy-pasting flags from the kernel
build files.
2. The LLVM compiler infrastructure doesn't yet support the 'asm
goto' gcc extension.
I encountered this problem while trying to compile a simple,
empty main C program which #included linux/namei.h.
If the kernel is built with CONFIG_JUMP_LABEL and
CC_HAVE_ASM_GOTO set, using clang will not work (for details, see
asm/compiler.h, asm/compiler_types.h, asm/compiler-gcc.h,
asm/compiler-clang.h). There is a macro (asm_volatile_goto(x))
used in asm/jump_label.h which is declared in asm/compiler-gcc.h,
but not in asm/compiler-clang.h (asm/jump_label.h includes one of
the two, but always uses the macro, even though in one of the
included files the macro is not defined). Undefining
CC_HAVE_ASM_GOTO (or just not defining it with -D...) when
compiling the .c file worked.
The motivation of debugging this was to first make sure that I
can compile a .c file (containing a kernel header) using clang,
so that then, when I compile a .dpp file using d++ (and clang
internally) and get errors, I know that there are problems
withing dpp and not clang.
3. After making sure clang worked with the above .c program, I
tried compiling the .dpp one with the same clang options preceded
by --clang-option. This currently does not work, as clang reports
some "undeclared identifier" and other syntax errors which I'll
have to dig into deeper to understand whether it's a problem with
the way the flags are passed to clang or something else.
More information about the Digitalmars-d
mailing list