Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while building stubs.cpp: a reinterpret_cast is not a constant expression #11

Open
gcoimbra opened this issue Jul 21, 2020 · 6 comments

Comments

@gcoimbra
Copy link

G++ version is g++ (Ubuntu 9.3.0-10ubuntu2) 9.3.0

g++ -I/usr/include/efi -I/usr/include/efi/x86_64 -I. -DGNU_EFI_USE_MS_ABI -g -std=c++11 -c stubs.cpp -o stubs.o
In file included from stubs.cpp:33:
main.h: In member function ‘constexpr std::size_t std::hash<EFI_GUID>::operator()(const EFI_GUID&) const’:
main.h:32:29: error: a reinterpret_cast is not a constant expression
   32 |    return ((UINT64*)&s)[0]^((UINT64*)&s)[1];
      |                            ~^~~~~~~~~~~~
stubs.cpp: In function ‘EFI_STATUS OutputString(SIMPLE_TEXT_OUTPUT_INTERFACE*, CHAR16*)’:
stubs.cpp:189:1: warning: no return statement in function returning non-void [-Wreturn-type]
  189 | }
      | ^
stubs.cpp: In function ‘EFI_STATUS GetVariable(CHAR16*, EFI_GUID*, UINT32*, UINTN*, void*)’:
stubs.cpp:214:1: warning: control reaches end of non-void function [-Wreturn-type]
  214 | }
      | ^

@kocoman2
Copy link

any updates?

@jethrogb
Copy link
Owner

PRs welcome

@kocoman2
Copy link

I was able to fix it with using older g++-6
but there is another error

efihooks.cpp:110:3: error: conflicting declaration ‘typedef struct EFI_DEVICE_PATH_PROTOCOL EFI_DEVICE_PATH_PROTOCOL’

} EFI_DEVICE_PATH_PROTOCOL;
^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/efi/efi.h:61:0,
from main.h:23,
from efihooks.cpp:45:
/usr/include/efi/efidevp.h:30:3: note: previous declaration as ‘typedef struct _EFI_DEVICE_PATH_PROTOCOL EFI_DEVICE_PATH_PROTOCOL’
} EFI_DEVICE_PATH_PROTOCOL;
^~~~~~~~~~~~~~~~~~~~~~~~
efihooks.cpp:126:3: error: conflicting declaration ‘typedef struct EFI_LOADED_IMAGE_PROTOCOL EFI_LOADED_IMAGE_PROTOCOL’
} EFI_LOADED_IMAGE_PROTOCOL;
^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/efi/efi.h:63:0,
from main.h:23,
from efihooks.cpp:45:
/usr/include/efi/efiprot.h:1248:3: note: previous declaration as ‘typedef struct EFI_LOADED_IMAGE_PROTOCOL EFI_LOADED_IMAGE_PROTOCOL’
} EFI_LOADED_IMAGE_PROTOCOL;
^~~~~~~~~~~~~~~~~~~~~~~~~
make: *** [Makefile:25: efihooks.o] Error 1

@KMalum
Copy link

KMalum commented Dec 19, 2022

Install gnu-efi-3.0.3 sudo make install
change /usr/include/efi to /usr/local/include/efi and /usr/include/efi/x86_64 to /usr/local/include/efi/x86_64 in Makefile
Add #include <stdint.h> to main.h
make

@Ristovski
Copy link

This patch allowed me to build efiperun:

diff --git i/efiperun/efihooks.cpp w/efiperun/efihooks.cpp
index 600f409..941c9a2 100644
--- i/efiperun/efihooks.cpp
+++ w/efiperun/efihooks.cpp
@@ -103,27 +103,27 @@ typedef struct _EFI_ACPI_SUPPORT_PROTOCOL {
 	void* PublishTables;
 } EFI_ACPI_SUPPORT_PROTOCOL; 
 
-typedef struct __attribute__((packed)) {
-	UINT8 Type;
-	UINT8 SubType;
-	UINT8 Length[2];
-} EFI_DEVICE_PATH_PROTOCOL;
-
-typedef struct {
-	UINT32                   Revision;
-	EFI_HANDLE               ParentHandle;
-	EFI_SYSTEM_TABLE         *SystemTable;
-	EFI_HANDLE               DeviceHandle;
-	EFI_DEVICE_PATH_PROTOCOL *FilePath;
-	VOID                     *Reserved;
-	UINT32                   LoadOptionsSize;
-	VOID                     *LoadOptions;
-	VOID                     *ImageBase;
-	UINT64                   ImageSize;
-	EFI_MEMORY_TYPE          ImageCodeType;
-	EFI_MEMORY_TYPE          ImageDataType;
-	VOID*                    Unload;
-} EFI_LOADED_IMAGE_PROTOCOL;
+// typedef struct __attribute__((packed)) {
+// 	UINT8 Type;
+// 	UINT8 SubType;
+// 	UINT8 Length[2];
+// } EFI_DEVICE_PATH_PROTOCOL;
+
+// typedef struct {
+// 	UINT32                   Revision;
+// 	EFI_HANDLE               ParentHandle;
+// 	EFI_SYSTEM_TABLE         *SystemTable;
+// 	EFI_HANDLE               DeviceHandle;
+// 	EFI_DEVICE_PATH_PROTOCOL *FilePath;
+// 	VOID                     *Reserved;
+// 	UINT32                   LoadOptionsSize;
+// 	VOID                     *LoadOptions;
+// 	VOID                     *ImageBase;
+// 	UINT64                   ImageSize;
+// 	EFI_MEMORY_TYPE          ImageCodeType;
+// 	EFI_MEMORY_TYPE          ImageDataType;
+// 	VOID*                    Unload;
+// } EFI_LOADED_IMAGE_PROTOCOL;
 
 typedef struct {
 	void* data;
diff --git i/efiperun/main.h w/efiperun/main.h
index b0304bb..8fbdce9 100644
--- i/efiperun/main.h
+++ w/efiperun/main.h
@@ -27,7 +27,7 @@ namespace std
 {
 	template<> struct hash<EFI_GUID>
 	{
-		constexpr size_t operator()(EFI_GUID const& s) const
+		size_t operator()(EFI_GUID const& s) const
 		{
 			return ((UINT64*)&s)[0]^((UINT64*)&s)[1];
 		}

@shuheque
Copy link

I can also build same way to @Ristovski

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants