[LLVMdev] Apple's GCC and .s/.S files in llvm-test (fwd)

Dale Johannesen dalej at apple.com
Mon Mar 24 14:40:53 PDT 2008

On Mar 21, 2008, at 10:59 AM, Julien Lerouge wrote:
> Hello,
> Apple's GCC does not make the distinction between .s and .S files and
> always run the preprocessor. From the man:
> |  file.s
> |      Assembler code. Apple's version of GCC runs the preprocessor  
> on these
> |      files as well as those ending in .S.
> |
> |  file.S
> |      Assembler code which must be preprocessed.

Yes.  The reason for this is that MacOS supports some non-case- 
sensitive filesystems, so .s and .S are not in general distinguishable.

> The problem is that sometimes llc generates comments in the assembly
> that look like this for x86:
> 	...
>        pushl   %esi
> 	...
> 	# implicit-def: EDI
> 	...
>        ret
> The comment line is perfectly valid for the assembler, but the
> preprocessor does not like it because it tries to interpret it as a
> macro... I can see it happening for example if -std=c99 is set in the
> CFLAGS (that's the case in SingleSource/Regression/C++) :
>  $ gcc --std=c99  -o t t.s
>  t.s:5:4: error: invalid preprocessing directive #implicit
> One solution is to force the language to be assembler (and not
> assembler-with-cpp) on Darwin, that's what the attached patch does,  
> but
> maybe there is a nicer solution ?

In general I think we want llvm-gcc's output .s files to be acceptable  
as input to gcc, so the right thing is to change the x86 asm printer  
so it doesn't generate these comments.   I don't see a good way to do  
full-line comments that works both if you run the preprocessor and if  
you don't.  (Using #pragma works since compilers are required to  
ignore unknown pragmas, but nobody would call that good.)  If we're  
willing to build in the assumption that the preprocessor will be  
run, // or /**/ comments work.  Or attaching them to the end of the  
previous line works.

More information about the llvm-dev mailing list