Bug 12246 - BFD linker plugin generates incorrect alignments for common symbols
Summary: BFD linker plugin generates incorrect alignments for common symbols
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.22
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-20 15:07 UTC by H.J. Lu
Modified: 2011-03-10 16:26 UTC (History)
2 users (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 H.J. Lu 2010-11-20 15:07:45 UTC
On Linux/ia32, when I compile SPEC CPU 2006 is with

-O3 -mfpmath=sse -msse2 -funroll-loops -ffast-math  -fwhole-program
-flto=jobserver -fuse-linker-plugin  

using GCC configured with --with-plugin-ld=ld, using binutils as of
2010-10-20 CVS, I got

403.gcc

/usr/local/bin/ld: Warning: alignment 4 of symbol `dconst2' in
/tmp/ccAavrnI.ltrans9.ltrans.o is smaller than 16 in emit-rtl.o.ironly
/usr/local/bin/ld: Warning: alignment 4 of symbol `dconstm1' in
/tmp/ccAavrnI.ltrans9.ltrans.o is smaller than 16 in emit-rtl.o.ironly
/usr/local/bin/ld: Warning: alignment 8 of symbol `dconst1' in
/tmp/ccAavrnI.ltrans16.ltrans.o is smaller than 16 in emit-rtl.o.ironly
/usr/local/bin/ld: Warning: alignment 4 of symbol `dconst0' in
/tmp/ccAavrnI.ltrans29.ltrans.o is smaller than 16 in emit-rtl.o.ironly
/usr/local/bin/ld: Warning: alignment 4 of symbol `sizetype_tab' in
/tmp/ccAavrnI.ltrans30.ltrans.o is smaller than 16 in stor-layout.o.ironly

readelf -s emit-rtl.o | grep dconst

   498: 00000004    24 OBJECT  GLOBAL DEFAULT  COM dconst0
   499: 00000004    24 OBJECT  GLOBAL DEFAULT  COM dconst1
   500: 00000004    24 OBJECT  GLOBAL DEFAULT  COM dconst2
   501: 00000004    24 OBJECT  GLOBAL DEFAULT  COM dconstm1

The normal symbols have 4 byte alignments, but their IR-only
counter ones seem to have 16byte alignment.
Comment 1 H.J. Lu 2010-11-20 15:23:03 UTC
/* A symbol belonging to an input file managed by the plugin library.  */

struct ld_plugin_symbol
{
  char *name;
  char *version;
  int def;
  int visibility;
  uint64_t size;
  char *comdat_key;
  int resolution;
};

For ELF common symbols, we also need value which holds
the symbol alignment.  Since it is missing, BFD linker
plugin generates wrong values for ELF common symbols.
Comment 2 H.J. Lu 2010-11-20 15:39:47 UTC
Since plugin doesn't care about alignment of common symbol,
we should just use 1 byte alignment. Linker will pick the
largest one.
Comment 3 H.J. Lu 2010-11-20 15:52:07 UTC
Something like this

---
diff --git a/ld/plugin.c b/ld/plugin.c
index 79b39e8..78815da 100644
--- a/ld/plugin.c
+++ b/ld/plugin.c
@@ -292,6 +292,9 @@ asymbol_from_plugin_symbol (bfd *abfd, asymbol *asym,
       flags = BSF_GLOBAL;
       section = bfd_com_section_ptr;
       asym->value = ldsym->size;
+      /* For ELF targets, set alignment of common symbol to 1.  */
+      if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
+	((elf_symbol_type *) symbol)->internal_elf_sym.st_value = 1;
       break;
 
     default:
----
Comment 4 H.J. Lu 2010-11-20 16:09:04 UTC
A patch is posted at

http://sourceware.org/ml/binutils/2010-11/msg00371.html
Comment 5 H.J. Lu 2010-11-20 17:35:39 UTC
Fixed.
Comment 6 Dave Korn 2010-11-20 20:18:22 UTC
Thank you.
Comment 7 Dave Korn 2011-03-10 16:26:06 UTC
*** Bug 12564 has been marked as a duplicate of this bug. ***