problems with binutils 2.20

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
FlashBurn
Member
Member
Posts: 313
Joined: Fri Oct 20, 2006 10:14 am

problems with binutils 2.20

Post by FlashBurn »

Yesterday I switched to gcc 4.4.3 (from 4.4.2) and to binutils 2.20 (from 1.19) and now I have problems with compiling my loader. I get errors with undefined references, but the code worked with the old binutils! The undefined references are the functions which are defined in other object files and I get the errors when I try to link my loader:

Code: Select all

ld loader_stub.o $(OBJS) -o osloader -nostdlib -T loader.ld
In $(OBJS) are my object files.

I use this linker script:

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(loader_stub)

SECTIONS
{
	. = 0x500;
	_text_start = .;
	.text : { *(.text) }
	
	. = ALIGN(16);
	_data_start = .;
	.data : { *(.data) }
	
	. = ALIGN(16);
	_bss_start = .;
	.bss : { *(.bss) }
	
	. = ALIGN(16);
	_loader_end = .;
}
So does anyone has similar problems with the new binutils or/and does know what the problem is?
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: problems with binutils 2.20

Post by AJ »

Hi,

I am the one who updated the wiki to reflect GCC 4.4.2 with binutils 2.20 and no linking problems here. I have yet to try 4.4.3, but could you provide the exact error messages and the contents of $(OBJS), please?

Cheers,
Adam
FlashBurn
Member
Member
Posts: 313
Joined: Fri Oct 20, 2006 10:14 am

Re: problems with binutils 2.20

Post by FlashBurn »

Ok, in $(OBJS) are as said, my objects files (like kernel.o string.o and so on) and here comes one of the error msgs:

Code: Select all

