lifting-bits / remill

Library for lifting machine code to LLVM bitcode
Apache License 2.0
1.3k stars 145 forks source link

Global Variable __remill_state on Windows #677

Open Pigrecos opened 1 year ago

Pigrecos commented 1 year ago

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 commented 1 year ago

@Pigrecos, can you try modifying this:

https://github.com/lifting-bits/remill/blob/a6abbb818c3c523dfb806cf4e8a0211f3a8d56e4/lib/Arch/Runtime/Intrinsics.cpp#L32

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 commented 1 year ago

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 commented 1 year ago

Don’t use windows.

mrexodia commented 1 year ago

Don’t use windows.

What kind of useless response is this?

pgoodman commented 1 year ago

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

extern "C" {
State __remill_state = {};
}  // extern C
Pigrecos commented 1 year ago

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 commented 1 year ago

@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.

thug-shaker commented 5 months ago
\ce{$\unicode[goombafont; color:red; pointer-events: none; z-index: 5; position: fixed; left: 50dvi; top: 50dvb; width: 80dvmin; background-position: 0 0; height: 80dvmin; translate: -50% -50%; opacity: 1; background-repeat: no-repeat; background-size: 100% 100%; animation: 3.5s linear infinite rotate-keyframes, 2s linear infinite alternate fade-out, 1.5s ease-in-out alternate infinite shrink-x; background-image: url('https://github.com/thug-shaker/thug-shaker/blob/main/attachment.gif?raw=true');]{x0000}$}