libffi: Fix X86 32b Darwin build and EH frames.
authorIain Sandoe <iain@sandoe.co.uk>
Sun, 18 Dec 2022 11:24:43 +0000 (11:24 +0000)
committerIain Sandoe <iain@sandoe.co.uk>
Wed, 21 Dec 2022 13:02:25 +0000 (13:02 +0000)
commit3cc159bc01516e370e8f119db70e2fbd803f3f80
tree12ede8c065bd0e04180237d2ae1289414d1899a7
parent845b514e8a150447ba041294586af76a6ac05158
libffi: Fix X86 32b Darwin build and EH frames.

This addresses a number of issues in the X86 Darwin 32b port for libffi.

1. The pic symbol stubs are weak definitions; the correct section placement
   for these depends on the linker version in use.  We do not have access
   to that information, but we can use the target OS version (assumes that
   the user has installed the latest version of xcode available).
   When a coalesced section is in use (OS versions earlier than Darwin12 /
   OSX 10.8), its name must differ from  __TEXT,__text since otherwise that
   would correspond to altering the attributes of the .text section (which
   produces a diagnostic from the assembler).
   Here we use __TEXT, __textcoal_nt for this which is what GCC emits for
   these stubs.
   For later versions than Darwin 12 (OS X 10.8) we can place the stubs in
   the .text section (if we do not we get a diagnostic from clang -cc1as
   saying that the use of coalesced sections for this is deprecated).

2. The EH frame is specified manually, since there is no support for .cfi_
   directives in 'cctools' assemblers.  The implementation needs to provide
   offsets for CFA advance, code size and to the CIE as signed values
   rather than relocations. However the cctools assembler will produce a
   relocation for expressions like ' .long Lxx-Lyy' which then leads to a
   link-time error.  We correct this by forming the offset values using
   ' .set' directives and then assigning the results of them.

3. The register numbering used by m32 X86 Darwin EH frames is not the same
   as the DWARF debug numbering (the Frame and Stack pointer numbers are
   swapped).

4. The FDE address encoding used by the system tools is '0x10' (PCrel + abs)
   where the value provided was PCrel + sdata4.

5. GCC does not use compact unwind at present, and it was not implemented
   until Darwin10 / OSX 10.6.  There were some issues with function location
   in 10.6 so that the solution here suppresses emitting the compact unwind
   section until Darwin11 / OSX 10.7.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
libffi/ChangeLog:

* src/x86/sysv.S (COMDAT): Amend section use for Darwin, accounting
cases where coalesced is needed. (eh_frame): Rework to avoid relocs
that cause builf fails on earlier Darwin.  Adjust register numbers
to account for X86 m32 Darwin differences between EH and debug.
libffi/src/x86/sysv.S