SpareMiNT Bugtracker
SpareMiNT Bugtracker


Viewing Issue Simple Details Jump to Notes ] Wiki ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0000160 [MiNTLib] bug minor always 2009-04-24 10:48 2009-11-25 15:42
Reporter Alan Hourihane View Status public  
Assigned To vriviere
Priority normal Resolution fixed  
Status resolved  
Summary 0000160: binutils linker (ld) outputs incorrect file when -r option used.
Description Use this simple program...

main()
{
}

then compile...

gcc -c main.c
ld -r -o main2.o main.o
ld -o main3.o main2.o

On the last command the linker will crash because of the output of main2.o is bad.
Additional Information
Tags No tags attached.
Attached Files

- Relationships

-  Notes
(0000184)
vriviere (developer)
2009-10-22 05:59

Now I understand what "ld -r" really is.
It is "relocatable linking", the technique for combining several .o files into a single .o file.
I confirm this is a bug that should be fixed.
I'm going to fix it soon.
(0000187)
Alan Hourihane (developer)
2009-11-24 10:33

Vincent, it seems in the new binutils patch that you abort with "-r" now and terminate ld.

Any ideas when you can fix, otherwise I might start poking ?
(0000188)
vriviere (developer)
2009-11-24 12:25

I confirm it works as expected with my latest binutils patch.

$ m68k-atari-mint-ld --version
GNU ld (GNU Binutils for MiNT 20091024) 2.20
...

$ m68k-atari-mint-gcc -c main.c
$ m68k-atari-mint-ld -r -o main2.o main.o

Now the last instruction in your testcase does not crash, and does what is expected:
$ m68k-atari-mint-ld -o main3.o main2.o
main2.o:main2.o:(.text+0x6): undefined reference to `__main'

This is because calling ld without -r produces an exectuable, not an object file. It is a "final link". In this case, you must give the CRT before the program objects, and link with libgcc and libc.

m68k-atari-mint-ld -o main3.tos /usr/local/cross-mint/m68k-atari-mint/lib/crt0.o main2.o -L/usr/local/cross-mint/lib/gcc/m68k-atari-mint/4.4.2 -lgcc -lc -lgcc

If finally it is OK for you, please close the bug.
(0000189)
Alan Hourihane (developer)
2009-11-24 12:37

Oh, I must not be up-to-date with your latest binutils patch. I'm off to try it right now !

Thanks Vincent!
(0000190)
Alan Hourihane (developer)
2009-11-24 12:41

Mmm, nope. I am up-to-date. I get this when running natively....

bash# ld -r -o main2.o main.o
ld: main2.o: relocatable output is not supported by format a.out-mintprg
ld: final link failed: Invalid operation
(0000191)
Alan Hourihane (developer)
2009-11-24 12:44

In m68kmint_prg_bfd_final_link() we have this in 2.20 binutils which didn't exist before which causes my error.....

+ if (info->relocatable)
+ {
+ _bfd_error_handler ("%B: relocatable output is not supported by format %s
",
+ abfd, bfd_get_target (abfd));
+ bfd_set_error (bfd_error_invalid_operation);
+ return FALSE;
+ }
(0000192)
Alan Hourihane (developer)
2009-11-24 12:49

Oh, hang on. Let me redo - back soon.
(0000193)
vriviere (developer)
2009-11-24 14:15

In the latest patch, I have updated both prg-mint.c and the linker script template in the files m68kmint.sc and m68kmint.sh. I guess you have messed up something, maybe you didn't rebuild the binutils from a clean directory. Or there is something wrong with the native ld, I didn't test it.
(0000194)
Alan Hourihane (developer)
2009-11-24 18:23

Verified. It works, but I can't see how to close bugs. :-(
(0000195)
vriviere (developer)
2009-11-25 15:42

We confirm it had been fixed in the patch binutils-mint-20091024.

- Issue History
Date Modified Username Field Change
2009-04-24 10:48 Alan Hourihane New Issue
2009-10-22 05:59 vriviere Note Added: 0000184
2009-10-22 05:59 vriviere Issue Monitored: vriviere
2009-11-24 10:33 Alan Hourihane Note Added: 0000187
2009-11-24 12:25 vriviere Note Added: 0000188
2009-11-24 12:37 Alan Hourihane Note Added: 0000189
2009-11-24 12:41 Alan Hourihane Note Added: 0000190
2009-11-24 12:42 Alan Hourihane Issue Monitored: Alan Hourihane
2009-11-24 12:44 Alan Hourihane Note Added: 0000191
2009-11-24 12:49 Alan Hourihane Note Added: 0000192
2009-11-24 14:15 vriviere Note Added: 0000193
2009-11-24 18:22 Alan Hourihane Issue End Monitor: Alan Hourihane
2009-11-24 18:23 Alan Hourihane Note Added: 0000194
2009-11-25 15:40 vriviere Status new => assigned
2009-11-25 15:40 vriviere Assigned To => vriviere
2009-11-25 15:42 vriviere Note Added: 0000195
2009-11-25 15:42 vriviere Status assigned => resolved
2009-11-25 15:42 vriviere Resolution open => fixed
2009-12-22 12:12 rmahlert Issue Monitored: rmahlert



Mantis 1.1.8[^]
Copyright © 2000 - 2009 Mantis Group
Powered by Mantis Bugtracker