Subject: Re: $./a.out Memory fault / gcc
To: Wood <758534@gmail.com>
From: Greg Troxel <gdt@ir.bbn.com>
List: netbsd-help
Date: 04/01/2007 09:09:10
  Is read and write protected words?

They are names of system calls and should not be used in normal user
programs, but they are not reserved words in the language.

man 2 read
man 2 write

printf apparently gets turned into puts, and that ends up calling
write:

#10 0x08048707 in write ()
#11 0xbbbc589c in __swrite () from /usr/lib/libc.so.12
#12 0xbbbc2e2c in __sflush () from /usr/lib/libc.so.12
#13 0xbbbc2ec1 in fflush () from /usr/lib/libc.so.12
#14 0xbbbc2d5c in __sfvwrite () from /usr/lib/libc.so.12
#15 0xbbb929f1 in puts () from /usr/lib/libc.so.12
#16 0x08048707 in write ()

  It works perfect on Linux and FreeBSD.

That's interesting, but perhaps somehow the way the program is linked
allows the printf library routine to call the write system call, or
perhaps it calls writev.

I don't have the C spec handy, but I'd say that redefining standard
library function names should result in undefined behavior.  Undefined
behavior includes a segmentation fault, so NetBSD seems ok here.

There's a harder question of how this could be caught in a more
friendly way.

-- 

    Greg Troxel <gdt@ir.bbn.com>