I haven't had a chance to actually set up and build a stand-alone project, like I plan to do, to thoroughly test this, but does adding NOLOAD
, as follows, work?
SECTIONS
{
.my_block (NOLOAD) :
{
KEEP(*(.UserDataSector));
} >USER_DATA_FLASH
}
Here's some notes I took in the v2.32 ld PDF user manual for "NOLOAD":

This seems to be what you might need.
Also, I usually place the attribute specifier after the variable, as is shown in many official gcc examples (such as the ones under "section" here), although I'm not sure that's strictly required (see official syntax documentation here).
ie:
static my_type my_array_name[] __attribute__((section(".UserDataSector"))) =
{
// member 1,
// member 2,
// member 3,
// etc
};
Also, your formatting (spaces, alignment, indentation, etc) in your question isn't very good, I must say, and along these lines of not paying close attention to detail, I see in your section attribute you have an extra space at the end: ".UserDataSector "
instead of ".UserDataSector"
, like it should be, so that might be the issue too.
Also, a few more notes:
- Note you should clean up your formatting, indentation, etc, a bit to make code in your question easier to read.
- I don't think
KEEP
is necessary here, but it doesn't hurt anything either I don't think.
You should study and read the official GNU Linker Script (LD) manual. It is available online in html format, here: https://sourceware.org/binutils/docs/ld/. the latest version is v2.32.
- However, I think it's much easier to study in a PDF so you can type into it, highlight it, mark it up, search it all at once, etc. Build the LD pdf user manual, then use Foxit Reader (cross-platform, and no-cost) to study and mark up the manual.
- How to build the Linker Script (LD) PDF user manual:
- Download the source code: https://www.gnu.org/software/binutils/
- Ex: get the latest binutils version (currently binutils-2.32.tar.xz) here: https://ftp.gnu.org/gnu/binutils/
- Extract it (right-click and go to "Extract Here" in Linux Ubuntu, for instance).
- cd into the folder:
cd binutils-2.32
Then configure and make:
./configure
make
make pdf
Done! Here are the PDFs now (found with find | grep '\.pdf'
):
binutils-2.32/libiberty/libiberty.pdf
binutils-2.32/bfd/doc/bfd.pdf
binutils-2.32/ld/ld.pdf <----- THE MAIN ONE I WANT!
binutils-2.32/gprof/gprof.pdf
binutils-2.32/gas/doc/as.pdf
binutils-2.32/binutils/doc/binutils.pdf
Save and use ld.pdf, which is now the PDF version of the HTML 2.32 binutils manual I linked to above.
- You may need to read your startup file to see if it's doing anything weird.
Like I said, I'd like to fully test this answer before posting this, but don't have the chance right now. I've spent many many hours in linker scripts over the last few weeks though, so with some of it fresh in my mind I thought this would help.
Other Linker Script questions of note
- Is accessing the "value" of a linker script variable undefined behavior in C?
- How to get value of variable defined in ld linker script from C