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

Global Variable __remill_state on Windows #677

Open
Pigrecos opened this issue Jul 18, 2023 · 7 comments
Open

Global Variable __remill_state on Windows #677

Pigrecos opened this issue Jul 18, 2023 · 7 comments

Comments

@Pigrecos
Copy link

I compiled on windows using LLVM ver. 16.0.4 the amd64 semantics files (for example) with these changes to the BCCompiler.cmake file:

set(DEFAULT_BC_COMPILER_FLAGS
   -emit-llvm -Wno-unknown-warning-option -Wall -Wshadow
   -Wconversion -Wpadded -pedantic -Wshorten-64-to-32 -Wgnu-alignof-expression
   -Wno-gnu-anonymous-struct -Wno-return-type-c-linkage
   -Wno-gnu-zero-variadic-macro-arguments -Wno-nested-anon-types
   -Wno-extended-offsetof -Wno-gnu-statement-expression -Wno-c99-extensions
   -Wno-ignored-attributes -fno-vectorize -fno-slp-vectorize
   -Wno-variadic-macros -Wno-c11-extensions -Wno-c++11-extensions
   -ffreestanding -fno-common -fno-builtin -fno-rtti
   -fno-asynchronous-unwind-tables -Wno-unneeded-internal-declaration
   -Wno-unused-function -Wgnu-inline-cpp-without-extern -fms-extensions
   -Wno-pass-failed=transform-warning -fshort-wchar -Xclang -mlong-double-80
   ${EXTRA_BC_SYSROOT}
)

the result for the global variable __remill_state is:

@"?__remill_state@@3UState@@A" = dso_local global %struct.State zeroinitializer, align 16

instead of (compiled under ubuntu):

@__remill_state = dso_local global %struct.State zeroinitializer, align 16

apply the decoration to the name.

Of course it can't find the variable:

const auto *state_global = module->getGlobalVariable("__remill_state");

Thank you

@pgoodman
Copy link
Collaborator

@Pigrecos, can you try modifying this:

extern State __remill_state;

to be something like:

extern "C" {
extern State __remill_state;
}  // extern C

And then do similar wrapping of the extern "C" around the definitions of __remill_state in the various lib/Arch/*/Runtime/Instructions.cpp?

@Pigrecos
Copy link
Author

I changed the definition to both

remill/lib/Arch/Runtime/Intrinsics.cpp

that in

lib/Arch/*/Runtime/Instructions.cpp

but the optimization is applied and it becomes:

@__remill_state = external dso_local global %struct.State, align 1

@hxm-cpp
Copy link

hxm-cpp commented Jul 19, 2023

Don’t use windows.

@mrexodia
Copy link
Contributor

Don’t use windows.

What kind of useless response is this?

@pgoodman
Copy link
Collaborator

pgoodman commented Jul 19, 2023

@Pigrecos at the definition sites, can you try doing:

extern "C" {
State __remill_state = {};
}  // extern C

@Pigrecos
Copy link
Author

at the definition sites, can you try doing:

Yes work ;)
Intrinsics.cpp

extern "C" {
extern State __remill_state ;
}  // extern C

lib/Arch/*/Runtime/Instructions.cpp

extern "C" {
extern State __remill_state = {};
}  // extern C

Result :

@__remill_state = dso_local global %struct.State zeroinitializer, align 16

@pgoodman
Copy link
Collaborator

@Pigrecos can you submit a PR, and if the changes that you made to DEFAULT_BC_COMPILER_FLAGS are generic, then please include those too.

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

4 participants