variable attribute "used" seems to be ignored?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

variable attribute "used" seems to be ignored?

4,395件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by toddatm on Thu Oct 27 14:31:51 MST 2011
I'm moving some code from another compiler and the following constant data is eventually to be placed in ROM. The source code does not access the symbols, so it appears the compiler/linker is removing the variables. I tried adding __attribute__((used)), but the compiler/linker is still removing the data/symbols.

#define CODE_MAJOR_VERSION (0)
#define CODE_MINOR_VERSION (1)
#define BOOT_CODE_VERSION ((unsigned short)(CODE_MAJOR_VERSION<<8 | CODE_MINOR_VERSION))
#define BUILD_DATE_LEN (22) // 11 + 1 + 8 + 1(for Null) + 1 to force it on an even word boundary
#define BUILD_DATE (__DATE__ " " __TIME__)
#define BUILD_DATE_ADDR (BOOT_CODE_VERSION_ADDR - BUILD_DATE_LEN) // Null-terminated date/time stored before that
const unsigned short codeVersion __attribute__((used)) = BOOT_CODE_VERSION;
const unsigned char buildDateTime[BUILD_DATE_LEN] __attribute__((used)) = BUILD_DATE;

Any advice on how to force this data into the ROM section would be appreciated? I'd rather not do it in the linker file, because I'm using the automatically generated linker files right now. If I must, though, OK. Is it possible to mix and match auto-generated linker file and my own? Thanks.
0 件の賞賛
返信
7 返答(返信)

3,606件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by toddatm on Mon Oct 31 11:30:16 MST 2011

Quote: Zero
Did you read this:

http://knowledgebase.nxp.com/showthread.php?t=1537&langid=1

That's working fine for me :)



Thank you! Something like this worked. I put:
  . = __top_MFlash512 - 32;
  KEEP(*(.myBldIdData))

in the .text section just after the "  *(.rodata .rodata.*)" to get it at the top of ROM.

For some reason, creating my own section outside in the SECTIONS{}, did not work.

3,605件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by toddatm on Mon Oct 31 11:09:50 MST 2011
No.

Here's my main.c compilation command:
arm-none-eabi-gcc -Wa,-ahlnds=main.asm -DDEBUG -D__USE_CMSIS=CMSISv1p30_LPC17xx -D__CODE_RED -D__REDLIB__ -I"C:\Users\toddt.MARVELL\Documents\LPCXpresso_4.0.5_123\workspace\CMSISv1p30_LPC17xx\inc" -O1 -g3 -fsigned-char -c -fmessage-length=0 -fno-builtin -ffunction-sections -mcpu=cortex-m3 -mthumb -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.c"

If instead of creating a new section, I put the following into the .text section just after the KEEP(*(.isr_vector)):
KEEP(*(.myBldIdData))

Then the linker keeps the data. My goal is to put it at the top of ROM. I'll try moving now within the .text section  and see if that work. I'm probably causing some kind of linker error and the linker is silently dealing with it. Perhaps I should look through the logs or turn on more verbosity.

Thanks for the suggestions.

3,605件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by atomicdog on Fri Oct 28 19:42:41 MST 2011
Is main.c being compiled with [I]-fdata-sections[/I] ?
0 件の賞賛
返信

3,606件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Oct 28 17:45:58 MST 2011
Did you read this:

http://knowledgebase.nxp.com/showthread.php?t=1537&langid=1

That's working fine for me :)
0 件の賞賛
返信

3,606件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by toddatm on Fri Oct 28 15:51:54 MST 2011
So, I modified my linker script to have a section that looks like this after all the flash sections (I'm working with the standard linker files supplied with the LPC1768):

. = __top_MFlash512 - SIZEOF ( .myBldIdData )
.myBldIdData (NOLOAD):
{
  KEEP(*(.myBldIdData))
} > MFlash512

and in my C code I have:

const unsigned short codeVersion __attribute__ ((section(".myBldIdData"))) = BOOT_CODE_VERSION;
const unsigned char buildDateTime[BUILD_DATE_LEN] __attribute__ ((section(".myBldIdData"))) = BUILD_DATE;

The section/data show up in the assembly code of main, but the linker is discarding the section. Even after I added KEEP.

Is there a KEEP_PLEASE or KEEP_DAMNIT? :confused:

Here's my linker command:
arm-none-eabi-gcc -nostdlib -L"C:\Users\toddt.MARVELL\Documents\LPCXpresso_4.0.5_123\workspace\CMSISv1p30_LPC17xx\Debug" -Xlinker -Map=Example01.map -Xlinker --gc-sections -mcpu=cortex-m3 -mthumb -T "example01_Debug_memt.ld" -L "../bootcodelinkerscripts/" -o"Example01.axf"  ./cr_startup_lpc17.o ./main.o   -lCMSISv1p30_LPC17xx

The section .myBldIdData shows up in the discarded sections section of the map file. I suppose because it's unreferenced. I thought removing the --gc-sections command on the linker would help, but then I get tons of link errors. I'm guessing that causes some of the sections to overflow...

Is there a way to get the linker to stop throwing my constant data away even though it's unreferenced? I would have thought the KEEP would work. That's how the vectors are included. Thanks.
0 件の賞賛
返信

3,606件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by toddatm on Fri Oct 28 11:35:59 MST 2011
Seeing no replies, I guessed I had created a box for myself. Thanks. Yes. I started modifying the linker script this morning! Thanks!
0 件の賞賛
返信

3,606件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Oct 28 10:39:55 MST 2011

Quote:

If I must, though, OK.

Yes, you have to :mad:

I think you have read this already:

http://support.code-red-tech.com/CodeRedWiki/PlacingData
0 件の賞賛
返信