On Thu Jan 23 21:01:24 2025 +0000, Gabriel Ivăncescu wrote:
I think, to be correct, we should decorate **all** functions that are referred to from asm functions with the `used` attribute. This means add it to `abort_thread` too. The reason being that there's no guarantee the compiler will keep it in its actual form around. It could completely inline it and then remove it, or copy it and propagate constant arguments or whatever other optimization it can think of, and the original won't be available. I mean it's free to do with it as it wants since it thinks it's not used anywhere else. Also I think we should hide this behind a macro like `DECLSPEC_USED` for example, like we do for `DECLSPEC_HIDDEN`. @julliard thoughts?
We only need to decorate all functions that are **only** called from asm, not **every** function that's ever called from asm at all. All we are doing is ensuring that these problematic functions/objects remain available and don't get optimized out at link-time. I haven't come across a case where this wasn't enough (with `ld.bfd`).
For reference, [`dlls/wow64/syscall.c`](https://gitlab.winehq.org/wine/wine/-/blob/master/dlls/wow64/syscall.c?ref_t...) contains a similar pattern. `call_user_exception_dispatcher` has the attribute, because it's only reachable from an asm block, counting `Wow64PassExceptionToGuest` which itself is only reachable from asm.
In general, my preferred approach for working towards fully functional Wine+LTO would be to make targeted, small changes in small batches, with whatever techniques are required for each case. Given that there's no chance that LTO will be a default compiler/linker option for Wine, I don't think it's worth struggling to wrangle everything all at once. In this case, I think that these functions should have had these attributes from the start, like the WoW64 example.