This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

-ffreestanding -Wno-main doesn't seem to work



I am getting a certain warning and error using EGCS 1.1.1 configured
as a cross-compiler from i586-pc-linux-gnu to mips-dec-ultrix4.5 using
--with-gnu-as --with-gnu-ld --enable-version-specific-runtime-libs,
which I don't think should happen, according to the documentation.

Here are the versions of the tools I'm using:
mgcc is:
219 brg@sartre:~/vm/test_code> mgcc -v
Reading specs from /usr/local/lib/gcc-lib/mips-dec-ultrix4.5/egcs-2.91.60/specs
gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release)

mld is:
226 brg@sartre:~/vm/test_code> mld -V
GNU ld version 2.9.1 (with BFD 2.9.1.0.19)
  Supported emulations:
   mipslit

mas is:
234 brg@sartre:~/vm/test_code> mas -v /dev/null
GNU assembler version 2.9.1 (mips-dec-ultrix4.5), using BFD version 2.9.1.0.19

sartre is a GNU/Linux system running libc version 5:
235 brg@sartre:~/vm/test_code> uname -a
Linux sartre 2.2.0-final #1 Sat Jan 23 12:07:18 PST 1999 i586 unknown
236 brg@sartre:~/vm/test_code> ls -l /lib/libc.so.5*
lrwxrwxrwx  1 root wheel      14 Jul 16  1998 /lib/libc.so.5 -> libc.so.5.4.44*
-rwxr-xr-x  1 bin  bin   1874736 Feb  1  1998 /lib/libc.so.5.4.44*

This is the error I get, _not_ using -v during the compile and omitting
random make messages (for clarity):
cpp setup.S > setup.s
mas  -o setup.o setup.s
...
mgcc -ffreestanding -Wno-main -g -c -o sort.o sort.c
sort.c: In function `main':
sort.c:90: warning: return type of `main' is not `int'
mgcc -ffreestanding -Wno-main -g -c -o random.o random.c
mld -T ld.script -o sort.fix setup.o sort.o random.o
sort.o: In function `main':
/home/brg/vm/test_code/sort.c:90: undefined reference to `__main'
/home/brg/vm/test_code/sort.c:90: relocation truncated to fit: JMPADDR __main
make: *** [sort.fix] Error 1

sort.c is a program which contains a function void main(void); the
intent of this usually abnormal declaration is that this particular
main doesn't actually take any arguments, because it's an entry point
into what is best understood as kernel code. (The project for which
this code is a test case is a MIPS virtual machine emulator.)
Accordingly, I thought that using -ffreestanding would cause it not to
try to access __main, and that -Wno-main would cause the ``return type
of `main' is not `int''' warning to go away. Am I mistaken? If so,
this should probably be documented, and if not, I claim this is a bug.

(The undefined ref to __main and truncated relocation are expected
given that __main is being inserted as a relocation entry which points
to zero, and given that the text segment is loaded at 0xbfc00000,
since the MIPS ``absolute'' jump instructions cannot jump farther than
0x0fffffff away from the PC. So I'm not complaining about that
bit. :-)

I'm able to get around the bug by calling the entry function ``entry''
instead of ``main'', so it's not a show-stopper, but I'm still a bit
confused; any help you can give would be very useful.

Here is a copy of the complete error listing using the -v option to mgcc,
mld, and mas:
--------------------------------------------------------
make[1]: Entering directory `/home/brg/vm/test_code'
cpp setup.S > setup.s
make[1]: Leaving directory `/home/brg/vm/test_code'
make[1]: Entering directory `/home/brg/vm/test_code'
mas -v  -o setup.o setup.s
GNU assembler version 2.9.1 (mips-dec-ultrix4.5), using BFD version 2.9.1.0.19
make[1]: Leaving directory `/home/brg/vm/test_code'
mgcc -g -ffreestanding -Wno-main -v -c -o sort.o sort.c
Reading specs from /usr/local/lib/gcc-lib/mips-dec-ultrix4.5/egcs-2.91.60/specs
gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release)
 /usr/local/lib/gcc-lib/mips-dec-ultrix4.5/egcs-2.91.60/cpp -lang-c -v -undef -D__GNUC__=2 -D__GNUC_MINOR__=91 -D__ANSI_COMPAT -DMIPSEL -DR3000 -DSYSTYPE_BSD -D_SYSTYPE_BSD -Dbsd4_2 -Dhost_mips -Dmips -Dultrix -Dunix -D__ANSI_COMPAT -D__MIPSEL__ -D__R3000__ -D__SYSTYPE_BSD__ -D_SYSTYPE_BSD -D__bsd4_2__ -D__host_mips__ -D__mips__ -D__ultrix__ -D__unix__ -D__MIPSEL -D__R3000 -D__SYSTYPE_BSD -D__bsd4_2 -D__host_mips -D__mips -D__ultrix -D__unix -Asystem(unix) -Asystem(bsd) -Acpu(mips) -Amachine(mips) -g -Wno-main -D__LANGUAGE_C -D_LANGUAGE_C -DLANGUAGE_C -D__SIZE_TYPE__=unsigned int -D__PTRDIFF_TYPE__=int sort.c /tmp/ccj5QeO2.i
GNU CPP version egcs-2.91.60 19981201 (egcs-1.1.1 release) [AL 1.1, MM 40] DECstation running ultrix
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/lib/gcc-lib/mips-dec-ultrix4.5/egcs-2.91.60/include
 /usr/local/mips-dec-ultrix4.5/include
End of search list.
 /usr/local/lib/gcc-lib/mips-dec-ultrix4.5/egcs-2.91.60/cc1 /tmp/ccj5QeO2.i -quiet -dumpbase sort.c -g -Wno-main -version -ffreestanding -o /tmp/cc20Cw3W.s
GNU C version egcs-2.91.60 19981201 (egcs-1.1.1 release) (mips-dec-ultrix4.5) compiled by GNU C version 2.7.2.3.
sort.c: In function `main':
sort.c:90: warning: return type of `main' is not `int'
 /usr/local/mips-dec-ultrix4.5/bin/as -g -v -o sort.o /tmp/cc20Cw3W.s
GNU assembler version 2.9.1 (mips-dec-ultrix4.5), using BFD version 2.9.1.0.19
mgcc -g -ffreestanding -Wno-main -v -c -o random.o random.c
Reading specs from /usr/local/lib/gcc-lib/mips-dec-ultrix4.5/egcs-2.91.60/specs
gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release)
 /usr/local/lib/gcc-lib/mips-dec-ultrix4.5/egcs-2.91.60/cpp -lang-c -v -undef -D__GNUC__=2 -D__GNUC_MINOR__=91 -D__ANSI_COMPAT -DMIPSEL -DR3000 -DSYSTYPE_BSD -D_SYSTYPE_BSD -Dbsd4_2 -Dhost_mips -Dmips -Dultrix -Dunix -D__ANSI_COMPAT -D__MIPSEL__ -D__R3000__ -D__SYSTYPE_BSD__ -D_SYSTYPE_BSD -D__bsd4_2__ -D__host_mips__ -D__mips__ -D__ultrix__ -D__unix__ -D__MIPSEL -D__R3000 -D__SYSTYPE_BSD -D__bsd4_2 -D__host_mips -D__mips -D__ultrix -D__unix -Asystem(unix) -Asystem(bsd) -Acpu(mips) -Amachine(mips) -g -Wno-main -D__LANGUAGE_C -D_LANGUAGE_C -DLANGUAGE_C -D__SIZE_TYPE__=unsigned int -D__PTRDIFF_TYPE__=int random.c /tmp/ccmJ7GTd.i
GNU CPP version egcs-2.91.60 19981201 (egcs-1.1.1 release) [AL 1.1, MM 40] DECstation running ultrix
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/lib/gcc-lib/mips-dec-ultrix4.5/egcs-2.91.60/include
 /usr/local/mips-dec-ultrix4.5/include
End of search list.
 /usr/local/lib/gcc-lib/mips-dec-ultrix4.5/egcs-2.91.60/cc1 /tmp/ccmJ7GTd.i -quiet -dumpbase random.c -g -Wno-main -version -ffreestanding -o /tmp/ccgfmJ3i.s
GNU C version egcs-2.91.60 19981201 (egcs-1.1.1 release) (mips-dec-ultrix4.5) compiled by GNU C version 2.7.2.3.
 /usr/local/mips-dec-ultrix4.5/bin/as -g -v -o random.o /tmp/ccgfmJ3i.s
GNU assembler version 2.9.1 (mips-dec-ultrix4.5), using BFD version 2.9.1.0.19
mld -v -T ld.script -o sort.fix setup.o sort.o random.o
sort.o: In function `main':
/home/brg/vm/test_code/sort.c:90: undefined reference to `__main'
/home/brg/vm/test_code/sort.c:90: relocation truncated to fit: JMPADDR __main
GNU ld version 2.9.1 (with BFD 2.9.1.0.19)
make: *** [sort.fix] Error 1
--------------------------------------------------------

Here is a copy of sort.c, which has been preprocessed using the exact cpp
command given in the listing above.
--------------------------------------------------------
# 1 "sort.c"
typedef unsigned long ulong_t;









void insertion_sort(ulong_t *array, ulong_t size);
void insert(ulong_t *array, ulong_t size, ulong_t x);





void insertion_sort(ulong_t *array, ulong_t size)
{
 ulong_t x;

 for (x = 1; x < size; x++) {
  insert(array, size, x);
 }
}

void insert(ulong_t *array, ulong_t size, ulong_t x)
{
 ulong_t temp;
 long y, behind;

 temp = array[x];
  
 for (behind = x - 1; behind >= 0; behind--) {
  if (temp >= array[behind]) break;
 }
  
 for (y = x - 1; y > behind; y--) {
  array[y+1] = array[y];
 }
  
 array[behind + 1] = temp;
}

# 76 "sort.c"










extern long random();


void main(void)
{
 ulong_t *x, y;

 x = (ulong_t *)0xa0000000 ;
 for (y = 0; y < 128 ; y++) {
  x[y] = random();
 }
 insertion_sort(x,128 );
}



--------------------------------------------------------

setup.S is a MIPS assembly language program which runs sort.c:main() after
clearing the registers and TLB and setting up global data.

Here is a copy of setup.S:
--------------------------------------------------------
/* setup.S
 *
 * A simple kernel to run one function void FUNCTION(void) in uncached,
 * unmapped kernel space. This program should be the first one linked in.
 */
#include "asm_regnames.h"

#define MEM_BASE		0xa0000000
#define MEM_SIZE		32768
#define INIT_STACK_BASE	MEM_BASE + (MEM_SIZE/2) - 4
#define NTLBENTRIES		64
#define FUNCTION 		main

	.text
	.globl __start

/* Start by clearing everything out. */
__start:
	.set noat
	move $1, $0
	.set at
	move $2, $0
	move $3, $0
	move $4, $0
	move $5, $0
	move $6, $0
	move $7, $0
	move $8, $0
	move $9, $0
	move $10, $0
	move $11, $0
	move $12, $0
	move $13, $0
	move $14, $0
	move $15, $0
	move $16, $0
	move $17, $0
	move $18, $0
	move $19, $0
	move $20, $0
	move $21, $0
	move $22, $0
	move $23, $0
	move $24, $0
	move $25, $0
	move $26, $0
	move $27, $0
	move $28, $0
	move $29, $0
	move $30, $0
	mtc0 $zero, $4
	mtc0 $zero, $8
	mtc0 $zero, $14

	/* Clear out the TLB. */
	li $t2, NTLBENTRIES	/* t2 = TLB entry number */
1:
	addiu $t2, $t2, -1	/* Decrement TLB entry number */
	sll $t1, $t2, 8	/* Shift entry number into Index field position */
	mtc0 $t1, $0		/* set Index */
	mtc0 $zero, $2		/* clear EntryHi */
	mtc0 $zero, $10		/* clear EntryLo */
	tlbwi			/* write TLB[Index] with (EntryHi, EntryLo) */
	bnez $t2, 1b		/* Go back if we're not done yet. */
	nop

	/* Set up the stack and globals pointer. */
	li $sp, INIT_STACK_BASE
	la $gp, _gp

	/* Copy writeable data to writeable RAM. */
	la $t1, _copystart	/* t1 = beginning source address for copy */
	la $t2, _copyend
	addiu $t2, $t2, 4	/* t2 = one word past ending source address */
	move $t3, $gp			/* t3 = beginning dest address */
1:
	lw $t4, 0($t1)			/* load t4 from ROM */
	sw $t4, 0($t3)			/* store it in RAM */
	addiu $t1, $t1, 4		/* increment both pointers */
	addiu $t3, $t3, 4
	bne $t1, $t2, 1b		/* if we're not finished, loop. */
	nop

	/* Call the function. */
	jal FUNCTION

	/* Wait a minute, wait a minute, stop the execution! */
	break 0x0
--------------------------------------------------------

ld.script is used to build the ROM images after the source code is assembled.
Here is a copy of ld.script:
--------------------------------------------------------
OUTPUT_FORMAT(ecoff-littlemips)
SECTIONS {
 ENTRY( __start )
 . = 0xbfc00000;
 .text : { *(.text) ; _etext = . ; }
 . = 0xa0004000;
 _gp = .;
 _copystart = SIZEOF(.text) + ADDR(.text) ;
 .data : AT ( SIZEOF(.text) + ADDR(.text) )
	{ _data = . ; *(.data) ; _edata = . ; }
 .sdata : AT ( SIZEOF(.data) + SIZEOF(.text) + ADDR(.text) )
	{ _sdata = . ; *(.sdata) ; _esdata = . ; }
 _copyend = SIZEOF(.sdata) + SIZEOF(.data) + SIZEOF(.text) + ADDR(.text) ;
 .bss : AT ( SIZEOF(.sdata) + SIZEOF(.data) + SIZEOF(.text) + ADDR(.text) )
	{ _bss = . ; *(.bss) *(COMMON) ; _ebss = . ; }
 _end = . ;
}
--------------------------------------------------------

random.c is (most of) the FreeBSD C Library's implementation of random().
It has been preprocessed as shown above.
--------------------------------------------------------
# 1 "random.c"
 


 



































static inline long good_rand(long);
void srandom(unsigned long x);
long random(void);





 


























































 

































 













long randtbl[31  + 1] = {
	3 ,
# 166 "random.c"

	0x991539b1, 0x16a5bce3, 0x6774a4cd, 0x3e01511e, 0x4e508aaa, 0x61048c05,
	0xf5500617, 0x846b7115, 0x6a19892c, 0x896a97af, 0xdb48f936, 0x14898454,
	0x37ffd106, 0xb58bff9c, 0x59e17104, 0xcf918a49, 0x09378c83, 0x52c7a471,
	0x8d293ea9, 0x1f4fc301, 0xc3db71be, 0x39b44e1c, 0xf8a44ef9, 0x4c8b80b1,
	0x19edc328, 0x87bf4bdd, 0xc9b240e5, 0xe9ee4b1b, 0x4382aee7, 0x535b6b41,
	0xf3bec5da

};

 













long *fptr = &randtbl[3  + 1];
long *rptr = &randtbl[1];

 









long *state = &randtbl[1];
long rand_type = 3 ;
long rand_deg = 31 ;
long rand_sep = 3 ;
long *end_ptr = &randtbl[31  + 1];

long good_rand (x)
	register long x;
{








 







	register long hi, lo;

	hi = x / 127773;
	lo = x % 127773;
	x = 16807 * lo - 2836 * hi;
	if (x <= 0)
		x += 0x7fffffff;
	return (x);

}

 












void
srandom(x)
	unsigned long x;
{
	register long i;

	if (rand_type == 0 )
		state[0] = x;
	else {
		state[0] = x;
		for (i = 1; i < rand_deg; i++)
			state[i] = good_rand(state[i - 1]);
		fptr = &state[rand_sep];
		rptr = &state[0];
		for (i = 0; i < 10 * rand_deg; i++)
			(void)random();
	}
}

 
















long
random()
{
	register long i;
	register long *f, *r;

	if (rand_type == 0 ) {
		i = state[0];
		state[0] = i = (good_rand(i)) & 0x7fffffff;
	} else {
		 


		f = fptr; r = rptr;
		*f += *r;
		i = (*f >> 1) & 0x7fffffff;	 
		if (++f >= end_ptr) {
			f = state;
			++r;
		}
		else if (++r >= end_ptr) {
			r = state;
		}

		fptr = f; rptr = r;
	}
	return(i);
}
--------------------------------------------------------

-- 
Brian R. Gaeke, UC Berkeley -- brg@uclink4.berkeley.edu
"the iguana / in the petshop window on St Catherine Street / crested,
 royal-eyed, ruling / its kingdom of water-dish and sawdust / dreams of
 sawdust" - Margaret Atwood, "Dreams of the Animals"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]