Link to home
Start Free TrialLog in
Avatar of sean-keys
sean-keys

asked on

manually assembling and linking gcc ouput source files

I have gcc creating asm source files like this.

m68hc11-gcc -g -Wall -Werror -Winline -O -m68hcs12 -mshort -ffunction-sections -fomit-frame-pointer -msoft-reg-count=8 -mauto-incdec -fsigned-char -x cpp-output -S -o assembly/main.s preprocessedc/main.pp.c

from that output I can manually assemble it like this

m68hc11-as main.s -o main.o -m68hcs12

 or like this

m68hc11-gcc -g -Wall -Werror -Winline -O -m68hcs12 -mshort -ffunction-sections -fomit-frame-pointer -msoft-reg-count=8 -mauto-incdec -fsigned-char -c -o objects/freeEMS.o assembly/freeEMS.s
and it wont give me any errors

but when I try to link, I get this.
m68hc12-ld -defsym vectors_addr=0xF710 -m m68hc12elfb -T hc9s12xdp512elfb.x -o output/freeems-0.1.1-SNAPSHOT-Simple.elf objects/Simple.o objects/freeEMS.o objects/staticInit.o objects/main.o objects/tableLookup.o objects/init.o objects/utils.o objects/globalConstants.o objects/coreVarsGenerator.o objects/derivedVarsGenerator.o objects/fuelAndIgnitionCalcs.o objects/flashWrite.o objects/commsCore.o objects/blockDetailsLookup.o objects/interrupts.o objects/injectionISRs.o objects/ignitionISRs.o objects/commsISRs.o objects/realtimeISRs.o objects/miscISRs.o objects/FixedConfig1.o objects/FixedConfig2.o objects/IATTransferTable.o objects/CHTTransferTable.o objects/MAFTransferTable.o objects/TestTransferTable.o objects/FuelTables.o objects/FuelTables2.o objects/TimingTables.o objects/TimingTables2.o objects/TunableConfig.o objects/TunableConfig2.o objects/flashBurn.o
/usr/bin/m68hc11-ld: warning: cannot find entry symbol _start; defaulting to 0000c000
objects/Simple.o: In function `PrimaryRPMISR':
/home/fred/workspaces/home/freeems-vanilla/src/Simple.c:69: undefined reference to `_.tmp'
/home/fred/workspaces/home/freeems-vanilla/src/Simple.c:69: undefined reference to `_.z'
/home/fred/workspaces/home/freeems-vanilla/src/Simple.c:69: undefined reference to `_.xy'
/home/fred/workspaces/home/freeems-vanilla/src/Simple.c:69: undefined reference to `_.d1'
/home/fred/workspaces/home/freeems-vanilla/src/Simple.c:69: undefined reference to `_.d2'
/home/fred/workspaces/home/freeems-vanilla/src/Simple.c:69: undefined reference to `_.d3'
/home/fred/workspaces/home/freeems-vanilla/src/Simple.c:69: undefined reference to `_.d4'
/home/fred/workspaces/home/freeems-vanilla/src/Simple.c:69: undefined reference to `_.d5'
/home/fred/workspaces/home/freeems-vanilla/src/Simple.c:69: undefined reference to `_.d6'
and the list goes on

I can link from gcc, but I need to use an external linker that has special patches.

I'm not quite sure where I am going wrong.  Any input would be appreciated.
ASKER CERTIFIED SOLUTION
Avatar of noci
noci

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sean-keys
sean-keys

ASKER

Ah yeah seems to work with -l /mygcclibs/....  

except  this except.....

mc9s12x-elf-ld: /usr/lib/gcc-lib/m68hc11/3.3.6-m68hc1x-20060122/m68hc12/mshort/crt1.o: Relocations in generic ELF (EM: 53)
/usr/lib/gcc-lib/m68hc11/3.3.6-m68hc1x-20060122/m68hc12/mshort/crt1.o: could not read symbols: File in wrong format
make: *** [output/freeems-0.1.1-SNAPSHOT-Simple.elf] Error 1
seank@mob-sean:/work/workspaceCDT/binutils-mc9s12x/build-testing/testing/f-mc9/freeems-vanilla/src$

