1

Update 2: So the undefined reference to __end is this:

opt/i386-pc-coff/lib/ndp//libc.a(brk.o):(.data+0x0): undefined reference to `__end'

But when I do objdump of that libc.a file, I see it defined.

brk.o:     file format coff-i386
<...snip...>
SYMBOL TABLE:
[  0](sec  1)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00000000 .text
[  1](sec  2)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00000048 .data
[  2](sec  3)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x0000004c .bss
[  3](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 sbrk
[  4](sec  0)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 __end
[  5](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x0000002a brk
[  6](sec  0)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 .cerror

So I don't really get what the error really means.

Update 1: It appears that gcc 3.1 and 3.2 have a bug in gcc/libgcc2.c where the macro EH_FRAME_SECTION_NAME triggers some #ifdef statements that shouldn't be triggered for coff and hms targets, according to this old email thread. I commented some bits out and now the undefined references to __EH_FRAME_BEGIN__ are gone. The undefined reference to __end still exists, but I am researching if an .ld linker script can't fix things.

Original Message: I am attempting to use my gcc cross-compiler for the first time with a simple Hello World program and I have encountered a number of road blocks. I am using gcc 3.2.3 with a i386-freebsd host, i386-pc-coff target, and binutils 2.19.1a. Everything was built with a prefix of "~/opt". I've placed the contents of /usr/include, /usr/lib, and /lib from my target machine into "~/opt/i386-pc-coff".

#include <stdio.h>
int main(void)
{
    puts("Hello World!");
}

When I attempt to use the standard startup files and libraries when linking, I receive the following error:

[user@vm-fbsd ~]$ i386-pc-coff-gcc -v -D__COHERENT__ helloworld.c
Reading specs from /home/user/opt/lib/gcc-lib/i386-pc-coff/3.2.3/specs
Configured with: ../gcc-3.2.3/configure --target=i386-pc-coff --prefix=/home/user/opt --disable-nls --enable-languages=c,c++
Thread model: single
gcc version 3.2.3
 /home/user/opt/lib/gcc-lib/i386-pc-coff/3.2.3/cc1 -lang-c -v -D__GNUC__=3 -D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=3 -D__GXX_ABI_VERSION=102 -D__NO_INLINE__ -D__STDC_HOSTED__=1 -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i386__ -D__COHERENT__ helloworld.c -quiet -dumpbase helloworld.c -version -o /var/tmp//ccMJ21ag.s
GNU CPP version 3.2.3 (cpplib) (80386, BSD syntax)
GNU C version 3.2.3 (i386-pc-coff)
ignoring nonexistent directory "/home/user/opt/i386-pc-coff/sys-include"
#include "..." search starts here:
#include <...> search starts here:
 /home/user/opt/include
 /home/user/opt/lib/gcc-lib/i386-pc-coff/3.2.3/include
 /home/user/opt/i386-pc-coff/include
End of search list.
 /home/user/opt/lib/gcc-lib/i386-pc-coff/3.2.3/../../../../i386-pc-coff/bin/as --traditional-format -o /var/tmp//ccA3Y8bB.o /var/tmp//ccMJ21ag.s
 /home/user/opt/lib/gcc-lib/i386-pc-coff/3.2.3/collect2 /home/user/opt/lib/gcc-lib/i386-pc-coff/3.2.3/../../../../i386-pc-coff/lib/crt0.o -L/home/user/opt/lib/gcc-lib/i386-pc-coff/3.2.3 -L/home/user/opt/lib/gcc-lib/i386-pc-coff/3.2.3/../../../../i386-pc-coff/lib /var/tmp//ccA3Y8bB.o -lgcc -lc -lgcc
/home/user/opt/lib/gcc-lib/i386-pc-coff/3.2.3/libgcc.a(__main.o): In function `__do_global_dtors':
libgcc2.c:1901: undefined reference to `__EH_FRAME_BEGIN__'
/home/user/opt/lib/gcc-lib/i386-pc-coff/3.2.3/libgcc.a(__main.o): In function `__do_global_ctors':
libgcc2.c:1917: undefined reference to `__EH_FRAME_BEGIN__'
/home/user/opt/lib/gcc-lib/i386-pc-coff/3.2.3/../../../../i386-pc-coff/lib/libc.a(brk.o):(.data+0x0): undefined reference to `__end'
collect2: ld returned 1 exit status

My startup file:

[user@vm-fbsd ~/opt/i386-pc-coff/lib]$ i386-pc-coff-objdump -x crt0.o

crt0.o:     file format coff-i386
crt0.o
architecture: i386, flags 0x00000035:
HAS_RELOC, HAS_LINENO, HAS_SYMS, HAS_LOCALS
start address 0x00000000

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         0000002c  00000000  00000000  0000008c  2**2
                  CONTENTS, ALLOC, LOAD, RELOC, CODE
  1 .data         00000000  0000002c  0000002c  00000000  2**2
                  ALLOC, LOAD, DATA
  2 .bss          00000004  0000002c  0000002c  00000000  2**2
                  ALLOC
SYMBOL TABLE:
[  0](sec  1)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00000000 .text
[  1](sec  2)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x0000002c .data
[  2](sec  3)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x0000002c .bss
[  3](sec  3)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x0000002c environ
[  4](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 _start
[  5](sec  0)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 exit
[  6](sec  0)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 main
[  7](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x0000001e _exit


RELOCATION RECORDS FOR [.text]:
OFFSET   TYPE              VALUE
00000009 dir32             .bss+0xffffffd4
00000011 DISP32            main
0000001a DISP32            exit

I am not using --sysroot because it isn't included in gcc 3. I'm not using gcc 4 or later because both *-coff and *-sysv targets were deprecated. Thoughts?

2
  • 1
    What platform will the code run on? As in, what hardware/OS does i386-pc-coff correspond to? Commented Oct 12, 2024 at 5:03
  • 1
    Coherent 4.2 for i386. Commented Oct 12, 2024 at 5:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.