• AVR Freaks

LockedLinker error for mismatched attributes of input and output sections

Author
dmytro
New Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2012/11/24 09:08:03
  • Location: 0
  • Status: offline
2012/11/24 09:47:17 (permalink)
0

Linker error for mismatched attributes of input and output sections

Hi,
I'm using(trying at least ...) xc-32(v1.11) for building standalone project(w/o using MPLABX). I'm using own initialization code.
I face an issue on link stage with .data section. For instance:
ld: Link Error: attributes for input section '.data.local_commands.local_commands' conflict with output section '.data'

The errors is raised for any global data object.
 
There's no such issue with normal GNU GCC toolchain(GNU GCC + LD).
 
The linker script I use:

OUTPUT_FORMAT("elf32-tradlittlemips")

OUTPUT_ARCH(pic32mx)
ENTRY(_start)
PROVIDE(__heap_end__ = 0x8001FFFF);
MEMORY
{
  kseg0_program_mem     (rx) : ORIGIN = 0x9D000000, LENGTH = 0x7FFFF
  /* kseg0_ram_mem              : ORIGIN = 0x80000000, LENGTH = 0x1FFFF */
  kseg1_data_mem       (w!x) : ORIGIN = 0xA0000000, LENGTH = 0x1FFFF
  kseg1_boot_mem        (rx) : ORIGIN = 0xBFC00000, LENGTH = 0x2FEF
  kseg0_boot_mem             : ORIGIN = 0x9D000000, LENGTH = 0x2FEF
  devcfg3                    : ORIGIN = 0xBFC02FF0, LENGTH = 0x4
  devcfg2                    : ORIGIN = 0xBFC02FF4, LENGTH = 0x4
  devcfg1                    : ORIGIN = 0xBFC02FF8, LENGTH = 0x4
  devcfg0                    : ORIGIN = 0xBFC02FFC, LENGTH = 0x4
  sfrs                       : ORIGIN = 0xBF800000, LENGTH = 0x100000
  exception_mem              : ORIGIN = 0x9D000180, LENGTH = 0x1000
}
SECTIONS
{
  .devcfg3 : {
    KEEP (*(.devcfg3))
  } > devcfg3
  .devcfg2 : {
    KEEP (*(.devcfg2))
  } > devcfg2
  .devcfg1 : {
    KEEP (*(.devcfg1))
  } > devcfg1
  .devcfg0 : {
    KEEP (*(.devcfg0))
  } > devcfg0

  .boot : {
    __init_start__ = .;
    KEEP (*(.entry*))
    __init_end__ = .;
  } > kseg1_boot_mem

  .text : {
    . = 0x180;
    ASSERT(. == 0x180, "wrong location of vectors");
    __vectors_start__ = .;
    KEEP (*(.evectors*))
    . = 0x200;
    ASSERT(. == 0x200, "wrong location of vectors");
    KEEP (*(.ivectors*))
    KEEP (*(.vectors*))
    __vectors_end__ = .;

    . = ALIGN(4);
    __text_start__ = .;
    KEEP (*(.core.entry*))
    *(.text*)
    *(.gcc*)
    *(.ctors)
    __text_end__ = .;
  } > kseg0_program_mem

  .rom_data ALIGN(4) : {
    __rom_data_start__ = .;
  } > kseg0_program_mem

  .data : AT((LOADADDR(.rom_data) + SIZEOF(.rom_data) + 31) & ~(31)) /* LMA */ {
    __ram_data_start__ = .;
    __rodata_start__ = .;
    *(.rodata*)
    __rodata_end__ = .;
    *(.data*)
    *(.sdata*)
    . = ALIGN(4);
    __ram_data_end__ = .;
  } > kseg1_data_mem

  .bss ALIGN(4) : {
    __bss_start__ = .;
    *(.bss*)
    *(.sbss*)
    *(COMMON)
    . = ALIGN(4);
    __bss_end__ = .;
  } > kseg1_data_mem

  .heap ALIGN(4) : {
    __heap_base__ = .;
  } > kseg1_data_mem

  .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
 
  /* Stabs debugging sections.  */
  .stab          0 : { *(.stab) }
  .stabstr       0 : { *(.stabstr) }
  .stab.excl     0 : { *(.stab.excl) }
  .stab.exclstr  0 : { *(.stab.exclstr) }
  .stab.index    0 : { *(.stab.index) }
  .stab.indexstr 0 : { *(.stab.indexstr) }
  .comment       0 : { *(.comment) }

  /* DWARF debug sections.
     Symbols in the DWARF debugging sections are relative to the beginning
     of the section so we begin them at 0.  */
  /* DWARF 1 */
  .debug          0 : { *(.debug) }
  .line           0 : { *(.line) }
  /* GNU DWARF 1 extensions */
  .debug_srcinfo  0 : { *(.debug_srcinfo) }
  .debug_sfnames  0 : { *(.debug_sfnames) }
  /* DWARF 1.1 and DWARF 2 */
  .debug_aranges  0 : { *(.debug_aranges) }
  .debug_pubnames 0 : { *(.debug_pubnames) }
  /* DWARF 2 */
  .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
  .debug_abbrev   0 : { *(.debug_abbrev) }
  .debug_line     0 : { *(.debug_line) }
  .debug_frame    0 : { *(.debug_frame) }
  .debug_str      0 : { *(.debug_str) }
  .debug_loc      0 : { *(.debug_loc) }
  .debug_macinfo  0 : { *(.debug_macinfo) }
  /* SGI/MIPS DWARF 2 extensions */
  .debug_weaknames 0 : { *(.debug_weaknames) }
  .debug_funcnames 0 : { *(.debug_funcnames) }
  .debug_typenames 0 : { *(.debug_typenames) }
  .debug_varnames  0 : { *(.debug_varnames) }
  .debug_pubtypes 0 : { *(.debug_pubtypes) }
  .debug_ranges   0 : { *(.debug_ranges) }

  /DISCARD/ : {
    *(.rel.dyn);
    *(.reginfo)
    *(.discard);
  }
}

 
Thanks,
-- dmytro
#1