So I need to recompile gcc using my binutils package correct?
Wasn't m68hc11-gcc built that way already? Is the output you posted from a run of m68hc11-gcc?
I wonder if there is another m68hc11 crt1.o somewhere that you should load manually - locate crt1.o|grep -w crt1 will show
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That's just it crt1.o needs to be built with my new binutils. Which I have done, but now I get this error when I try to link more than one source file.

mc9$ make all
mc9s12x-elf-as --gstabs  -o main.o main.s
mc9s12x-elf-as --gstabs  -o xgate.o xgate.s
mc9s12x-elf-ld -m mc9s12xelfb --defsym _start=0 -o test.elf main.o xgate.o

 in bfd_default_compatible about to compare 31 and 31
 in bfd_default_compatible about to compare 31 and 31
mc9s12x-elf-ld: failed to merge target specific data of file xgate.o
 in bfd_default_compatible about to compare 31 and 31
 input was 31 output was 31make: *** [test.elf] Error 1

My printf code says they are of the same target, so I dont see what the problem is.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That did work for linking two files generated with asm.  But when I try the gcc example I get

 m68hc11-gcc -mc9s12x -mshort -Wl,-m,mc9s12xelfb --no-warn-mismatch -Wl,-defsym,_io_ports=0x1000 -o test.elf main.o vectors.o
/usr/bin/mc9s12x-elf-ld: failed to merge target specific data of file main.o
/usr/bin/mc9s12x-elf-ld: failed to merge target specific data of file vectors.o
/usr/bin/mc9s12x-elf-ld: failed to merge target specific data of file /usr/lib/gcc-lib/m68hc11/3.3.6-m68hc1x-20060122/mshort/libgcc.a(_regs_min.o)
/usr/bin/mc9s12x-elf-ld: failed to merge target specific data of file /usr/lib/gcc-lib/m68hc11/3.3.6-m68hc1x-20060122/mshort/libgcc.a(_premain.o)
/usr/bin/mc9s12x-elf-ld: failed to merge target specific data of file /usr/lib/gcc-lib/m68hc11/3.3.6-m68hc1x-20060122/mshort/libgcc.a(__exit.o)
/usr/bin/mc9s12x-elf-ld: failed to merge target specific data of file /usr/lib/gcc-lib/m68hc11/3.3.6-m68hc1x-20060122/mshort/libgcc.a(_map_data.o)
/usr/bin/mc9s12x-elf-ld: failed to merge target specific data of file /usr/lib/gcc-lib/m68hc11/3.3.6-m68hc1x-20060122/mshort/libgcc.a(_init_bss.o)

 in bfd_default_compatible about to compare 31 and 31
 in bfd_default_compatible about to compare 31 and 31
 in bfd_default_compatible about to compare 31 and 31
 in bfd_default_compatible about to compare 31 and 31
 in bfd_default_compatible about to compare 31 and 31
 input was 31 output was 31
 in bfd_default_compatible about to compare 31 and 31
 input was 31 output was 31
 in bfd_default_compatible about to compare 31 and 31
 input was 31 output was 31
 in bfd_default_compatible about to compare 31 and 31
 input was 31 output was 31
 in bfd_default_compatible about to compare 31 and 31
 input was 31 output was 31
 in bfd_default_compatible about to compare 31 and 31
 input was 31 output was 31
 in bfd_default_compatible about to compare 31 and 31
 input was 31 output was 31collect2: ld returned 1 exit status
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That did allow my sample project to build.  But my main project which requires newlib fails.  So i figured I could just recompile newlib.  It builds most of it except the last section.

Configured with: ../src/configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --with-gnu-as --with-gnu-ld --enable-nls --without-inclu$
Thread model: single
gcc version 3.3.6-m68hc1x-20060122
 /usr/lib/gcc-lib/m68hc11/3.3.6-m68hc1x-20060122/collect2 -m m68hc11elf -relax /usr/lib/gcc-lib/m68hc11/3.3.6-m68hc1x-20060122/crt1.o -L/usr/lib/gcc-lib/m$
/usr/lib/gcc-lib/m68hc11/3.3.6-m68hc1x-20060122/crt1.o:(.install4+0x1): undefined reference to `main'

I wonder if I my "mc9s12x-elf-ld: failed to merge target specific data of file" problem is really a problem.,,,,
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What noci said.  Figure out how to compile and link a library using a stock compiler, do the same test with your compiler to make sure you have it down, then use -v to see the flags and other hidden stuff.
Thanks guys, I was able to use the information in this thread to get it working!