Skip to content

gas64: darwin-x86_64: Mach-O assembly for the assembler of clang - #510

Open
XusinboyBekchanov wants to merge 1 commit into
freebasic:masterfrom
XusinboyBekchanov:gas64-darwin-macho
Open

XusinboyBekchanov wants to merge 1 commit into
freebasic:masterfrom
XusinboyBekchanov:gas64-darwin-macho

Conversation

@XusinboyBekchanov

Copy link
Copy Markdown
Contributor

gas64 for darwin-x86_64: the assembly is written for the assembler of clang (Mach-O). On upstream master -gen gas64 on macOS fails at the first line (.section .text: "unexpected token in '.section' directive").

  • sections of Mach-O: .text, .data, __DATA,... for the others; __mod_init_func/__mod_term_func for the constructors/destructors (Mach-O has no priorities, they run in the order of the modules)
  • .balign, power-of-two alignment of .comm/.lcomm, the underscore prefix of the C functions, no @PLT
  • the System V ABI like linux: UDT results in registers
  • 8/16-bit arguments are extended to 32 bits by the caller (clang's callees expect it)
  • inline asm [var] and offset sym[rip] written so that clang accepts them
  • extern variables are accessed through the GOT: Mach-O has no copy relocations, and ld rejects a RIP-relative access to a variable of a dylib ("invalid use of rip-relative addressing", e.g. __stdoutp of libSystem). The lines are rewritten at the end of each proc (after the peephole optimizer), only on darwin
  • the internal symbols $mxcsr, $sse41 and $sse41_test are named fb_gas64_mxcsr, fb_gas64_sse41 and fb_gas64_sse41_test ($ starts an immediate value for the assembler of clang)
  • -gen gas64 keeps the intel syntax on darwin

New test: tests/crt/darwin-extern-data.bas (darwin only) loads __stdoutp/__stderrp of libSystem, takes their address and passes them to fileno().

Tested on macOS 14.8 (x86_64, Xcode 16 clang), together with #507 and #508 (without them the rtlib does not build and programs don't link on current macOS):

  • a hello world builds and runs with -gen gas64
  • unit tests with -gen gas64: 1154499 of 1154503 asserts pass, including the new test. The same 4 asserts fail with -gen gcc too, so they are not about gas64: 2 in optimizations/consteval.bas (acos( -1.0f ) of SINGLE) and 2 in file/input.bas (wstringOverflowInput)
  • gfxlib2 has no fb_hGL_GetProcAddress on darwin without XQuartz, so for the unit tests I linked a stub that returns NULL (see fbc: darwin: link with the SDK of macOS, no crt objects, -dylib, #inclib "framework:Name" #508)

On linux-x86_64 all unit tests pass with -gen gas64 and -gen gcc (the darwin changes are only for the darwin target).

…tem V UDT results, 8/16-bit arguments extended for clang's callees

Extern variables are accessed through the GOT on darwin: Mach-O has no copy relocations, and ld rejected the RIP-relative access to a variable of a dylib (__stdoutp of libSystem in fbcunit) with "invalid use of rip-relative addressing".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant