Bug 13597 - Broken sysv-style hash table when --hash-style=both
Summary: Broken sysv-style hash table when --hash-style=both
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Cary Coutant
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-16 09:33 UTC by Kito Cheng
Modified: 2014-09-30 21:46 UTC (History)
4 users (show)

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


Attachments
Verify tools (44.83 KB, application/x-bzip)
2012-01-16 09:33 UTC, Kito Cheng
Details
Reorder the output order between .gnu.hash and .hash (611 bytes, patch)
2012-01-17 20:39 UTC, Kito Cheng
Details | Diff
Reorder the output order between .gnu.hash and .hash v2 (909 bytes, patch)
2012-01-18 08:41 UTC, Kito Cheng
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kito Cheng 2012-01-16 09:33:46 UTC
Created attachment 6159 [details]
Verify tools

The gold linker would generate broken sysv-style hash table when --hash-style=both

attach is our verify tools, it's include pre-build so file, link by ld.gold and ld.bfd. and the verify tool are only support 32-bit only now.


Tool usage
# ./elf-verify-hash libtest.bfd.so
verify '_edata'...pass
verify 'f'...pass
verify '_end'...pass
verify '__bss_start'...pass
verify '_init'...pass
verify '_fini'...pass
                 ^^^^
# pass mean the lookup result of gnu-style & sysv hash are same

# ./elf-verify-hash libtest.gold.so
verify 'f'...SysV-style: 0 GNU-style: 4
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
# if lookup result are different, the tool will print the lookup result
verify '_edata'...pass
verify '_end'...SysV-style: 0 GNU-style: 6
verify '_init'...pass
verify '__bss_start'...pass
verify '_fini'...pass
Comment 1 Kito Cheng 2012-01-16 12:47:14 UTC
Generate by gold --hash-style=sysv
SysV Hash table header
  nbuckets : 3
  buckets : 0x1216dc8
  chains : 0x1216dd4
    buckets 0 : 
       sym : _edata
       sym : f
       sym : _Jv_RegisterClasses
       sym : _init
       sym : __gmon_start__
       sym : 
    buckets 1 : 
       sym : _end
       sym : _fini
       sym : 
    buckets 2 : 
       sym : __bss_start
       sym : __cxa_finalize
       sym : 

Generate by gold --hash-style=both
SysV Hash table header
  nbuckets : 3
  buckets : 0xf2eea8
  chains : 0xf2eeb4
    buckets 0 : 
       sym : _init
       sym : _end
       sym : _edata
       sym : __cxa_finalize
       sym : __gmon_start__
       sym : 
    buckets 1 : 
       sym : _fini
       sym : _Jv_RegisterClasses
       sym : 
    buckets 2 : 
       sym : __bss_start
       sym : f
       sym :
Comment 2 Kito Cheng 2012-01-16 12:54:08 UTC
Hey, it's seem the string table are rearranged after sysv-hash table generated.

Generate by gold --hash-style=sysv
SysV Hash table header
  nbuckets : 3
  buckets : 0x5a6dc8
  chains : 0x5a6dd4
    buckets 0 : 
       sym : _edata (7)
                    ^^^ index
       sym : f (6)
       sym : _Jv_RegisterClasses (5)
       sym : _init (2)
       sym : __gmon_start__ (1)
       sym :  (0)
    buckets 1 : 
       sym : _end (9)
       sym : _fini (3)
       sym :  (0)
    buckets 2 : 
       sym : __bss_start (8)
       sym : __cxa_finalize (4)
       sym :  (0)

Generate by gold --hash-style=both
SysV Hash table header
  nbuckets : 3
  buckets : 0x643ea8
  chains : 0x643eb4
    buckets 0 : 
       sym : _init (7)
       sym : _end (6)
       sym : _edata (5)
       sym : __cxa_finalize (2)
       sym : __gmon_start__ (1)
       sym :  (0)
    buckets 1 : 
       sym : _fini (9)
       sym : _Jv_RegisterClasses (3)
       sym :  (0)
    buckets 2 : 
       sym : __bss_start (8)
       sym : f (4)
       sym :  (0)
Comment 3 Kito Cheng 2012-01-17 20:39:01 UTC
Created attachment 6161 [details]
Reorder the output order between .gnu.hash and .hash

The root cause seem the gold::Dynobj::create_gnu_hash_table will
change the dynsym_index,

so this patch just reorder the symbol table generate order to
guarantee the gold::Dynobj::create_elf_hash_table get correct
dynsym_index.

However it's will change the section order between .hash and
.gnu.hash, any suggestion ?
Comment 4 Cary Coutant 2012-01-17 21:26:14 UTC
I don't know of any reason why the section order would matter. Generating the .gnu.hash first sounds like the best fix to me. I'd suggest adding a comment that explains why the order matters, though.

-cary
Comment 5 Kito Cheng 2012-01-18 08:41:02 UTC
Created attachment 6162 [details]
Reorder the output order between .gnu.hash and .hash v2

Add comment above creating hash table

Create GNU-sytle hash table first since string table index will 
change during creating GNU-sytle hash table. It's will break 
the SysV-sytle hash table since SysV-style hash table contain
out-of-date string table index.
Comment 6 Mike Hommey 2014-09-30 09:33:51 UTC
I just hit this bug today. What's holding it being fixed?
Comment 7 Sourceware Commits 2014-09-30 21:37:44 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".

The branch, master has been updated
       via  cd6da0366dc6684d32f349b729b5558258fc3af4 (commit)
      from  d83ad864a285fe3127e1a98830197e8461ad2745 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cd6da0366dc6684d32f349b729b5558258fc3af4

commit cd6da0366dc6684d32f349b729b5558258fc3af4
Author: Kito Cheng <kito@0xlab.org>
Date:   Tue Sep 30 14:36:46 2014 -0700

    Fix SysV-style hash table when --hash-style=both.
    
    When --hash-style-both is used, gold currently builds the sysv hash
    table first, then the gnu hash table. Building the gnu hash table
    renumbers the dynamic symbol table, invalidating the sysv hash
    table. This patch reverses the order in which the hash tables are
    build so that both hash tables are correct.
    
    gold/
    	PR gold/13597
    	* layout.cc (Layout::create_dynamic_symtab): Build gnu-style
    	hash table before sysv-style hash table.

-----------------------------------------------------------------------

Summary of changes:
 gold/ChangeLog |    6 ++++++
 gold/layout.cc |   42 ++++++++++++++++++++++--------------------
 2 files changed, 28 insertions(+), 20 deletions(-)
Comment 8 Cary Coutant 2014-09-30 21:46:13 UTC
Sorry, I thought the proposed patch had already been applied.