mkst / maspsx

MIT License
5 stars 4 forks source link

Add hacky workaround for GCC reordering INCLUDE_ASM()s #99

Closed dezgeg closed 2 weeks ago

dezgeg commented 3 weeks ago

With some versions of GCC, passing -G to it causes INCLUDE_ASM()'d functions get reordered. Add an extremely ugly hack that makes it possible to workaround that problem.

mkst commented 3 weeks ago

Is it possible to add a simple test (or couple of tests) for this?

In terms of a review, can we call it __maspsx_include_asm_hack (rather than global)

In terms of the wording:

When compiling with non-zero -G value, some versions of GCC reorder functions to appear after data definitions in the output assembly. Unfortunately, this also causes functions to be placed after __asm__ statements, thus breaking the usual implementation of the INCLUDE_ASM macro.

By using this updated INCLUDE_ASM macro, each included assembly file is wrapped in a dummy function (thus preserving ordering), and maspsx will strip out the wrapper machinery (keeping only lines containing maspsx-keep) ensuring the resulting output is as expected.

dezgeg commented 2 weeks ago

Yeah,I'll try to add some tests (and test more GCC versions as well).

I avoided adding include_asm to the macro name because I had thought it could be used more generically to implement for instance INCLUDE_RODATA() as well, but now that I think more maybe this trick can't help can't fix rodata ordering anyway...

dezgeg commented 2 weeks ago

Updated

mkst commented 2 weeks ago

Could you run black on the repo and commit the change, it's going to swap all your ' for "...

dezgeg commented 2 weeks ago

Done