[Bug ld/15839] New: avr-ld -r removes sections created with avr-gcc -ffunction-sections -fdata-sections

2013-08-14 Thread asmtwiddler at gmail dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=15839

Bug ID: 15839
   Summary: avr-ld -r removes sections created with avr-gcc
-ffunction-sections -fdata-sections
   Product: binutils
   Version: 2.23
Status: NEW
  Severity: normal
  Priority: P2
 Component: ld
  Assignee: unassigned at sourceware dot org
  Reporter: asmtwiddler at gmail dot com

Currently avr-ld -r merges sections created with avr-gcc -ffunction-sections
-fdata-sections back into the .text and .data sections.
This is problematic as it prevents --gc-sections from removing unused
functions.

Example:

long func1(long val) {
return val - 1;
}

long func2(long val) {
return val + 1;
}

I compiled with avr-gcc -ffunction-sections -fdata-sections -c
I also used -O2 -mmcu=atmega328 -Wall but that shouldn't matter.

Then I ran avr-ld -r on the created object file to create a new object file.

Using avr-objdump -h gave me, for the initial object file:
Idx Name  Size  VMA   LMA   File off  Algn
  0 .text       0034  2**0
  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data       0034  2**0
  CONTENTS, ALLOC, LOAD, DATA
  2 .bss        0034  2**0
  ALLOC
  3 .text.func1   000a      0034  2**0
  CONTENTS, ALLOC, LOAD, READONLY, CODE
  4 .text.func2   000a      003e  2**0
  CONTENTS, ALLOC, LOAD, READONLY, CODE
  5 .comment  002a      0048  2**0
  CONTENTS, READONLY

And for the second (relocated) object file:
Idx Name  Size  VMA   LMA   File off  Algn
  0 .text 0014      0034  2**1
  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data       0048  2**0
  CONTENTS, ALLOC, LOAD, DATA
  2 .bss        0048  2**0
  ALLOC
  3 .comment  002a      0048  2**0
  CONTENTS, READONLY

Thanks for any help.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/15839] avr-ld -r removes sections created with avr-gcc -ffunction-sections -fdata-sections

2013-08-22 Thread asmtwiddler at gmail dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=15839

--- Comment #2 from asmtwiddler at gmail dot com ---
(In reply to Nick Clifton from comment #1)
> Created attachment 7160 [details]
> Update AVR linker script to only merge text and data sections during a final
> link
> 
> Hi amstwiddler,
> 
>   Please could you try out the uploaded patch and let me know if it works
> for you.
> 
>   The problem is the AVR linker script which is merging the text sections
> created by -ffunction-sections into a single .text section, even when
> creating a relocatable object file.
> 
> Cheers
>   Nick

Thanks for the fast response.

I tried the patch and it's working correctly.
Now objdump -h shows that the sections have been relocated.
Also ld --gc-sections properly removes unused sections.

This works correctly with functions and data, but doesn't work with progmem
data.
I'm not sure whether or not this is intended (as progmem is a special section)
but the code below isn't relocated properly:
#include 
const PROGMEM int table [] = {
8,7,6,5,4,3,2,1
};

Initial objdump:
Idx Name  Size  VMA   LMA   File off  Algn
  0 .text       0034  2**0
  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data       0034  2**0
  CONTENTS, ALLOC, LOAD, DATA
  2 .bss        0034  2**0
  ALLOC
  3 .progmem.data.table 0010      0034  2**0
  CONTENTS, ALLOC, LOAD, READONLY, DATA
  4 .comment  002a      0044  2**0
  CONTENTS, READONLY

Relocated objdump:
Idx Name  Size  VMA   LMA   File off  Algn
  0 .text 0010      0034  2**1
  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data       0044  2**0
  CONTENTS, ALLOC, LOAD, DATA
  2 .bss        0044  2**0
  ALLOC
  3 .comment  002a      0044  2**0
  CONTENTS, READONLY

I was able to fix this by changing
*(.progmem*)
to
${RELOCATING+ *(.progmem*)}
but I'm not sure if this is right.

Other than the "progmem" issue, I believe this is fixed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils