ellishg wrote:

> I'm not comfortable with direct calls bypassing the thunk by default. At the 
> very least it should be behind a flag. These functions get a thunk because 
> their address is significant, and that address is also where tools act on the 
> function: a breakpoint, a DTrace pid entry probe, or an inline hook patching 
> its entry. Today all of them see every call. With this change they only see 
> calls through a pointer, so the same function behaves differently depending 
> on how it's called.

I suppose breakpoints still work with `--icf=all` because both folded symbols 
point to the same address. With `--icf=safe_thunks`, the address significant 
symbol points to the thunk, and the other symbol points to the function body. 
So bypassing the thunk would break debuggers. I could guard this behind a flag, 
but I'm wondering if the benefit is worth it.

> Some of the cost described in the description comes from where the thunks are 
> placed. They're appended after every other input section, so without an order 
> file a call to a thunk-folded function first jumps to the end of __text, 
> which could be a long jump in a large binary. I have a patch that instead 
> puts each thunk where the function it replaces was in the input order. The 
> caller's jump then reaches a thunk at the original function's distance.

We have logic in BP to order ICF thunks with their bodies, but of course that 
requires an orderfile.

> I also have another patch ready that keeps fewer functions 
> address-significant. Safe ICF applies Apple ld's address-taken heuristic when 
> __llvm_addrsig is missing or marks a function. A function then stays unique 
> only if it's exported or something other than a branch references it. That 
> should noticeably reduce the number of thunks, and with them the calls this 
> PR is trying to shorten.

Yeah we do this too, but we only look at relocations in the `__text` section. 
This will miss function addresses stored in data sections, but apparently this 
isn't a problem for us. Do you do something similar? This reminds me of the 
discussion in https://github.com/llvm/llvm-project/pull/192636. 

https://github.com/llvm/llvm-project/pull/239472
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to