Skip to contentSkip to conversation

efi_loader: helloworld.c: Explicitly use .rodata for loaded_image_guid

PATCH New Alexander Graf 3 participants 3 messages Dec 11, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi_loader: helloworld.c: Explicitly use .rodata for loaded_image_guid

Commit bbf75dd9345d0b ("efi_loader: output load options in helloworld") introduced a const variable in efi_main() called loaded_image_guid which got populated from a constant struct.

While you would usually expect a compiler to realize that this variable should really just be a global pointer to .rodata, gcc disagrees and instead puts it on the stack. Unfortunately in some implementations of gcc it does so my calling memcpy() which we do not implement in our hello world environment.

So let's explicitly move it to a global variable which in turn puts it in .rodata reliably and gets rid of the memcpy().

Fixes bbf75dd9345d0b ("efi_loader: output load options in helloworld")
---
 lib/efi_loader/helloworld.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/efi_loader/helloworld.c +2 -1
index e59c24c788..b8c147d7f2 100644
@@ -13,6 +13,8 @@
 #include <common.h>
 #include <efi_api.h>
 
+static const efi_guid_t loaded_image_guid = LOADED_IMAGE_GUID;
+
 /*
  * Entry point of the EFI application.
  *
@@ -26,7 +28,6 @@ efi_status_t EFIAPI efi_main(efi_handle_t handle,
 	struct efi_simple_text_output_protocol *con_out = systable->con_out;
 	struct efi_boot_services *boottime = systable->boottime;
 	struct efi_loaded_image *loaded_image;
-	const efi_guid_t loaded_image_guid = LOADED_IMAGE_GUID;
 	efi_status_t ret;
 
 	con_out->output_string(con_out, L"Hello, world!\n");
Signature · 1 line
2.12.3
#1 lore raw

PATCH 1/1 efi_loader: helloworld.c: Explicitly use .rodata for loaded_image_guid

Quoted 35 lines · Alexander Graf

Commit bbf75dd9345d0b ("efi_loader: output load options in helloworld") introduced a const variable in efi_main() called loaded_image_guid which got populated from a constant struct.

While you would usually expect a compiler to realize that this variable should really just be a global pointer to .rodata, gcc disagrees and instead puts it on the stack. Unfortunately in some implementations of gcc it does so my calling memcpy() which we do not implement in our hello world environment.

So let's explicitly move it to a global variable which in turn puts it in .rodata reliably and gets rid of the memcpy().

Fixes bbf75dd9345d0b ("efi_loader: output load options in helloworld")
---
  lib/efi_loader/helloworld.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
lib/efi_loader/helloworld.c +2 -0
index e59c24c788..b8c147d7f2 100644
@@ -13,6 +13,8 @@
  #include <common.h>
  #include <efi_api.h>
 
+static const efi_guid_t loaded_image_guid = LOADED_IMAGE_GUID;
+
  /*
   * Entry point of the EFI application.
   *

lib/efi_loader/helloworld.c efi_status_t EFIAPI efi_main(efi_handle_t handle, · line 33

Quoted 7 lines
lib/efi_loader/helloworld.c +0 -1
@@ -26,7 +28,6 @@ efi_status_t EFIAPI efi_main(efi_handle_t handle,
  	struct efi_simple_text_output_protocol *con_out = systable->con_out;
  	struct efi_boot_services *boottime = systable->boottime;
  	struct efi_loaded_image *loaded_image;
-	const efi_guid_t loaded_image_guid = LOADED_IMAGE_GUID;
  	efi_status_t ret;
 
  	con_out->output_string(con_out, L"Hello, world!\n");
#2 lore raw

PATCH 1/1 efi_loader: helloworld.c: Explicitly use .rodata for loaded_image_guid

In reply to Alexander Graf
Quoted 10 lines · Alexander Graf

Commit bbf75dd9345d0b ("efi_loader: output load options in helloworld") introduced a const variable in efi_main() called loaded_image_guid which got populated from a constant struct.

While you would usually expect a compiler to realize that this variable should really just be a global pointer to .rodata, gcc disagrees and instead puts it on the stack. Unfortunately in some implementations of gcc it does so my calling memcpy() which we do not implement in our hello world environment.

Quoted 6 lines

So let's explicitly move it to a global variable which in turn puts it in .rodata reliably and gets rid of the memcpy().

Fixes bbf75dd9345d0b ("efi_loader: output load options in helloworld")

Thanks Alexander!

Quoted 26 lines
---
 lib/efi_loader/helloworld.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/efi_loader/helloworld.c +2 -1
index e59c24c788..b8c147d7f2 100644
@@ -13,6 +13,8 @@
 #include <common.h>
 #include <efi_api.h>
 
+static const efi_guid_t loaded_image_guid = LOADED_IMAGE_GUID;
+
 /*
  * Entry point of the EFI application.
  *
@@ -26,7 +28,6 @@ efi_status_t EFIAPI efi_main(efi_handle_t handle,
 	struct efi_simple_text_output_protocol *con_out = systable->con_out;
 	struct efi_boot_services *boottime = systable->boottime;
 	struct efi_loaded_image *loaded_image;
-	const efi_guid_t loaded_image_guid = LOADED_IMAGE_GUID;
 	efi_status_t ret;
 
 	con_out->output_string(con_out, L"Hello, world!\n");
Signature · 1 line
Florian