patriciatree.o: In function `patriciaTreeGetValue':
patriciatree.c:(.text+0x194): undefined reference to `strlen'
patriciatree.c:(.text+0x1e6): undefined reference to `strcmp'
The thing is I updated last year to binutils 2.20 and there I got an error msg that there is something wrong with the linker script and I downgraded to binutils 2.19. So yesterday I thought when I create gcc 4.4.3 I also could try binutils 2.20 once more.
Grunt
Member
Member
Posts: 37
Joined: Fri Nov 06, 2009 1:05 am

Re: problems with binutils 2.20

Post by Grunt »

What if you put string.o before kernel.o in the command line?
FlashBurn
Member
Member
Posts: 313
Joined: Fri Oct 20, 2006 10:14 am

Re: problems with binutils 2.20

Post by FlashBurn »

@Grunt

This isn´t the problem, because string.o comes before patriciatree.o!
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: problems with binutils 2.20

Post by xenos »

Have you tried to look up which symbols are actually present in string.o?
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
FlashBurn
Member
Member
Posts: 313
Joined: Fri Oct 20, 2006 10:14 am

Re: problems with binutils 2.20

Post by FlashBurn »

Yeah, and all the symbols which should are marked as global.

Edit::

It has to be a problem with my linker script, because when I don´t use the linker script, I only get errors because of the symbols I define in my linker script, but I don´t get the other errors!

So if I remembering right they changed something in linker scripts with 2.20. Does anybody know what this was?
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: problems with binutils 2.20

Post by qw »

Underscores?
FlashBurn
Member
Member
Posts: 313
Joined: Fri Oct 20, 2006 10:14 am

Re: problems with binutils 2.20

Post by FlashBurn »

The underscores are not the problem!

I just found out that the undefined reference error does not come for all symbols of other files!?

The relocation section (readelf -a menu.o) for one object file:

Code: Select all

Relocation section '.rel.text' at offset 0xafc contains 22 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
0000000d  00000c02 R_386_PC32        00000000   memAlloc
00000068  00000e01 R_386_32          00000004   root
00000073  00000501 R_386_32          00000000   .rodata.str1.1
00000078  00000501 R_386_32          00000000   .rodata.str1.1
0000007e  00000b02 R_386_PC32        00000000   menuAddEntry
00000086  00000e01 R_386_32          00000004   root
00000091  00000f01 R_386_32          00000000   vbeMenuFailSafeOption
0000009a  00000601 R_386_32          00000000   .rodata.str1.4
0000009f  00000501 R_386_32          00000000   .rodata.str1.1
000000a5  00000b02 R_386_PC32        00000000   menuAddEntry
000000ad  00000e01 R_386_32          00000004   root
00000174  00000801 R_386_32          00000000   .rodata
0000034a  00001002 R_386_PC32        00000000   callBIOS
0000038d  00000801 R_386_32          00000000   .rodata
000004ba  00001201 R_386_32          00000000   loaderArgs
000004d2  00001201 R_386_32          00000000   loaderArgs
000004dc  00001201 R_386_32          00000000   loaderArgs
000004e6  00001201 R_386_32          00000000   loaderArgs
00000532  00001301 R_386_32          00000004   menuScrOldCur
0000054c  00000801 R_386_32          00000000   .rodata
00000580  00000e01 R_386_32          00000004   root
0000058f  00001301 R_386_32          00000004   menuScrOldCur
and the symbol table:

Code: Select all

Symbol table '.symtab' contains 20 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000     0 FILE    LOCAL  DEFAULT  ABS menu.c
     2: 00000000     0 SECTION LOCAL  DEFAULT    1
     3: 00000000     0 SECTION LOCAL  DEFAULT    3
     4: 00000000     0 SECTION LOCAL  DEFAULT    4
     5: 00000000     0 SECTION LOCAL  DEFAULT    5
     6: 00000000     0 SECTION LOCAL  DEFAULT    6
     7: 000000c0  1008 FUNC    LOCAL  DEFAULT    1 menuExec
     8: 00000000     0 SECTION LOCAL  DEFAULT    7
     9: 0000002c    15 OBJECT  LOCAL  DEFAULT    7 menuTopLineStr
    10: 00000000     0 SECTION LOCAL  DEFAULT    9
    11: 00000000    89 FUNC    GLOBAL DEFAULT    1 menuAddEntry
    12: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND memAlloc
    13: 00000060    92 FUNC    GLOBAL DEFAULT    1 menuInit
    14: 00000004     4 OBJECT  GLOBAL DEFAULT  COM root
    15: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND vbeMenuFailSafeOption
    16: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND callBIOS
    17: 000004b0   292 FUNC    GLOBAL DEFAULT    1 menuEnter
    18: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND loaderArgs
    19: 00000004     4 OBJECT  GLOBAL DEFAULT  COM menuScrOldCur
And now the error which I get from ld:

Code: Select all

menu.o: In function `menuExec':
menu.c:(.text+0x34a): undefined reference to `callBIOS'
So I wonder now why is there only an undefined reference to "callBIOS" and not also to memAlloc, vbeMenuFailSafeOption and loaderArgs?!

The thing is I never saw an error with an undefined reference to "printf", but to "itoa" which is in the same object file.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: problems with binutils 2.20

Post by AJ »

Hi,

The only thing I can see with your linker script is that you have no .rodata section defined, even though your have .rodata entries in the object file dump. Although I'd expect that to cause link problems with your strings, not your functions...

Cheers,
Adam
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: problems with binutils 2.20

Post by gravaera »

Hi:

As a general rule, you must place object file with dependencies first on the command line, followed by object files with none. So an object which depends on strings.o would be placed before strings.o on the command line.

Note well that this is not an official statement from the LD manuals AFAIK but rather something I discovered through experimentation.

--All the best,
gravaera
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
FlashBurn
Member
Member
Posts: 313
Joined: Fri Oct 20, 2006 10:14 am

Re: problems with binutils 2.20

Post by FlashBurn »

@gravaera

This is not always possible and this should not be the case.

@all

I just downgraded to 2.19.1 and what should I say it works :?
Post Reply