https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109534
Bug ID: 109534 Summary: -fdirectives-only does not work with assembler-with-cpp Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: boris at kolpackov dot net Target Milestone: --- I've noticed that -fdirectives-only has no effect when preprocessing assembler-with-cpp files. Instead, one always get a fully preprocessed source: $ cat <<EOF >test.S #define MAIN_RESULT 2 .text .global main main: movq $MAIN_RESULT, %rax ret EOF $ gcc -E -fdirectives-only -o test.Si test.S $ cat test.Si # 0 "test.S" # 0 "<built-in>" # 0 "<command-line>" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 0 "<command-line>" 2 # 1 "test.S" .text .global main main: movq $2, %rax ret Running the same command with -v reveals that -fdirectives-only is overriden with -fno-directives-only: $ gcc -v -E -fdirectives-only -o test.Si test.S ... /usr/lib/gcc/x86_64-linux-gnu/12/cc1 -E -lang-asm -quiet -v -imultiarch x86_64-linux-gnu test.S -o test.Si -mtune=generic -march=x86-64 -fdirectives-only -fasynchronous-unwind-tables -fno-directives-only -dumpbase test.S -dumpbase-ext .S ... And I've tracked this down to the following old gcc/ChangeLog-2007 entry: 2007-08-30 Ollie Wild <a...@google.com> * c-opts.c (c_common_handle_option): Support -fno-directives-only. * gcc.c (default_compilers): Add -fno-directives-only to @assembler-with-cpp. Unfortunately there is no rationale (I've also checked the commit message and there is nothing there either). I then tried to manually remove -fno-directives-only and see what happens: $ /usr/lib/gcc/x86_64-linux-gnu/12/cc1 -E -lang-asm -quiet -v -imultiarch x86_64-linux-gnu test.S -o test.Si -mtune=generic -march=x86-64 -fdirectives-only -fasynchronous-unwind-tables -dumpbase test.S -dumpbase-ext .S The resulting test.Si file looked sensible so I tried to compile it further: $ gcc -v -x assembler-with-cpp -fpreprocessed -fdirectives-only main.Sii But -fno-directives-only is passed in this case as well so I had to tweak and run the underlying commands manually: $ /usr/lib/gcc/x86_64-linux-gnu/12/cc1 -E -lang-asm -quiet -v -imultiarch x86_64-linux-gnu test.Si -mtune=generic -march=x86-64 -fpreprocessed -fdirectives-only -fasynchronous-unwind-tables -o test.s $ as -v --64 -o test.o test.s test.Si:1: Error: junk at end of line, first unrecognized character is `0' The beginning of test.s looks like this: $ head -4 test.s # 1 "test.Si" 0 "test.S" # 0 "<built-in>" # 0 "<built-in>" The second line definitely looks wrong (missing #? maybe that's what the above commit was hacking around?). But if I fix that, for example, by adding the leading #, the rest looks correct and everything compiles, links, and runs as expected. So it seems like making -fdirectives-only work for assembler-with-cpp is a matter of tracking down and fixing that broken line directive generation.