6 Replies Related Threads

    JasonK
    Moderator
    • Total Posts : 3411
    • Reward points : 0
    • Joined: 2003/11/14 09:49:40
    • Location: Microchip Technology in Arizona, USA
    • Status: offline
    Re:Linker error for mismatched attributes of input and output sections 2012/11/27 08:58:16 (permalink)
    0
    It sounds like there is a .data section getting generated that does not have the data attribute. It may have the code. Are you using the section attribute on any variables? Is there any assembly code involved?

    Jason Kajita
     Follow me on Twitter
    http://support.microchip.com for urgent questions
    #2
    dmytro
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2012/11/24 09:08:03
    • Location: 0
    • Status: offline
    Re:Linker error for mismatched attributes of input and output sections 2012/11/28 05:19:22 (permalink)
    0
    I don't have any special attributes for data objects.
    Initially I also thought that maybe I'm using some GCC attribute that is not supported by microchip's LD, but it's not like that.
    In fact if I add any global(or static) initialized variable to the compilation unit I have this error. I can successfully finish the linking only if I don't declare any object that might go to .data.
    Note, that I don't have this issue with .rodata.
     
    thanks,
    -- dmytro
    #3
    dmytro
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2012/11/24 09:08:03
    • Location: 0
    • Status: offline
    Re:Linker error for mismatched attributes of input and output sections 2012/12/04 15:59:18 (permalink)
    0
    Hi, I've found the root cause of this linker error, however I do not understand it. Please explain why it comes out.
    Does it because the strings are stored in .rodata but referenced from .data? Still don't see any reason for fail.
    With the following code the linker fails to build an ELF:
    struct s {  
        char *n;
        int f;
    };
    #if 1 // set to 0 if you want successfully compile this piece of code
    struct s s[] = {{"a", 2}, {"g", 3}, {0, 1}};
    #else
    struct s s[] = {{0, 1}};
    #endif
    void _start(void) { }
    int main(void) {
        /* Normal main() thread activity ;) */
        return 0;
    }
    In some particular cases it helps to define global var as const but this solution is pretty fragile as the entire project is not xc32-specific and it will be hard to correct each such case. And maintain in the future.
     
    Same linker script is used as in original post.
    Makefile used to build this simple piece of code that blows up xc32-ld:
    OPT = -EL  
    OPT = -O0 -ggdb
    OPT += -mtune=4kc
    # usually gives very good i-cache hit rate
    OPT += -falign-functions=16
    OPT += -D__32MX795F512L__ -mprocessor=32MX795F512L

    COPT =
    LDOPT = -EL

    PROJECT = tst

    LDSCRIPT = mips_pic32mx795f512l.xc32.lds

    TRGT  ?= xc32-

    CC   = $(TRGT)gcc
    LD   = $(TRGT)gcc

    CWARN = -Wall -Wextra -Wstrict-prototypes

    CSRC = main.c
    ELF  = main.elf

    OPT += -ffunction-sections -fdata-sections

    OBJS      = $(CSRC:.c=.o)

    MCFLAGS   = -mips32r2 -G0 -fno-pic -fno-PIC -mno-abicalls -msoft-float -fomit-frame-pointer
    CFLAGS    = $(MCFLAGS) $(OPT) $(COPT) $(CWARN) $(DEFS)
    LDFLAGS   = $(MCFLAGS) -G0 -fno-pic -fno-PIC -static -n -nostdlib -nostartfiles $(LDOPT) -Wl,--script=$(LDSCRIPT) -Wl--cref,--no-warn-mismatch,--gc-sections $(LLIBDIR)

    .PHONY: $(ELF)

    all: $(ELF)


    $(ELF): $(OBJS) $(LDSCRIPT)
        $(LD) $(OBJS) $(LDFLAGS) -o $@

    %.o: %.c
        $(CC) -c $(CFLAGS) -I. $< -o $@

    clean:
        @-rm -f *.o *.elf

    post edited by dmytro - 2012/12/04 16:08:30
    #4
    dmytro
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2012/11/24 09:08:03
    • Location: 0
    • Status: offline
    Re:Linker error for mismatched attributes of input and output sections 2012/12/04 16:16:56 (permalink)
    0
    And the linker error:
    *~>make
    xc32-gcc -c -mips32r2 -G0 -fno-pic -fno-PIC -mno-abicalls -msoft-float -fomit-frame-pointer -O0 -ggdb -mtune=4kc -falign-functions=16 -D__32MX795F512L__ -mprocessor=32MX795F512L -ffunction-sections -fdata-sections  -Wall -Wextra -Wstrict-prototypes  -I. main.c -o main.o
    xc32-gcc main.o -mips32r2 -G0 -fno-pic -fno-PIC -mno-abicalls -msoft-float -fomit-frame-pointer -G0 -fno-pic -fno-PIC -static -n -nostdlib -nostartfiles -EL -Wl,--script=mips_pic32mx795f512l.xc32.lds -Wl--cref,--no-warn-mismatch,--gc-sections  -o main.elf
    /opt/microchip/xc32/v1.11/bin/../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/bin/ld: Link Error: attributes for input section '.data' conflict with output section '.data'
    collect2: ld returned 1 exit status
    make: *** [main.elf] Error 1
    *~>xc32-gcc --version
    xc32-gcc (Microchip Technology) 4.5.1 MPLAB XC32 Compiler v1.11 Build date: Sep 14 2012
    Copyright (C) 2010 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    #5
    JasonK
    Moderator
    • Total Posts : 3411
    • Reward points : 0
    • Joined: 2003/11/14 09:49:40
    • Location: Microchip Technology in Arizona, USA
    • Status: offline
    Re:Linker error for mismatched attributes of input and output sections 2012/12/05 09:55:52 (permalink)
    0
    Hi dmytro,
     
    I see now. The error is because .rodata input sections as well as .data input sections are mapped to the .data output section.

      .data : AT((LOADADDR(.rom_data) + SIZEOF(.rom_data) + 31) & ~(31)) /* LMA */ {
        __ram_data_start__ = .;
        __rodata_start__ = .;
        *(.rodata*)
        __rodata_end__ = .;
        *(.data*)
        *(.sdata*)
        . = ALIGN(4);
        __ram_data_end__ = .;
      } > kseg1_data_mem
    The .rodata input sections have the code space attribute on them. The .data input sections have the data space attribute on them. The linker does not allow both code and data input sections in a single output section.
     
    You can probably get around this by using the compiler's "-mno-embedded-data" option. This option will tell the compiler to put all data into a data section rather than trying to put const data into code space (.rodata).
     

    Jason Kajita
     Follow me on Twitter
    http://support.microchip.com for urgent questions
    #6
    dmytro
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2012/11/24 09:08:03
    • Location: 0
    • Status: offline
    Re:Linker error for mismatched attributes of input and output sections 2012/12/06 14:31:19 (permalink)
    0
    Hi Jason,
    thanks for your suggestion and explanation.
    "-mno-embedded-data" option didn't help but putting .rodata into the program memory worked out. At least I can get an ELF.
    I have some issues during the runtime, but that's another story.
     
    Thank you very much!
     
    cheers,
    -- dmytro
    #7
    Jump to:
    © 2020 APG vNext Commercial Version 4.5