* mfentry and Darwin.
@ 2019-05-21 16:15 Iain Sandoe
2019-05-21 18:37 ` Uros Bizjak
0 siblings, 1 reply; 3+ messages in thread
From: Iain Sandoe @ 2019-05-21 16:15 UTC (permalink / raw)
To: Uros Bizjak; +Cc: gcc
Hi Uros,
It seems to me that (even if it was working “properly”, which it isn't) ‘-mfentry’ would break ABI on Darwin for both 32 and 64b - which require 16byte stack alignment at call sites.
For Darwin, the dynamic loader enforces the requirement when it can and will abort a program that tries to make a DSO linkage with the stack in an incorrect alignment. We previously had a bug against profiling caused by exactly this issue (but when the mcount call was in the post-prologue position).
Actually, I’m not sure why it’s not an issue for other 64b platforms that use the psABI (AFAIR, it’s only the 32b case that’s Darwin-specific).
Anyway, my current plan is to disable mfentry (for Darwin) - the alternative might be some kind of “almost at the start of the function, but needing some stack alignment change”,
I’m interested in if you know of any compelling use-cases that would make it worth finding some work-around instead of disabling.
thanks
Iain
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: mfentry and Darwin.
2019-05-21 16:15 mfentry and Darwin Iain Sandoe
@ 2019-05-21 18:37 ` Uros Bizjak
2019-05-22 11:45 ` Iain Sandoe
0 siblings, 1 reply; 3+ messages in thread
From: Uros Bizjak @ 2019-05-21 18:37 UTC (permalink / raw)
To: Iain Sandoe; +Cc: GCC Development
On Tue, May 21, 2019 at 6:15 PM Iain Sandoe <iain@sandoe.co.uk> wrote:
>
> Hi Uros,
>
> It seems to me that (even if it was working “properly”, which it isn't) ‘-mfentry’ would break ABI on Darwin for both 32 and 64b - which require 16byte stack alignment at call sites.
>
> For Darwin, the dynamic loader enforces the requirement when it can and will abort a program that tries to make a DSO linkage with the stack in an incorrect alignment. We previously had a bug against profiling caused by exactly this issue (but when the mcount call was in the post-prologue position).
>
> Actually, I’m not sure why it’s not an issue for other 64b platforms that use the psABI (AFAIR, it’s only the 32b case that’s Darwin-specific).
The __fentry__ in glibc is written as a wrapper around the call to
__mcount_internal, and is written in such a way that it compensates
stack misalignment in a call to __mcount_internal. __fentry__ survives
stack misalignment, since no xmm regs are saved to the stack in the
function.
> Anyway, my current plan is to disable mfentry (for Darwin) - the alternative might be some kind of “almost at the start of the function, but needing some stack alignment change”,
>
> I’m interested in if you know of any compelling use-cases that would make it worth finding some work-around instead of disabling.
Unfortunately, not from the top of my head...
Uros.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: mfentry and Darwin.
2019-05-21 18:37 ` Uros Bizjak
@ 2019-05-22 11:45 ` Iain Sandoe
0 siblings, 0 replies; 3+ messages in thread
From: Iain Sandoe @ 2019-05-22 11:45 UTC (permalink / raw)
To: Uros Bizjak; +Cc: GCC Development
Hi Uros,
> On 21 May 2019, at 19:36, Uros Bizjak <ubizjak@gmail.com> wrote:
>
> On Tue, May 21, 2019 at 6:15 PM Iain Sandoe <iain@sandoe.co.uk> wrote:
>>
>> It seems to me that (even if it was working “properly”, which it isn't) ‘-mfentry’ would break ABI on Darwin for both 32 and 64b - which require 16byte stack alignment at call sites.
>>
>> For Darwin, the dynamic loader enforces the requirement when it can and will abort a program that tries to make a DSO linkage with the stack in an incorrect alignment. We previously had a bug against profiling caused by exactly this issue (but when the mcount call was in the post-prologue position).
>>
>> Actually, I’m not sure why it’s not an issue for other 64b platforms that use the psABI (AFAIR, it’s only the 32b case that’s Darwin-specific).
>
> The __fentry__ in glibc is written as a wrapper around the call to
> __mcount_internal, and is written in such a way that it compensates
> stack misalignment in a call to __mcount_internal. __fentry__ survives
> stack misalignment, since no xmm regs are saved to the stack in the
> function.
Well, we can’t change Darwin’s libc to do something similar (and anyway the dynamic loader would also need to know that this was a special as well to avoid aborting the exe).
... however we could do a dodge where some shim code was inserted into any TU that used mfentry to redirect the call to an ABI-compliant launchpad… etc. etc.
It seems we can’t instrument “exactly at the entry” .. only “pretty close to it”.
>> Anyway, my current plan is to disable mfentry (for Darwin) - the alternative might be some kind of “almost at the start of the function, but needing some stack alignment change”,
>>
>> I’m interested in if you know of any compelling use-cases that would make it worth finding some work-around instead of disabling.
>
> Unfortunately, not from the top of my head…
Well, I can’t either, so for now I’m going to make a patch to disable it (since it’s not fully working in any case) .. if anyone screams that there’s a major reduction in functionality - we can investigate some scheme as mentioned above.
thanks
Iain
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-05-22 11:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-21 16:15 mfentry and Darwin Iain Sandoe
2019-05-21 18:37 ` Uros Bizjak
2019-05-22 11:45 ` Iain Sandoe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).