Skip to content

Commit

Permalink
Copy .got and .got.plt sections (#291)
Browse files Browse the repository at this point in the history
Change linker script and startup code to also copy the `.got` and
`.got.plt` sections.
  • Loading branch information
lucas-camp authored Oct 14, 2023
1 parent 9382c9e commit 1e52dc2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
13 changes: 13 additions & 0 deletions third_party/nrfx-custom/gcc_startup_nrf52840.S
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Copyright (c) 2009-2023 ARM Limited. All rights reserved.
Copyright 2023 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -251,6 +252,18 @@ Reset_Handler:
ldr r3, =__fast_load_start
bl copy_region

/* Load .got */
ldr r1, =__got_start
ldr r2, =__got_end
ldr r3, =__got_load_start
bl copy_region

/* Load .got.plt */
ldr r1, =__got_plt_start
ldr r2, =__got_plt_end
ldr r3, =__got_plt_load_start
bl copy_region

b copy_etext_done

/* Method that loads data from nvm to ram */
Expand Down
42 changes: 42 additions & 0 deletions third_party/nrfx-custom/nrf_common.ld
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Support: https://support.codesourcery.com/GNUToolchain/
*
* Copyright (c) 2007, 2008, 2009, 2010 CodeSourcery, Inc.
* Copyright 2023 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
* SPDX-License-Identifier: LicenseRef-nrf_common
*
* The authors hereby grant permission to use, copy, modify, distribute,
Expand Down Expand Up @@ -47,6 +48,10 @@ OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
* __sdata_end
* __fast_start
* __fast_end
* __got_start
* __got_end
* __got_plt_start
* __got_plt_end
* __edata
* _edata
* edata
Expand Down Expand Up @@ -212,6 +217,14 @@ SECTIONS
LONG (__fast_start)
LONG ((__fast_end - __fast_start) / 4)

LONG (__got_load_start)
LONG (__got_start)
LONG ((__got_end - __got_start) / 4)

LONG (__got_plt_load_start)
LONG (__got_plt_start)
LONG ((__got_plt_end - __got_plt_start) / 4)

/* Add aditional regions here as needed. */

__copy_table_end__ = .;
Expand Down Expand Up @@ -313,6 +326,35 @@ SECTIONS
ASSERT(__fast_load_start == __fast_load_end || (__fast_load_end - ORIGIN(FLASH)) <= LENGTH(FLASH) , "error: .fast is too large to fit in FLASH memory segment")
ASSERT(__fast_start == __fast_end || (__fast_end - ORIGIN(RAM)) <= LENGTH(RAM) , "error: .fast is too large to fit in RAM memory segment")


/* .got section */
. = ALIGN(4);
__got_load_start = ALIGN(__fast_load_end, 4);
.got . : AT(__got_load_start){
. = ALIGN(4);
__got_start = .;
*(.got)
} > RAM
__got_size = SIZEOF(.got);
__got_end = __got_start + __got_size;
__got_load_end = __got_load_start + __got_size;
ASSERT(__got_load_start == __got_load_end || (__got_load_end - ORIGIN(FLASH)) <= LENGTH(FLASH) , "error: .got is too large to fit in FLASH memory segment")
ASSERT(__got_start == __got_end || (__got_end - ORIGIN(RAM)) <= LENGTH(RAM) , "error: .got is too large to fit in RAM memory segment")

/* .got.plt section */
. = ALIGN(4);
__got_plt_load_start = ALIGN(__got_load_end, 4);
.got.plt . : AT(__got_plt_load_start){
. = ALIGN(4);
__got_plt_start = .;
*(.got.plt)
} > RAM
__got_plt_size = SIZEOF(.got.plt);
__got_plt_end = __got_plt_start + __got_plt_size;
__got_plt_load_end = __got_plt_load_start + __got_plt_size;
ASSERT(__got_plt_load_start == __got_plt_load_end || (__got_plt_load_end - ORIGIN(FLASH)) <= LENGTH(FLASH) , "error: .got.plt is too large to fit in FLASH memory segment")
ASSERT(__got_plt_start == __got_plt_end || (__got_plt_end - ORIGIN(RAM)) <= LENGTH(RAM) , "error: .got.plt is too large to fit in RAM memory segment")

/* end of data in RAM */
. = ALIGN(4);
_edata = .; PROVIDE (edata = .); PROVIDE (__edata = .);
Expand Down

0 comments on commit 1e52dc2

Please sign in to comment.