This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Binutils gc-sections


Hi Alan!

Thanks, your testcase showed me the real problem.  BTW, it is usually
better to ask questions or discuss patches on public mailing lists.  See
http://www.eyrie.org/~eagle/faqs/questions.html
Ok, i see you.

* elflink.c (elf_gc_mark_dynamic_ref_symbol): Use !info-executable
to test for linking shared libs, not info->shared.
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.198
diff -u -p -r1.198 elflink.c
--- bfd/elflink.c 7 Dec 2005 14:43:53 -0000 1.198
+++ bfd/elflink.c 10 Dec 2005 03:25:48 -0000
@@ -9068,7 +9075,7 @@ elf_gc_mark_dynamic_ref_symbol (struct e
  if ((h->root.type == bfd_link_hash_defined
       || h->root.type == bfd_link_hash_defweak)
      && (h->ref_dynamic
-   || (info->shared
+   || (!info->executable
       && h->def_regular
       && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
       && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN)))

About you patch. As I show in my previous atached samples problem was on --pic-executable flag.
After you remove restriction in "elflink.c":


[code]
 if (!get_elf_backend_data (abfd)->can_gc_sections
     || info->relocatable
     || info->emitrelocations
     || info->shared

[/code]

ld begin allow it with --gc-sections key (see CMD line parser for detail).

I make other patch now and test again on my file, results followed later.
While all look like good. But please see on string where i remove "h->ref_dynamic",
with out it, "--gc-sections" not work correctly. I not sure on 100% about it, but on my test it work correctly.


[ ------- patch ------- ]
diff -u elflink.c elflink.c
--- elflink.c_ Wed Dec  7 14:43:53 2005
+++ elflink.c Sat Dec 10 20:39:27 2005
@@ -9067,11 +9067,10 @@

  if ((h->root.type == bfd_link_hash_defined
       || h->root.type == bfd_link_hash_defweak)
-      && (h->ref_dynamic
-   || (!info->executable
+      && (info->shared && !info->pie
       && h->def_regular
       && ELF_ST_VISIBILITY (h->other) != STV_INTERNAL
-       && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN)))
+       && ELF_ST_VISIBILITY (h->other) != STV_HIDDEN))
    h->root.u.def.section->flags |= SEC_KEEP;

  return TRUE;
[ ------- end patch ------- ]

[ ------- sample ------- ]
/* simple internal program function */
void exec_if() {}

/* function ptr declarated in data */
void (*fptr)() = exec_if;

/* exectable entry */
void exec_entry() { fptr(); }

/* shared lib internal function */
void lib_if() {}

/* shared lib exproted function */
__attribute__((visibility("default")))
void lib_ef() {}

/* shared lib exported data */
__attribute__((visibility("default")))
const char lib_ed[] = { "test_exp_str" };
[ ------- end sample ------- ]

[ ------- build ------- ]
arm-elf-gcc -Os -c -fvisibility=internal -ffunction-sections -fdata-sections sample.c
arm-elf-ld -s --gc-sections -shared -o sample.so sample.o
arm-elf-ld -s --gc-sections --pic-executable --entry=exec_entry -o sample sample.o
[ ------- end build ------- ]


[ ------- sample.so disasm ------- ]
.text:0000025C ; Processor : ARM
.text:0000025C ; Target assembler: Generic assembler for ARM
.text:0000025C ; Byte sex : Little endian
.text:0000025C
.text:0000025C ; ===========================================================================
.text:0000025C
.text:0000025C ; Segment type: Pure code
.text:0000025C AREA .text, CODE, READWRITE
.text:0000025C ; ORG 0x25C
.text:0000025C CODE32
.text:0000025C
.text:0000025C ; --------------- S U B R O U T I N E ---------------------------------------
.text:0000025C
.text:0000025C
.text:0000025C EXPORT lib_ef
.text:0000025C lib_ef
.text:0000025C BX LR
.text:0000025C ; End of function lib_ef
.text:0000025C
.text:0000025C ; _text ends
.text:0000025C
.rodata:00000260 ; ===========================================================================
.rodata:00000260
.rodata:00000260 ; Segment type: Pure data
.rodata:00000260 AREA .rodata, DATA, READONLY
.rodata:00000260 ; ORG 0x260
.rodata:00000260 EXPORT lib_ed
.rodata:00000260 lib_ed DCB "test_exp_str",0
.rodata:0000026D ALIGN 0x10
.rodata:0000026D ; _rodata ends
.rodata:0000026D
.got:000003C8 ; ===========================================================================
.got:000003C8
.got:000003C8 ; Segment type: Pure data
.got:000003C8 AREA .got, DATA
.got:000003C8 ; ORG 0x3C8
.got:000003C8 DCD 0x370, 0, 0
.got:000003C8 ; _got ends
.got:000003C8
abs:000003D4 ; ===========================================================================
abs:000003D4
abs:000003D4 ; Segment type: Absolute symbols
abs:000003D4 __exidx_end = 0x270
abs:000003D8 _bss_end__ = 0x3D4
abs:000003DC __bss_start__ = 0x3D4
abs:000003E0 __exidx_start = 0x270
abs:000003E4 __bss_end__ = 0x3D4
abs:000003E8 __bss_start = 0x3D4
abs:000003EC __end__ = 0x3D4
abs:000003F0 _edata = 0x3D4
abs:000003F4 _end = 0x3D4
abs:000003F8 _stack = 0x80000
abs:000003FC __data_start = 0x3D4
abs:000003FC
abs:000003FC END
[ ------- end sample.so disasm ------- ]


[ ------- sample disasm ------- ]
.text:00000288 ; Processor : ARM
.text:00000288 ; Target assembler: Generic assembler for ARM
.text:00000288 ; Byte sex : Little endian
.text:00000288
.text:00000288 ; ===========================================================================
.text:00000288
.text:00000288 ; Segment type: Pure code
.text:00000288 AREA .text, CODE, READWRITE
.text:00000288 ; ORG 0x288
.text:00000288 CODE32
.text:00000288
.text:00000288 ; --------------- S U B R O U T I N E ---------------------------------------
.text:00000288
.text:00000288
.text:00000288 nullsub_1 ; DATA XREF: start:__data_starto
.text:00000288 BX LR
.text:00000288 ; End of function nullsub_1
.text:00000288
.text:0000028C
.text:0000028C ; --------------- S U B R O U T I N E ---------------------------------------
.text:0000028C
.text:0000028C
.text:0000028C EXPORT start
.text:0000028C start
.text:0000028C
.text:0000028C var_4 = -4
.text:0000028C arg_4 = 4
.text:0000028C
.text:0000028C ; FUNCTION CHUNK AT .data:00000444 SIZE 00000004 BYTES
.text:0000028C
.text:0000028C STR LR, [SP,#var_4]!
.text:00000290 LDR R3, =__data_start
.text:00000294 MOV LR, PC
.text:00000298 LDR PC, [R3]
.text:0000029C LDR PC, [SP],#arg_4
.text:0000029C ; End of function start
.text:0000029C
.text:0000029C ; ---------------------------------------------------------------------------
.text:000002A0 off_2A0 DCD __data_start ; DATA XREF: start+4r
.text:000002A0 ; _text ends
.text:000002A0
.got:00000438 ; ===========================================================================
.got:00000438
.got:00000438 ; Segment type: Pure data
.got:00000438 AREA .got, DATA
.got:00000438 ; ORG 0x438
.got:00000438 DCD 0x3B8, 0, 0
.got:00000438 ; _got ends
.got:00000438
.data:00000444 ; ===========================================================================
.data:00000444
.data:00000444 ; Segment type: Pure data
.data:00000444 AREA .data, DATA
.data:00000444 ; ORG 0x444
.data:00000444 ; START OF FUNCTION CHUNK FOR start
.data:00000444 EXPORT __data_start
.data:00000444 __data_start DCD nullsub_1 ; CODE XREF: start+10j
.data:00000444 ; DATA XREF: .text:off_2A0o
.data:00000444 ; END OF FUNCTION CHUNK FOR start
.data:00000444 ; _data ends
.data:00000444
abs:00000448 ; ===========================================================================
abs:00000448
abs:00000448 ; Segment type: Absolute symbols
abs:00000448 __exidx_end = 0x2B5
abs:0000044C _bss_end__ = 0x448
abs:00000450 __bss_start__ = 0x448
abs:00000454 __exidx_start = 0x2B5
abs:00000458 __bss_end__ = 0x448
abs:0000045C __bss_start = 0x448
abs:00000460 __end__ = 0x448
abs:00000464 _edata = 0x448
abs:00000468 _end = 0x448
abs:0000046C _stack = 0x80000
abs:0000046C
abs:0000046C END start
[ ------- end sample disasm ------- ]


--
Regards
Ivan Petrov



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]