bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug gold/14265] New: -gc-sections ignores KEEP annotations


From: enrico.scholz at informatik dot tu-chemnitz.de
Subject: [Bug gold/14265] New: -gc-sections ignores KEEP annotations
Date: Tue, 19 Jun 2012 08:30:57 +0000

http://sourceware.org/bugzilla/show_bug.cgi?id=14265

             Bug #: 14265
           Summary: -gc-sections ignores KEEP annotations
           Product: binutils
           Version: 2.22
            Status: NEW
          Severity: normal
          Priority: P2
         Component: gold
        AssignedTo: address@hidden
        ReportedBy: address@hidden
                CC: address@hidden
    Classification: Unclassified


sections which are marked with KEEP() in a linker file will be removed
when -gc-sections is specified.  Old bfd linker kept them as expected.

In the sample below, it is expected that:

* __foo0_start == __foo0_end   (can be optimized way)

* __foo1_start < __foo1_end

* __foo2_end - __foo2_start == __foo1_end - __foo1_start


The last two expectations hold with bfd linker but not with gold.



--- x2.ld ---
SECTIONS
{
    .text : { *(.text) }

    __foo0_start = .;
    .foo0 : { *(.foo0.*) }
    __foo0_end = .;

    __foo1_start = .;
    .foo1 : { KEEP(*(.foo1.*)) }
    __foo1_end = .;

    .foo2 : {
        __foo2_start = .;
        KEEP(*(.foo2.*))
        __foo2_end = .;
    }
}


--- x2.c ---
int foo0 __attribute__((used,section(".foo0.0")));
int foo1 __attribute__((used,section(".foo1.0")));
int foo2 __attribute__((used,section(".foo2.0")));

extern unsigned long    __foo0_start;
extern unsigned long    __foo0_end;

extern unsigned long    __foo1_start;
extern unsigned long    __foo1_end;

extern unsigned long    __foo2_start;
extern unsigned long    __foo2_end;

int main() {
    return ((__foo0_end - __foo0_start) -
        (__foo1_end - __foo1_start) -
        (__foo2_end - __foo2_start));
}


-----

$ gcc -c x2.c
$ ld.gold -gc-sections -T x2.ld x2.o -o /tmp/x2-gold
$ ld.bfd  -gc-sections -T x2.ld x2.o -o /tmp/x2-bfd

$ readelf -s /tmp/x2-bfd /tmp/x2-gold

File: /tmp/x2-bfd

Symbol table '.symtab' contains 13 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 SECTION LOCAL  DEFAULT    1 
     2: 0000000000000004     0 SECTION LOCAL  DEFAULT    2 
     3: 0000000000000000     0 SECTION LOCAL  DEFAULT    3 
     4: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS x2.c
     5: 0000000000000004     0 NOTYPE  LOCAL  DEFAULT    2 __foo2_start
     6: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  ABS __foo1_start
     7: 0000000000000008     0 NOTYPE  LOCAL  DEFAULT    2 __foo2_end
     8: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  ABS __foo0_start
     9: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  ABS __foo0_end
    10: 0000000000000004     0 NOTYPE  LOCAL  DEFAULT  ABS __foo1_end
    11: 0000000000000004     4 OBJECT  GLOBAL DEFAULT    2 foo2
    12: 0000000000000000     4 OBJECT  GLOBAL DEFAULT    1 foo1

File: /tmp/x2-gold

Symbol table '.symtab' contains 9 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS x2.c
     2: 0000000000000000    76 FUNC    GLOBAL DEFAULT    1 main
     3: 0000000000000090     0 NOTYPE  GLOBAL DEFAULT  ABS __foo0_end
     4: 0000000000000090     0 NOTYPE  GLOBAL DEFAULT  ABS __foo0_start
     5: 0000000000000090     0 NOTYPE  GLOBAL DEFAULT  ABS __foo1_start
     6: 0000000000000090     0 NOTYPE  GLOBAL DEFAULT  ABS __foo1_end
     7: 0000000000000090     0 NOTYPE  GLOBAL DEFAULT  ABS __foo2_start
     8: 00000000000000dc     0 NOTYPE  GLOBAL DEFAULT  ABS __foo2_end


$ ld.gold --version
GNU gold (version 2.22.52.0.1-10.fc17 20120131) 1.11

$ ld.bfd --version
GNU ld version 2.22.52.0.1-10.fc17 20120131

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]