On Tue, Nov 28, 2017 at 11:26 AM, Dan Cross <crossd@gmail.com> wrote:
On Tue, Nov 28, 2017 at 12:56 PM, Warner Losh <imp@bsdimp.com> wrote:
Ah, the tyranny of  static analysis tools... _exit(0) should be marked such that the tools know it does not return. This means the /*NOTREACHED*/ isn't needed. And since there's no real exit path out of  main, the return (0) is equally bogus (because main can't return). Yet lint and other tools have ushered in this insanity.

Hmm; in what way can main() not return? Surely this is true if `_exit(0)` is called as this calls the exit system call, which cannot -- by definition -- return. But main() itself can return to whatever calls it (usually `start`, I'd imagine). For that matter, I'm not aware of any prohibition against calling `main()` recursively.

Ture but completely irrelevant. If exit happens, the process is done. main isn't going to return because control never returns back to main. That's what makes the messages completely bogus. Execution simply stops. _exit() doesn't cause main() to return to _start(), the process stops executing at that point.

This is much smaller than the binary for the assembler program I posted for macOS earlier in this thread: the result there was much larger (but due to the requirement to have a non-empty data segment in the executable; this ends up being page-aligned and filled with zeros).

Contrast that with FreeBSD's /usr/bin/true:
-r-xr-xr-x  1 root  wheel  4624 Nov 20 11:56 /usr/bin/true
  text   data   bss    dec     hex   filename
  1540    481     8   2029   0x7ed   /usr/bin/true

which is little more than return(0), but also has a fair amount of copyright and SCCS data.

Is the copyright data actually present in the object file? I see some RCS $Id$ strings (in the guise of $FreeBSD:$ stuff) but no copyright strings in /usr/bin/true on my system.

Ah yes, I read the source, but hadn't checked the final binary... Most of the data seems to be other things...  It used to get the copyright data with gcc a long time ago...

Warner