On 07/18/2017 08:25 PM, Jonathan Wakely wrote:
On 18 July 2017 at 23:44, Dennis Clarke wrote:
On 07/18/2017 06:33 PM, Jonathan Wakely wrote:
On 18 July 2017 at 21:46, Dennis Clarke wrote:
Fascinating. I never would have thought that a zero line length file
would be accepted as valid. However gcc ( older rev 4.9.2 ) will
accept this :
$ printf "int main ( int argc, char* argv[] ) { return 0; }" > tzero.c
Aside: why would you bother to declare parameters for such a program?
What's wrong with int main(void) ?
I wonder about this every time somebody reports a bug that gives
-Wunused-parameter warnings because of pointless unused parameters.
Since C99 (and in C++) you don't even need the return statement.
int main() { }
Not interested in "-Wunused-parameter" issues. I think you missed the
point.
No, I didn't, that's why I started my reply with "Aside:" -- did you miss that?
yep .. missed it :-\
sorry.
On an entirely separate topic it really is cool to see how amazingly
terse and clean the output assembly is from gcc. As opposed to some
massive compiler like the Oracle Studio stuff. Which is really the
old Sun Studio which is really the Forte Studio which is really ...
$ cat hello.c
#define _XOPEN_SOURCE 600
#include <stdlib.h>
#include <stdio.h>
int main( int argc, char *argv[] ) {
printf ( "duh ..\n" );
exit ( EXIT_SUCCESS );
}
$
$ /usr/local/gcc4/bin/gcc -m64 -std=c99 -pedantic -D_TS_ERRNO
-D_POSIX_PTHREAD_SEMANTICS -D_LARGEFILE64_SOURCE -D_XOPEN_SOURCE=600 -S
-o hello_492.s hello.c
$ cat hello_492.s
.file "hello.c"
.section ".rodata"
.align 8
.LLC0:
.asciz "duh .."
.section ".text"
.align 4
.global main
.type main, #function
.proc 04
main:
save %sp, -176, %sp
mov %i0, %g1
stx %i1, [%fp+2183]
st %g1, [%fp+2175]
sethi %h44(.LLC0), %g1
or %g1, %m44(.LLC0), %g1
sllx %g1, 12, %g1
or %g1, %l44(.LLC0), %o0
call puts, 0
nop
mov 0, %o0
call exit, 0
nop
nop
.size main, .-main
.ident "GCC: (genunix Fri Jan 2 11:56:03 GMT 2015) 4.9.2"
$
Look at that. Perfectly terse and to the point.
Now pass that to the C99 compiler/assembler/linker :
$ c99 -m64 -o hello_c99 hello_492.s
$ ./hello_c99
duh ..
$ mcs -p ./hello_c99
./hello_c99:
@(#)SunOS 5.10 Generic January 2005
as: Sun Compiler Common 12.4 SunOS_sparc 2014/10/20
GCC: (genunix Fri Jan 2 11:56:03 GMT 2015) 4.9.2
ld: Software Generation Utilities - Solaris Link Editors: 5.10-1.1522
cool.
Care to see the assembly from the Oracle C99 compiler ?
$ c99 -Xc -m64 -D_TS_ERRNO -D_POSIX_PTHREAD_SEMANTICS
-D_LARGEFILE64_SOURCE -D_XOPEN_SOURCE=600 -S -o hello_c99.s hello.c
$
$ wc -l hello_c99.s
197 hello_c99.s
Where is 197 lines coming from ? We get everything plus the phone book
and your pet dogs favorite bone :
$ cat hello_c99.s
.section ".text",#alloc,#execinstr
.L_y0:
.align 8
.word 65536
.word 65536
.word 65536
.word 65536
.word 65536
.word 65536
! block 0
.global main
.type main,#function
main:
.L_y3:
save %sp,-208,%sp
! block 1
.L13:
st %i0,[%fp+2043]
stx %i1,[%fp+2031]
! block 2
.L14:
! File hello.c:
! 1 #define _XOPEN_SOURCE 600
! 2 #include <stdlib.h>
! 3 #include <stdio.h>
! 4
! 5 int main( int argc, char *argv[] ) {
! 6 printf ( "duh ..\n" );
sethi %h44(.L16),%o0
or %o0,%m44(.L16),%o0
sllx %o0,12,%o0
or %o0,%l44(.L16),%o0
call printf
nop
! 7 exit ( EXIT_SUCCESS );
call exit
mov 0,%o0
! 8 }
mov 0,%l0
st %l0,[%fp+2027]
! block 3
.L12:
mov 0,%l0
sra %l0,0,%i0
jmp %i7+8
restore
.size main,(.-main)
.L_y4:
.align 8
.section ".annotate",#progbits
! ANNOTATION: Header
.asciz "anotate"
.word 6
.word 0
.xword .L_y2 - .L_y1
.L_y1:
! ANNOTATION: Module
.word 0
.word .L_y6 - .L_y5
.L_y5:
.xword .L_y0
.xword .L_y4 - .L_y0
.L_y6:
! ANNOTATION: Function
.word 1
.word .L_y8 - .L_y7
.L_y7:
.xword .L_y3
.xword .L_y4 - .L_y3
.word -2141695872
.word 0
.L_y8:
.L_y2:
! ANNOTATION: End
.section ".rodata1",#alloc
.align 8
.L16:
.ascii "duh ..\n\000"
.type .L16,#object
.size .L16,8
.section ".data",#alloc,#write
Ddata.data:
.skip 0
.type Ddata.data,#object
.size Ddata.data,0
.section ".rodata",#alloc
Drodata.rodata:
.skip 0
.type Drodata.rodata,#object
.size Drodata.rodata,0
.section ".picdata",#alloc,#write
Dpicdata.picdata:
.skip 0
.type Dpicdata.picdata,#object
.size Dpicdata.picdata,0
.section ".bss",#alloc,#write
Bbss.bss:
.skip 0
.type Bbss.bss,#object
.size Bbss.bss,0
.file "hello.c"
.ident "@(#)stdlib.h 1.52 12/08/01 SMI"
.ident "@(#)stdlib_iso.h 1.9 04/09/28 SMI"
.ident "@(#)feature_tests.h 1.26 11/04/12 SMI"
.ident "@(#)ccompile.h 1.2 04/11/08 SMI"
.ident "@(#)isa_defs.h 1.30 11/03/31 SMI"
.ident "@(#)stdlib_c99.h 1.2 04/03/29 SMI"
.ident "@(#)wait.h 1.23 04/06/03 SMI"
.ident "@(#)types.h 1.90 14/04/07 SMI"
.ident "@(#)machtypes.h 1.13 99/05/04 SMI"
.ident "@(#)int_types.h 1.10 04/09/28 SMI"
.ident "@(#)resource.h 1.37 07/02/07 SMI"
.ident "@(#)time.h 2.79 13/07/01 SMI"
.ident "@(#)select.h 1.19 04/01/28 SMI"
.ident "@(#)time_impl.h 1.11 05/05/19 SMI"
.ident "@(#)siginfo.h 1.59 04/07/15 SMI"
.ident "@(#)machsig.h 1.15 99/08/15 SMI"
.ident "@(#)time_std_impl.h 1.3 04/01/21 SMI"
.ident "@(#)procset.h 1.26 11/04/18 SMI"
.ident "@(#)signal.h 1.67 13/09/11 SMI"
.ident "@(#)signal_iso.h 1.6 03/05/02 SMI"
.ident "@(#)unistd.h 1.46 12/01/17 SMI"
.ident "@(#)ucontext.h 1.31 03/12/18 SMI"
.ident "@(#)regset.h 1.29 07/09/06 SMI"
.ident "@(#)stdio.h 1.86 13/09/11 SMI"
.ident "@(#)stdio_iso.h 1.8 05/08/16 SMI"
.ident "@(#)va_list.h 1.15 04/11/19 SMI"
.ident "@(#)stdio_tag.h 1.4 04/09/28 SMI"
.ident "@(#)stdio_impl.h 1.15 07/03/05 SMI"
.ident "@(#)stdio_c99.h 1.2 04/03/29 SMI"
.ident "acomp: Sun C 5.13 SunOS_sparc 2014/10/20"
.global __fsr_init_value
__fsr_init_value = 0x0
! Begin sdCreateSection : .debug_info
! Section Info: link_name/strtab=, entsize=0x1, adralign=0x1, flags=0x0
! Section Data Blocks:
! reloc[0]: knd=2, off=14, siz=8, lab1=.debug_abbrev, lab2=, loff=0
! reloc[1]: knd=2, off=264, siz=8, lab1=.debug_line, lab2=, loff=0
.section ".debug_info"
.byte 0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00
.byte 0x00,0x00,0x01,0x05,0x00,0x02
.uaxword %section_symbol(".debug_abbrev")
.byte 0x08,0x01
.ascii "hello.c\0"
.byte 0x0c
.ascii "DBG_GEN 5.5.0\0"
.ascii "/export/home/dclarke/pgm/C/hello/\0"
.ascii "/opt/solarisstudio12.4/bin/c99 -Xc -m64 -D_TS_ERRNO
-D_POSIX_PTHREAD_SEMANTICS -D_LARGEFILE64_SOURCE -D_XOPEN_SOURCE='600'
-S hello.c\0"
.ascii "Xa;R=5.13<<Sun C 5.13 SunOS_sparc 2014/10/20>>;\0"
.uaxword %section_symbol(".debug_line")
.byte 0x00
! End sdCreateSection
! Begin sdCreateSection : .debug_line
! Section Info: link_name/strtab=, entsize=0x1, adralign=0x1, flags=0x0
! Section Data Blocks:
.section ".debug_line"
.byte 0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00
.byte 0x00,0x00,0x00,0x25,0x00,0x02,0x00,0x00
.byte 0x00,0x00,0x00,0x00,0x00,0x1b,0x04,0x00
.byte 0xff,0x04,0x0a,0x00,0x01,0x01,0x01,0x01
.byte 0x00,0x00,0x00,0x01,0x00,0x68,0x65,0x6c
.byte 0x6c,0x6f,0x2e,0x63,0x00,0x00,0x00,0x00
.byte 0x00
! End sdCreateSection
! Begin sdCreateSection : .debug_abbrev
! Section Info: link_name/strtab=, entsize=0x1, adralign=0x1, flags=0x0
! Section Data Blocks:
.section ".debug_abbrev"
.byte 0x01,0x11,0x00,0x03,0x08,0x13,0x0b,0x25
.byte 0x08,0x1b,0x08,0x85,0x44,0x08,0x87,0x44
.byte 0x08,0x10,0x07,0x00,0x00,0x00
! End sdCreateSection
.xstabs ".stab.index","V=10.0;DBG_GEN=5.5.0;Xa;R=5.13<<Sun C
5.13 SunOS_sparc 2014/10/20>>",60,0,0,0
.xstabs ".stab.index","/export/home/dclarke/pgm/C/hello;
/opt/solarisstudio12.4/bin/c99 -Xc -m64 -D_TS_ERRNO
-D_POSIX_PTHREAD_SEMANTICS -D_LARGEFILE64_SOURCE -D_XOPEN_SOURCE='600'
-S hello.c",52,0,0,0
.xstabs ".stab.index","main",42,0,0,5
$
That is a hell of a lot of fluff in there.
$ c99 -Xc -m64 -o hello_c99_2 hello_c99.s
$ ls -laptr hello_c99*
-rwxr-xr-x 1 dclarke devl 7424 Jul 19 00:42 hello_c99
-rw-r--r-- 1 dclarke devl 5010 Jul 19 00:45 hello_c99.s
-rwxr-xr-x 1 dclarke devl 9584 Jul 19 00:49 hello_c99_2
$
the output binary is a bit more fat also.
There is 1160 bytes of info added :
$ mcs -p hello_c99_2 | wc
37 144 1160
$
$ mcs -p hello_c99_2
hello_c99_2:
@(#)SunOS 5.10 Generic January 2005
as: Sun Compiler Common 12.4 SunOS_sparc 2014/10/20
@(#)stdlib.h 1.52 12/08/01 SMI
@(#)stdlib_iso.h 1.9 04/09/28 SMI
@(#)feature_tests.h 1.26 11/04/12 SMI
@(#)ccompile.h 1.2 04/11/08 SMI
@(#)isa_defs.h 1.30 11/03/31 SMI
@(#)stdlib_c99.h 1.2 04/03/29 SMI
@(#)wait.h 1.23 04/06/03 SMI
@(#)types.h 1.90 14/04/07 SMI
@(#)machtypes.h 1.13 99/05/04 SMI
@(#)int_types.h 1.10 04/09/28 SMI
@(#)resource.h 1.37 07/02/07 SMI
@(#)time.h 2.79 13/07/01 SMI
@(#)select.h 1.19 04/01/28 SMI
@(#)time_impl.h 1.11 05/05/19 SMI
@(#)siginfo.h 1.59 04/07/15 SMI
@(#)machsig.h 1.15 99/08/15 SMI
@(#)time_std_impl.h 1.3 04/01/21 SMI
@(#)procset.h 1.26 11/04/18 SMI
@(#)signal.h 1.67 13/09/11 SMI
@(#)signal_iso.h 1.6 03/05/02 SMI
@(#)unistd.h 1.46 12/01/17 SMI
@(#)ucontext.h 1.31 03/12/18 SMI
@(#)regset.h 1.29 07/09/06 SMI
@(#)stdio.h 1.86 13/09/11 SMI
@(#)stdio_iso.h 1.8 05/08/16 SMI
@(#)va_list.h 1.15 04/11/19 SMI
@(#)stdio_tag.h 1.4 04/09/28 SMI
@(#)stdio_impl.h 1.15 07/03/05 SMI
@(#)stdio_c99.h 1.2 04/03/29 SMI
acomp: Sun C 5.13 SunOS_sparc 2014/10/20
ld: Software Generation Utilities - Solaris Link Editors: 5.10-1.1522
$
Not sure where the fat comes from because if I just use gcc in one pass
with no intermediate assembly file then I get :
$ /usr/local/gcc4/bin/gcc -m64 -std=c99 -pedantic -D_TS_ERRNO \
> -D_POSIX_PTHREAD_SEMANTICS -D_LARGEFILE64_SOURCE \
> -D_XOPEN_SOURCE=600 -o hello_492 hello.c
$ ls -l hello_492
-rwxr-xr-x 1 dclarke devl 9560 Jul 19 00:51 hello_492
So 9560 bytes.
Anyways, fairly interesting to produce the assembly from gcc, or perhaps
even the preprocessed intermediate and then pass to the Oracle assembler
and linker stage to get a very small file. Whereas one pass creates a
larger binary. Could play with this all day .. but, maybe not. I really
need to bootstrap a recent gcc to see what happens there.
Dennis