Skip to content

Commit

Permalink
plat: Add _base_addr symbol to represent the reference base address
Browse files Browse the repository at this point in the history
Export a linker script symbol called `_base_addr` to represent the exact
reference value used by the linker to resolve absolute references to
symbols.

Also, similarly to the other exported symbols, create a corresponding
macro, to avoid having to explicitly cast it for every reference.

Signed-off-by: Sergiu Moga <sergiu.moga@protonmail.com>
  • Loading branch information
mogasergiu committed Aug 10, 2023
1 parent 07234c0 commit 88d7d27
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions plat/common/include/uk/plat/common/sections.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
/* _dtb: start of device tree */
extern char _dtb[];

/* _base_addr: this is the base address of the unikernel image. It is set at
* link time. It is used to compute other addresses, as reference to this.
*/
extern char _base_addr[];

/* [_text, _etext]: contains .text.* sections */
extern char _text[], _etext[];

Expand Down Expand Up @@ -75,6 +80,7 @@ extern char _end[];
#define __uk_image_symbol(addr) ((unsigned long)(addr))

#define __DTB __uk_image_symbol(_dtb)
#define __BASE_ADDR __uk_image_symbol(_base_addr)
#define __TEXT __uk_image_symbol(_text)
#define __ETEXT __uk_image_symbol(_etext)
#define __EH_FRAME_START __uk_image_symbol(__eh_frame_start)
Expand Down
2 changes: 2 additions & 0 deletions plat/kvm/arm/link64.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ SECTIONS {
_start_ram_addr = .;
. = . + DTB_RESERVED_SIZE;

_base_addr = .; /* Symbol to represent the load base address */

/* Code */
_text = .;
.text :
Expand Down
2 changes: 2 additions & 0 deletions plat/kvm/x86/link64.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ SECTIONS
{
. = 0x100000;

_base_addr = .; /* Symbol to represent the load base address */

/* Code */
_text = .;
.text :
Expand Down
9 changes: 9 additions & 0 deletions plat/linuxu/arm64/entry64.S
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@

.section .text

/* For now, although inaccurate, set the
* _base_addr symbol to _liblinuxuplat_start, since that is where most images
* happen to begin anyway. We do not use it in linuxu anyway, so we do not care.
* We only do this so that references to this symbol do not generate build
* errors, although it is not used.
*/
.globl _base_addr
.set _base_addr, _liblinuxuplat_start

.global _liblinuxuplat_start
_liblinuxuplat_start:
ldr x0, [sp] // argc to r0
Expand Down
9 changes: 9 additions & 0 deletions plat/linuxu/x86/entry64.S
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@

.section .text

/* For now, although inaccurate, set the
* _base_addr symbol to _liblinuxuplat_start, since that is where most images
* happen to begin anyway. We do not use it in linuxu anyway, so we do not care.
* We only do this so that references to this symbol do not generate build
* errors, although it is not used.
*/
.globl _base_addr
.set _base_addr, _liblinuxuplat_start

.global _liblinuxuplat_start
_liblinuxuplat_start:
xorl %ebp, %ebp # mark the outmost frame (clear the frame pointer)
Expand Down
3 changes: 3 additions & 0 deletions plat/xen/arm/link32.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ SECTIONS
_boot_stack_end = 0x404000;
_page_dir = 0x404000; /* 16 KB translation table */
. = 0x408000;

_base_addr = .; /* Symbol to represent the load base address */

_text = .; /* Text and read-only data */
.text : {
*(.text.zimageboot) /* zImage boot header & code
Expand Down
3 changes: 3 additions & 0 deletions plat/xen/x86/link64.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ ENTRY(_libxenplat_start)
SECTIONS
{
. = 0x0;

_base_addr = .; /* Symbol to represent the load base address */

_text = .; /* Text and read-only data */
.text : {
*(.text.boot)
Expand Down

0 comments on commit 88d7d27

Please sign in to comment.