Bug 13720 - Ld 2.22 computes wrong symbol values
Summary: Ld 2.22 computes wrong symbol values
Status: RESOLVED OBSOLETE
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.22
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-21 13:29 UTC by Matthieu Lemerre
Modified: 2022-07-29 02:54 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthieu Lemerre 2012-02-21 13:29:11 UTC
Hello,

ld version 2.22 gives wrong symbol values for some symbols.

To be precise, it seems to compute the right value for the symbol, but
uses a bad value when the symbol is used.

Here are some  relevant parts of the map file:

# Here, the value for iSegCode0 is correctly computed
0x0000000000000008                iSegCode0 = (ABSOLUTE (.) - ABSOLUTE (tabGDT))

# Later, the value is not used correctly
0x0000000000117002        0x2 SHORT 0x113008 iSegCode0

# With ld version 2.20, the correct value is used:
0x0000000000117002        0x2 SHORT 0x8 iSegCode0


For another symbol, I have:
0x0000000000000020                offset_master_PIC = ((ABSOLUTE (.) - ABSOLUTE (tabIDT)) >> 0x3)

And if I link an assembly file that uses this symbol 
(it does a movb $offset_master_PIC, %al), I get this error: 

(.text+0x7): relocation truncated to fit: R_386_8 against symbol

If I change my assembly file to do (movw $offset_master_PIC, %eax)
instead and use objdump, I can see that offset_master_PIC has a
completely wrong value (which explains the truncation error).

Somehow it seems that the value of the symbol gets overwritten. We
tried using valgrind to see if it was a simple memory error without
success.

We can reproduce the error in the complete projet; when trying to
create a simpler case, we did not manage to reproduce the error. We
tried to simplify our linker script, but with simple modifications
(e.g. changing the order of sections) the error did not occur.

The error already appeared with ld version 21.51.
Comment 1 Alan Modra 2012-02-21 22:33:38 UTC
> iSegCode0 = (ABSOLUTE (.) - ABSOLUTE (tabGDT))
> offset_master_PIC = ((ABSOLUTE (.) - ABSOLUTE (tabIDT)) >> 0x3)

Did the above expressions occur inside output section statements in your linker script?  If so, your symbols iSegCode0 and offset_master_PIC will be section relative since the right hand side of these expressions evaluate to a number.  (See ld.info node "Expression Section".)  When you use these symbols in relocations, they will have the output section address added to their (offset) value.
Comment 2 Alan Modra 2012-02-22 02:09:37 UTC
BTW, ld script expression rules changed between 2.20 and 2.21 so this would explain your problem completely.  The old "rules" were so inconsistent that it was almost impossible to describe how ld evaluated script expressions.
Comment 3 Alan Modra 2022-07-29 02:54:27 UTC
No reply to questions.  Assuming linker scripts modified to suit new ld evaluation.