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
m68k: data race initializing global g_instruction_table in build_opcode_table() #1397
Comments
@emoon, i think the solution (2) is the best. |
Imho a library initializer/constructor would be cleaner but that will break backwards compat.
… On 26 Feb 2019, at 07:28, Nguyen Anh Quynh ***@***.***> wrote:
@emoon, i think the solution (2) is the best.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I would agree with @radare that a I can try to look at this during the week and hopefully today. |
m68k is a stable architecture, without any future update (?), so this is one time change, and should work well. |
Yeah I think it will be fine. |
@emoon definitely include the script that is used to generate the array. That will make future contributions easier. :-) |
@tmfink yes, that is the plan :) |
Overcomplicating the implementwtion of a library messing with threads, mutexes, locks and such when it just needs a decent api is a bad idea imho. Because the null chk in the fini call as well as the handler resolution instead of just using a pointer holding the initialized library would be other changes i would appreciate to see in the next release if you are in the mood to change the api
… On 26 Feb 2019, at 10:41, Nguyen Anh Quynh ***@***.***> wrote:
I would agree with @radare that a init function would be cleaner but (2) wouldn't break anything so I guess is what needs to be done. I guess what I need to do is to write a script that generates the table. I can include the script as an optional thing that people that changes the code may need to use. Users in general will never need to poke around in this code so having a manual step isn't the biggest issue I would say and in many cases one wouldn't need to change this anyway.
m68k is a stable architecture, without any future update (?), so this is one time change, and should work well.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Well the fix in this case won't involve any threading setup but I agree it would be nice with an init call but I will do the pre-create table approach here. |
It's important to realize with this change there will be a file with ~65535 lines of code in it. While no compilers these days will have any issues with (esp as it's data only) it will likely bump the compile times a bit. |
We may want such a large file to be #include'd instead of dropped in
directly.
…On Wed, Feb 27, 2019, 06:25 Daniel Collin ***@***.***> wrote:
It's important to realize with this change there will be a file with
~65535 lines of code in it. While no compilers these days will have any
issues with (esp as it's data only) it will likely bump the compile times a
bit.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1397 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFBYuFAa97RIxwMBiHF6CAqAiqqepM4Nks5vRmtDgaJpZM4bRb5n>
.
|
Sure it can be an include. |
That will probably hurt in the final binary size. And capstone is already quite big...
… On 27 Feb 2019, at 17:45, Daniel Collin ***@***.***> wrote:
Sure it can be an include.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Including big files is what we have been doing for x86 & other LLVM based
archs. And 64k files are nothing, no worry :-)
|
Unfortunately we have to choose between performance & size. For now, most
efforts are to make the core faster.
For X86, i have been doing many optimization on the binary size, because
people want to put Capstone inside OS kernels or so. There is no such
demand for other archs.
Of course there are other options available, such as selected build only
archs you need, or the diet mode.
|
Alright. I will implement this on Friday. Expect a PR then |
Why not add a C11 atomic flag?
|
Because we want to support all compilers?
|
It's part of standard C11 language, all platforms, and compilers can support. |
Even older compiler versions?
|
Well, maybe not. |
I can use the |
No please. You never know which compilers users are using, so better if we
dont force them.
You will not believe, but i had to use 20+ years old compiler, and i had no
choice.
|
Ouch :( ok, well I have a PR for the static table anyway. |
Other issue with using atomics:
|
To be fair having the table static has it's issue also:
Also the calling code from the outside would be identical when using atomic so that wouldn't be much of an issue. Actually the creation of the table would be faster because multiple threads would do it at the same time but that it's not really a big issue as it's only being done once. But as written above |
@emoon Can we redefine Also, while you are already modifying the file, can you eliminate the Thanks for your work! |
Sure I can fix that and thanks :) (edit: This is now fixed in the PR) |
With #1408 being merged can this be closed now? |
close, thanks! |
The global array
g_instruction_table
init inM680XDisassembler.c:build_opcode_table()
is a race condition.Declaration:
https://github.com/aquynh/capstone/blob/de952a3e5a519b4a0d0dd2ef921a755891860ca6/arch/M68K/M68KDisassembler.c#L250-L251
Initialization:
https://github.com/aquynh/capstone/blob/de952a3e5a519b4a0d0dd2ef921a755891860ca6/arch/M68K/M68KDisassembler.c#L3787-L3827
This caused problems while working on the Rust language bindings. The tests are run in parallel:
- PR: capstone-rust/capstone-rs#60
- Travis CI failure: https://travis-ci.org/capstone-rust/capstone-rs/jobs/498529801#L623
Possible solutions:
build_opcode_table()
capstone_init()
function that must be called before any other Capstone functionscs_struct
Similar past issue: #1171
The text was updated successfully, but these errors were encountered: