Home > OS >  C compiler failing with Warning: end of file not at end of a line; newline inserted
C compiler failing with Warning: end of file not at end of a line; newline inserted

Time:07-24

Buon giorno,

my C build started failing on GCC 10.2 cross-compiling from x86_64 to ARM with

{standard input}: Assembler messages:
{standard input}:2186487: Warning: end of file not at end of a line; newline inserted
arm-linux-gnueabihf-g  : fatal error: Killed signal terminated program cc1plus

I don't have any explicit .asm file being built to which I could append a newline to, it happens when compiling a C source file with g . What are my options for debugging this?

CodePudding user response:

I'll describe one possible cause I've seen of such problems - and options for addressing them.

However, from information provided in the question, it's a bit hard to be certain there aren't other causes (or corresponding solutions).

Such symptoms are often a side-effect of transferring source files of a project between systems (e.g. windows and unix) that handle "text" files (bearing in mind that source files contain text) differently. Specifically, some some (file) systems require a text file to have a newline (or a carriage-return newline pair) immediately before the end of a text file, and some don't.

If transferring source files between systems, and not correcting for that, a compiler (which is, at its heart, a program that parses source files) will often complain about things like missing newlines before the end of files.

This problem with file transfer can happen in various ways, such as using ftp and "binary" mode to transfer files, extracting source files from a tarball (or other file archive) on a different host system from where the tarball was created.

Such problems can be avoided somewhat by doing text-based transfers (e.g. using ftp to transfer source files in "text" mode rather than "binary" mode).

If the files are already transferred, some particular programs like dos2unix (if the file has been transferred from a windows machine to a unix machine) can be used to fix all affected source files. Alternatively, the files may be edited by hand (using any text editor, or most IDEs) and adding an additional line at the end of the file.

It's a little bit more unusual to see these symptoms with intermediate files produced in a build process (e.g. an asm file produced as an intermediate step by a C compiler). But, if the source (C or C ) source file has been transferred, some compilers (or compiler versions or particular builds of a compiler) may emit assembler code that causes the assembler to complain in such a way. That can also happen after transferring source files, and is a consequence of how the compiler parses source files, and what assumptions it makes (or checks it doesn't do). But the fix is often the same - to fix the source file(s) from which the intermediate file is being produced.

CodePudding user response:

GCC works by compiling .cpp to an actual asm file (with /usr/lib/gcc/arm-none-eabi/11.2.0/cc1plus or whatever), and running as on it. (Or piping to as.)

If the C compiler is killed (because it's using too much CPU time on some server?), its asm output will be truncated, presumably in the middle of a line. So as sees that and warns, and you get a message about the cc1plus compiler-proper process being terminated by a signal (SIGTERM, not a crash.)

Don't kill your processes before they're finished. (Or don't run your testing on a server which does that. Or if you need to, maybe split up your source file into multiple smaller files which can compile before timing out.)

You haven't given any info in the question on where this is running or what's going on, so it's hard to say anything specific. Jester was able to identify the problem in comments, pointing out that it's a 2-million line asm file.

  • Related