2

I am trying to build an application manually using arm-none-eabi-gcc. The build goes fine but I get the following error during link time:

error: no memory region specified for loadable section `.bss'

No other errors nor warnings. Just the build's output and this error, I ended up trying back to the most basic type of linker script file that still allows me to build my app. This is the simplest/simplified linker script I can use and stil leads to the above error message:

MEMORY 
{         
    foo                   : ORIGIN = 0x50000000, LENGTH = 0xF0000000
}

SECTIONS
{
    .sram :
    {
        __sram_bss_start = .;
        *(.bss)
        *(.bss*)
        *(.text)
        __sram_bss_end = .;
    } > foo

}

That's the linker file. Nothing more, nothing less.

As you can see the .bss segment is clearly defined so it is not clear to me why the linker is complaining.

This is how I am building and linking:

...
SOURCES := source1.c
SOURCES += source2.c
...

OBJECTS := $(SOURCES:$(MYSRCDIR)/%.c=$(MYOBJDIR)/%.o)

LD_FLAGS := -nostartfiles
LD_FLAGS += -T linkerScript.ld 
LD_FLAGS += --entry=Reset_Handler 
LD_FLAGS += -Wl,-Map,"memoryMap.map"
LD_FLAGS += -mcpu=cortex-m7
LD_FLAGS += -mthumb
LD_FLAGS += -mlittle-endian
LD_FLAGS += -mfloat-abi=hard
LD_FLAGS += -mfpu=fpv5-sp-d16
LD_FLAGS += -specs=nano.specs
LD_FLAGS += -specs=nosys.specs
LD_FLAGS += -lc
LD_FLAGS += -lm
LD_FLAGS += -lgcc
LD_FLAGS += --sysroot="/usr/lib/arm-none-eabi/newlib"
#LD_FLAGS += --verbose

all: $(BIN)

$(BIN): $(OBJECTS) 
    $(CC) -o $@ $^ $(LD_FLAGS)

$(OBJDIR)/%.o : $(SRCDIR)/%.c
        @mkdir -p $(@D)
    $(CC) $(INC) $(CFLAGS) -o $@ -c $< $(DEFS)

```

Compiler & linker version:

$ arm-none-eabi-gcc -v
...
gcc version 9.2.1 20191025
$ arm-none-eabi-ld -v
GNU ld (2.34-4ubuntu1+13ubuntu1) 2.34

Did I misunderstand something here?

I expected the application to compile and link fine. I tried going through gnu's documentation to understand what I misunderstood. But no success so far.

UPDATE:

This linker file gets passed the aforementionned issue:

MEMORY 
{         
    foo                   : ORIGIN = 0x50000000, LENGTH = 0xF0000000
}


SECTIONS
{
    /* Works fine */
    .sram : { *(.text) } > foo
    .bss : { *(.bss) } > foo

    /* Does not work */
    /*
    .text : { *(.text) } > foo
    .sram : { *(.bss) } > foo
    */
}

So I presume it maybe somehow has issues with the sectionname .sram? Based on the information I could find online any sectionname can be given and this name is not dependent on any other definition/declaration/... elsewhere in the project

zupoluzu
  • 51
  • 4
  • Why do you have `__sram_bss_start/end` assigned multiple times? – Eugene Sh. Dec 08 '22 at 22:20
  • @EugeneSh. my bad. Let me edit this.., Removing this does not solve the issue though. Exactly the same error persists. – zupoluzu Dec 08 '22 at 22:22
  • Unrelated to your question, but also your `.text` is between these markers too. Really bad idea if you intend to use these to zero out `.bss` – Eugene Sh. Dec 08 '22 at 22:24
  • Which version of `gcc` are you using? – Eugene Sh. Dec 08 '22 at 22:27
  • @EugeneSh. gcc version 9.2.1 20191025 and GNU ld (2.34-4ubuntu1+13ubuntu1) 2.34, Cf my post, I reformatted it – zupoluzu Dec 08 '22 at 22:32
  • @EugeneSh. yhea I just added the .text section in there to get to the .bss error because it was saying (in this simplification) that I was missing a .text section (just like the .bss section). This obviously is a simplified representation of the issue. Understanding what causes the .bss error will help me understand what the real issue is and/or what I am misunderstanding – zupoluzu Dec 08 '22 at 22:34
  • what's stopping you from writing it properly without shortcuts? – 0___________ Dec 08 '22 at 23:02
  • Seems your MCU is a Cortex-M7, which is 32-bit. The 'foo' ORIGIN + LENGTH overflows 32-bits. Might be irrelevant, who knows. – pmacfarlane Dec 08 '22 at 23:34
  • I think .bss isn't supposed to be loadable. Show your code (minimal reproducing one), you might have placed something in .bss that does not belong there. – Eugene Sh. Dec 08 '22 at 23:53
  • @EugeneSh. the code is am example project from my IDE in which the project builds perfectly fine. I just simplified the linker file even more btw. This does not make any sense to me... – zupoluzu Dec 09 '22 at 06:09

0 Answers0