Bug 13491 - SECREL32 relocation invalid with external symbol
Summary: SECREL32 relocation invalid with external symbol
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.24
: P2 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-12 16:49 UTC by Daniel Green
Modified: 2012-01-16 08:32 UTC (History)
2 users (show)

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


Attachments
Test case for secrel32 (216 bytes, text/plain)
2011-12-12 16:49 UTC, Daniel Green
Details
Proposed changes. (367 bytes, patch)
2011-12-12 20:22 UTC, Daniel Green
Details | Diff
secrel32.s (409 bytes, text/plain)
2011-12-12 20:24 UTC, Daniel Green
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Green 2011-12-12 16:49:45 UTC
Created attachment 6102 [details]
Test case for secrel32

Attempting to use SECREL32 relocation for generating TLS offsets on Windows works perfectly if the symbol is defined in the object file it is used.

However when the symbol is defined in different object file it generates the offset against ".text".

The following lines of code appear in coff_i386_rtype_to_howto of bfd/coff-i386.c and I believe should account for that.  But it doesn't and I found it odd that h->type was used when similar tests used h->root.type.

if (h && (h->type == bfd_link_hash_defined
    || h->type == bfd_link_hash_defweak))
        osect_vma = h->root.u.def.section->output_section->vma;

After changing from h->type to h->root.type the problem went away.
Comment 1 Daniel Green 2011-12-12 20:22:57 UTC
Created attachment 6103 [details]
Proposed changes.
Comment 2 Daniel Green 2011-12-12 20:24:51 UTC
Created attachment 6104 [details]
secrel32.s

Included wrong assembly file.
Comment 3 Sourceware Commits 2012-01-16 08:30:31 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	amodra@sourceware.org	2012-01-16 08:30:20

Modified files:
	bfd            : ChangeLog coff-i386.c coff-x86_64.c 

Log message:
	PR ld/13491
	* coff-i386.c (coff_i386_rtype_to_howto <R_SECREL32>): Test
	h->root.type not h->type.
	* coff-x86_64.c (coff_amd64_rtype_to_howto <R_AMD64_SECREL>): Likewise.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.5587&r2=1.5588
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/coff-i386.c.diff?cvsroot=src&r1=1.35&r2=1.36
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/coff-x86_64.c.diff?cvsroot=src&r1=1.14&r2=1.15
Comment 4 Alan Modra 2012-01-16 08:32:52 UTC
patch applied