Skip to content

Conversation

@jayrm
Copy link
Member

@jayrm jayrm commented Jul 18, 2021

This pull request is mostly from an old branch of @rversteegen (TeeEmCee) which had the bulk of the changes for freebsd and Darwin. A few changes from myself while building and testing on freebsd.

The freebsd changes were tested on FreeBSD 13.0 i386 & amd64

  • there are few failing tests in tests/cpp having to do with calling conventions and interfacing directly with g++ classes
  • note: need to use gmake and gcc for compiling
    Result so far natively on FreeBSD vm's:
  • boot strap a compiler with 1.08.1 bootstrap sources,
  • rebuild the current fbc/master (this PR)
  • run the test suite (4 log-tests fail in tests/cpp)
  • make gitdist, bindist, bootstrap-dist successfully

Darwin changes reviewed only. I wasn't able to test. However, it's reasonable to include the changes for Darwin, because:

  1. they included some needed improvements for freebsd
  2. it will be harder to add later because conflicts will increase
  3. most changes are Darwin specific and are within compile target checks so should not affect other targets

Changes / fixes - all targets

  • rtlib: enable fb_AtomicSetThreadFlags() in src/rtlib/thread_self.c - an unusual case but possible where the non mt rtlib is used to create threads
  • fbc: Add -entry commandline option to override the name of the entry procedure (TeeEmCee)
  • gen gcc: allow compiling with GCC 4.5 and older, by avoiding -Wno-unused-but-set-variable
  • When using -gen gcc, ask gcc which as and ld to use. This fixes FreeBSD.

Updates for Darwin (TeeEmCee)

  • Implement objinfo Mach-O parser
  • fixes and improvements for compiling and linking
  • darwin: put objinfo in 'fbctinf, __DATA' section instead of '.fbctinf'
  • darwin/x86 backend: Fix constructor and destructor sections.
  • darwin: default to -gen gcc
  • darwin: Default to at&t instead of intel asm syntax on Darwin except for -gen gas
  • darwin: pass -macosx_version_min=10.4 instead of 10.6.
  • darwin: Fix name mangling in cpudetect.s
  • darwin: prefix function names with underscores
  • darwin: pass argument to tell ld the target architecture
  • darwin: 'as' expects temp labels to begin with L not .L
  • darwin/rtlib: implement FRE and add a bunch of missing stub functions
  • darwin: dylibload should check for .dylib files too

Updates for freebsd 13.0 i386 & amd64

  • add minimal crt headers for freebsd to allow compiling and testing
  • update main makefile and tests makefile to work with
  • add objinfo reader for freebsd x86 object files and libraries
  • rtlib: freebsd: minimum thread stacksize 8192 KiB - without this minimum libpthreads was crashing (I think trying to extend stack space but denied).

jayrm and others added 30 commits July 17, 2021 10:12
- prepare stdlib.bi for fall back to unix include when not specifically given for the target
…types.bi

- add custom crt headers for freebsd to pick up types needed to build the test suite

crt-headers: guard wchar_t and wint_t
- ideally we should like to only have this defined in one place

crt-headers: move wmemcpy() up in to inc/crt/wchar.bi and
- assume wmemcpy() it exists on all targets.  If it doesn't move it back some time later
- xargs on freebsd does not support the '-a filename' option, use 'cat filename | xargs' instead
- fb_AtomicSetThreadFlags() is needed in the non-multithreaded rtlib
- threading functions are still available in the non-multithreaded rtlib
- it is needed by thread_core.c:threadproc()
- unusual but not impossible to link the non-multithreaded rtlib and call thread functions
What are not supported are .a files which are actually fat/universal binaries
rather than ar archives. However, I have yet to encounter any of these, and
fbc itself will not create them, so there should be no problem.
…DATA

Updated gas, gcc and llvm backends, but haven't tested llvm.

On Darwin the assembler/linker are a bit different; it is necessary to provide
a segment, section pair rather than just a section name. It is possible to use
any segment name we want, but since it isn't stripped, putting it in a new
segment would only increase bloat.

Also, use "fbctinf" rather than ".fbctinf" on darwin, where section names aren't
normally prefixed with .
…procedure.

This is necessary in order to use SDL 1.2 or SDL 2.0 on at least Android, OSX,
iOS, and winRT, and is optional on Windows. SDL_main.h #defines main to SDL_main,
and declares the real main() itself. Under FB that can't be done, so the solution
is to pass -entry SDL_main when compiling the main module.

No guarentees that that is all that is needed to properly initialise a
FB program under SDL.

Note: I wasn't sure where to put this global. env.clopt.entry would seem to
be the natural place, but env.clopt contains only integral datatypes,
and file-scope for other structures like fbc seems to be strictly enforced.
So it went into fbc and then passed to fbInit and put in env.
I don't emit the ctor/dtor priorities, because they are simply not supported
by the darwin dyld. The most that the gas backend can do is to ensure that
ctors/dtors are placed in the right order within a single module. Which of
course isn't implemented.
Apple gas diverged long ago from FSF/GNU gas, and there are many
incompatibilities, especially in intel syntax support.

Also noted (in a comment) that one of the gcc flags we use is not compatible
with, for example gcc 4.2, so you need a fairly recent gcc.
…for -gen gas

Of all the Apple and MacPorts gcc and clang compilers I tried, only
clang 3.6 and 3.8 from MacPorts supported -masm=intel, while Apple
gcc and clang and MP gcc were compiled with support disabled.
This doesn't seem to cause any problems when the corresponding Mac SDK
isn't installed.
This tells ld what is expected when crosscompiling to 32/64 bit
when the default architecture is the opposite.
Because symbUniqueId already generates identifiers stating with Lt_ I changed
symbUniqueLabel to use L_ (darwin) or .L_ (elsewhere) prefixes instead of .Lt_
…sed-but-set-variable

In order to disable that warning, disable whole family of warnings instead;
-Wno-unused.

Unforunately, newer versions of gcc ignore unknown warning flags, but that's
also a recent feature.
It's necessary to use the as and ld packaged with gcc rather than the system
ones.
- allow freebsd-i386 to pass the tan() accuracy test
- also allow showing the failed test if ENABLE_CHECK_BUGS=1 is defined
- tan() function on freebsd-i386 has different accuracy
- tan() function was modified to have greater accuracy in freebsd's implementation of the math library
- the accuracy may vary depending on which c runtime was linked in and which builtins were used
jayrm added 3 commits July 17, 2021 20:04
- the objinfo features writes extra information to object files and libraries
- this information is read back by fbc when fbc to determine some compile time options and required library names
@jayrm jayrm merged commit 36a6feb into freebasic:master Jul 18, 2021
@jayrm jayrm deleted the freebsd branch July 18, 2021 18:07
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.

2 participants