hlfs fwrite changes to binutils and gcc

Charity charity at orlandotelco.net
Thu Feb 15 05:38:14 PST 2007

Yes, that's exactly the post I was referring to. Here are my fixes for 
fwrites only that I applied to binutils and gcc for the cocoon and 
butterfly builds. I used the 4.1.2 rc1 version of gcc. binutils 2.17 and 
I successfully compiled the kernel. The upgrade to gcc was 
probably not needed, but the release said it had regression fixes only 
and no new features. I still can't run the gcc test suite, but am 
otherwise having no problems with the compiler. I added autogen so I 
could run the fixincludes test, which runs with no errors, but the gcc 
test fails at the first torchure compile and then hangs even with make 
-k check. I later added the java language and everything bootstrapped 
fine. It may have something to do with the hardened specs file that 
causes the test suite to fail. The type cast to (size_t) is not 
absolutely necessary unless you still want to use the -Werror switch :) 
It will give you a warning that stops the build if it's not there and 
-Werror is set.

Note: These are only changes to the fwrite asserts. I still used the 
other asserts as suggested.

cp -vi binutils/ar.c{,.orig}
sed -e 's/fwrite (cbuf, 1, nread, ostream)/assert( (size_t) nread == 
fwrite (cbuf, 1, nread, ostream))/' \
    -e 's/fwrite (cbuf, 1, nread, stdout)/assert( (size_t) nread == 
fwrite (cbuf, 1, nread, stdout))/' \
    -e 's/#include <sys\/stat.h>/&\n#include <assert.h>/' \
    binutils/ar.c.orig > binutils/ar.c

gcc (careful about the long line, maybe should be a patch file since it 
can't easily fit on the command line)
cp -vi libcpp/lex.c{,.orig}
sed -e 's/fwrite (buffer, 1, 10, fp)/assert( (size_t) 10 == fwrite 
(buffer, 1, 10, fp))/' \
 -e 's/fwrite (token->val.str.text, 1, token->val.str.len, fp)/assert( 
(size_t) token->val.str.len == fwrite (token->val.str.text, 1, 
token->val.str.len, fp))/' \
 -e 's/#include "internal.h"/&\n#include <assert.h>/' \
    libcpp/lex.c.orig > libcpp/lex.c
cp -vi gcc/c-ppoutput.c{,.orig}
sed -e 's/fwrite (pfile->out.base, 1, len, print.outf)/assert( (size_t) 
len == fwrite (pfile->out.base, 1, len, print.outf))/' \
    -e 's/#include "c-pragma.h"/&\n#include <assert.h>/' \
    gcc/c-ppoutput.c.orig > gcc/c-ppoutput.c
cp -vi gcc/dbxout.c{,.orig}
sed -e 's/fwrite (chunk, 1, chunklen, asm_out_file)/assert( (size_t) 
chunklen == fwrite (chunk, 1, chunklen, asm_out_file))/' \
    -e 's/fwrite (str, 1, len, asm_out_file)/assert( (size_t) len == 
fwrite (str, 1, len, asm_out_file))/' \
    -e 's/#include "expr.h"/&\n#include <assert.h>/' \
    gcc/dbxout.c.orig > gcc/dbxout.c

>     hey I saw you had a post at
>     http://article.gmane.org/gmane.linux.lfs.hardened/121
>     I was wondering where it described those fwrite changes.  I'm
>     getting an internal compiler error when building the kernel:
>     binutils 2.17, gcc-4.1.1, linux- (hlfs)
>     ... blaaaaaaa bla
>     arch/i386/mach-generic/../mach-es7000/es7000plat.c:167: warning:
>     'sdt.count' may be used uninitialized in this function
>       LD      arch/i386/mach-generic/../mach-es7000/built- in.o
>       LD      arch/i386/mach-generic/built-in.o
>       CC      arch/i386/kernel/process.o
>       CC      arch/i386/kernel/signal.o
>       AS      arch/i386/kernel/entry.o
>     cc1: /hlfs/work/butterfly-prep/gcc/c-ppoutput.c:200:
>     scan_translation_unit_trad: Assertion `fwrite_unlocked (pfile->
>     out.base, 1, len, print.outf)' failed.
>     <built-in>:0: internal compiler error: Aborted
>     Please submit a full bug report,
>     ... blaaaaaaaa bla :)
>     tia
>     mg

More information about the hlfs-dev mailing list