Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Clean up .ncdata/ncbss hackery in plugin linker script

The mess here can be reduced by paying careful attention to
how the linker allocates LMAs/VMAs within MEMORY regions.

Changing the way .ncdata and .ncbss are defined so that they
reserve the LMA/VMA ranges they use in PLUGIN_RAM removes the
need to explicitly set the VMAs of other sections, cutting
down on the number of ifdefs needed and making the script a
bit simpler.

Change-Id: I316fc6e8dedd621537261d52c1ec7c20ec09438a

authored by

Aidan MacDonald and committed by
Solomon Peachy
92b0bf7a bce2c4e0

+47 -25
+47 -25
apps/plugins/plugin.lds
··· 281 281 } > PLUGIN_RAM 282 282 283 283 #if NOCACHE_BASE != 0 284 - .ncdata . + NOCACHE_BASE : 284 + /* 285 + * Allocate .ncdata based on the following constraints: 286 + * 287 + * 1. the LMA must be allocated at the next free LMA in 288 + * PLUGIN_RAM and aligned to a cacheline boundary. 289 + * 2. the VMA - LMA offset must equal NOCACHE_BASE. 290 + */ 291 + .ncdata ALIGN(. + NOCACHE_BASE, CACHEALIGN_SIZE) : ALIGN(CACHEALIGN_SIZE) 285 292 { 286 - . = ALIGN(CACHEALIGN_SIZE); 287 293 *(.ncdata*) 288 294 . = ALIGN(CACHEALIGN_SIZE); 289 - /* EABI currently needs these defined here, otherwise .iram and .bss can 290 - sometimes have an incorrect load address, breaking codecs and plugins. */ 291 - bssaddr = . - NOCACHE_BASE; 292 - #if defined(IRAMSIZE) && IRAMSIZE != 0 293 - iramcopy = . - NOCACHE_BASE; 294 - #endif 295 295 } AT> PLUGIN_RAM 296 - /* This definition is used when NOCACHE_BASE is 0. The address offset bug only 297 - seems to occur when the empty .ncdata is present. */ 298 - #else 299 - bssaddr = .; 300 - #if defined(IRAMSIZE) && IRAMSIZE != 0 301 - iramcopy = .; 302 - #endif 303 296 #endif 304 297 305 298 /DISCARD/ : ··· 311 304 #endif 312 305 } 313 306 314 - .bss bssaddr (NOLOAD) : 307 + .bss (NOLOAD) : 315 308 { 316 309 plugin_bss_start = .; 317 310 _plugin_bss_start = .; ··· 324 317 } > PLUGIN_RAM 325 318 326 319 #if NOCACHE_BASE != 0 327 - .ncbss . + NOCACHE_BASE (NOLOAD) : 320 + /* 321 + * .ncbss has the same constraints as the .ncdata section 322 + * above but there is an extra complication: because it is 323 + * a NOLOAD section, unlike .ncdata it cannot consume any 324 + * VMAs or LMAs in PLUGIN_RAM itself. 325 + * 326 + * Because free VMA/LMAs in PLUGIN_RAM are unchanged, any 327 + * subsequent sections will get placed at the end of the 328 + * .bss section, overlapping .ncbss, which we don't want. 329 + * 330 + * One solution is to manually place the next sections to 331 + * account for the size of .ncbss, but a cleaner solution 332 + * is to define a dummy section (.ncbss_vma) allocated at 333 + * the same VMA as .ncbss and equal in size, and placed in 334 + * the PLUGIN_RAM region. This allocates the correct VMA 335 + * range in plugin RAM so that the next section will not 336 + * overlap .ncbss. 337 + */ 338 + .ncbss ALIGN(. + NOCACHE_BASE, CACHEALIGN_SIZE) (NOLOAD) : ALIGN(CACHEALIGN_SIZE) 328 339 { 329 - . = ALIGN(CACHEALIGN_SIZE); 330 340 *(.ncbss*) 331 341 . = ALIGN(CACHEALIGN_SIZE); 332 - /* We won't trust this one any more than with .ncdata */ 333 - pluginendaddr = . - NOCACHE_BASE; 334 342 } AT> PLUGIN_RAM 335 - #else 336 - pluginendaddr = .; 343 + 344 + .ncbss_vma (NOLOAD) : ALIGN(CACHEALIGN_SIZE) 345 + { 346 + . += SIZEOF(.ncbss); 347 + } > PLUGIN_RAM 337 348 #endif 338 349 339 350 /* Final end of plugin after IRAM setup. The plugin or codec buffer 340 351 is considered unused by the in-RAM image at this point once IRAM 341 352 is copied. */ 342 - .pluginend pluginendaddr : 353 + .pluginend (NOLOAD) : 343 354 { 344 355 _plugin_end_addr = .; 345 356 plugin_end_addr = .; 346 - } 357 + } > PLUGIN_RAM 347 358 348 359 #if defined(IRAMSIZE) && IRAMSIZE != 0 349 - .iram IRAMORIG : AT (iramcopy) 360 + .iram IRAMORIG : AT(LOADADDR(.bss)) 350 361 { 351 362 iramstart = .; 352 363 *(.icode) ··· 354 365 *(.idata) 355 366 iramend = .; 356 367 } > PLUGIN_IRAM 368 + iramcopy = LOADADDR(.iram); 357 369 358 370 .ibss (NOLOAD) : 359 371 { ··· 384 396 KEEP(*(.comment)) 385 397 } 386 398 } 399 + 400 + #if NOCACHE_BASE != 0 401 + /* Some asserts to make sure nocache sections appear correctly defined */ 402 + ASSERT(LOADADDR(.ncdata) == ADDR(.ncdata) - NOCACHE_BASE, ".ncdata has incorrect LMA/VMA address"); 403 + ASSERT(LOADADDR(.ncdata) % CACHEALIGN_SIZE == 0, ".ncdata incorrectly aligned"); 404 + ASSERT(LOADADDR(.ncbss) == ADDR(.ncbss) - NOCACHE_BASE, ".ncbss has incorrect LMA/VMA address"); 405 + ASSERT(LOADADDR(.ncbss) % CACHEALIGN_SIZE == 0, ".ncbss incorrectly aligned"); 406 + ASSERT(ADDR(.ncbss_vma) == LOADADDR(.ncbss), ".ncbss_vma has wrong address"); 407 + ASSERT(SIZEOF(.ncbss_vma) == SIZEOF(.ncbss), ".ncbss_vma has wrong size"); 408 + #endif