Forum: Compiler & IDEs section-start wird nur auf erstes .o file angewendet


von Dirk A. (tuxbow)


Lesenswert?

Hallo,
ich hab' jetzt einen halben Tag lang gegoogled und probiert, und komme 
nicht weiter:

ich habe in mehreren .c files einige Funktionen mit 
__attribute__((section(".xbootloader"))) versehen.

der GCC aufruf zum linken lautet:
1
avr-gcc fb_prot.o fb_bootloader.o msg_queue.o fb_hal.o fbrf_hal.o fbrf_prot.o rf22.o Spi.o 
2
-Wl,-Map,fb-bootloader.out.map -mmcu=atmega328p -lm  -Wl,--section-start=.xbootloader=0x1000
3
-Wl,--section-start=.text=0x7000 -o fb-bootloader.out
danach stehen die .xbootloader funktionen von fb_prot.o wie gewünscht 
auf 0x1000.
1
.xbootloader    0x00001000      0x3e0
2
 .xbootloader   0x00001000      0x3e0 fb_prot.o
3
                0x0000123a                fbprot_msg_handler
4
                0x000013c8                fbprot_Init
die funktionen aus fb_bootloader.o z.B. jedoch nicht, sie werden hinten 
an .text angehängt:
1
.xbootloader    0x00007e96      0x15c
2
 .xbootloader   0x00007e96      0x15c fb_bootloader.o
3
                0x00007e96                jumpToApplication
4
                0x00007edc                restartApplication
5
                0x00007ee0                runApplication
6
                0x00007f6a                main
wenn ich im gcc aufruf fb_bootloader.o nach vorn schiebe, ist es genau 
umgekehrt. --section-start wird also offenbar nur das erste .o file 
angewendet.
Wie bekomme ich den gcc dazu, alle .o files zu berücksichtigen?

Gruß,
tuxbow.

von Jörg W. (dl8dtl) (Moderator) Benutzerseite


Lesenswert?

--section-start bezieht sich auf eine output section.

Ich glaube, damit dein Vorhaben funktioniert, müsstest du einen
eigenen Linkerscript benutzen, der dein .xbootloader explizit als
output section anlegt.  Andernfalls sortiert der Linker das wohl
implizit hinter .text, weil er dafür keine weite Angabe im
Linkerscript hat.

Ganz genau verstehe ich die Linkerstrategie auch nicht ;), aber
mit einem expliziten Linkerscript geht's zumindest.

von Dirk A. (tuxbow)


Lesenswert?

So, ich hab's jetzt doch selbst herausgefunden:
 ich hab eine Kopie des ldscripts (in meinem Fall avr5.x) in mein 
Projektverzeichnis getan (neuer Name fb-avr5.x)und dort hinzugefügt;
1
MEMORY
2
{
3
  text   (rx)   : ORIGIN = 0, LENGTH = 128K
4
  xbootloader (rx)   : ORIGIN = 0, LENGTH = 128K    /* <--- */
5
  data   (rw!x) : ORIGIN = 0x800060, LENGTH = 0xffa0
6
  eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 64K
7
}
8
SECTIONS
9
{
10
....
11
  .xbootloader  :
12
  {
13
    *(.xbootloader*)
14
  }  > xbootloader
15
....

und dann natürlich die option

-T fb-avr5.x   ins link Kommando mitgeben.

so bekomme ich die .xbootloader sections aus allen .o files dort wo ich 
sie haben will:
1
.bootloader     0x00001000      0x53c
2
 *(.bootloader*)
3
 .bootloader    0x00001000      0x15c fb_bootloader.o
4
                0x00001000                jumpToApplication
5
                0x00001046                restartApplication
6
                0x0000104a                runApplication
7
                0x000010d4                main
8
 .bootloader    0x0000115c      0x3e0 fb_prot.o
9
                0x00001396                fbprot_msg_handler
10
                0x00001524                fbprot_Init

BINGO!

von Dirk A. (tuxbow)


Lesenswert?

Danke, Jörg. Während ich die Lösung getippt habe, ist Deine Antwort 
eingetroffen. That's life, danke für Deine Mühe.

Gruß,
Dirk.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.