Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check whether core MPS is freestanding #151

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

rptb1
Copy link
Member

@rptb1 rptb1 commented Feb 13, 2023

Working on #133

Plan of work:

  • Work out what compiler invocations can be used on available platforms to check dependencies on libraries
  • Implement dummy freestanding plinth
  • Resolve problems
  • Add to CI checks

@rptb1
Copy link
Member Author

rptb1 commented Feb 13, 2023

gcc -nostdlib -DCONFIG_PLINTH_NONE -DCONFIG_PF_ANSI mps.c mpslibfs.c on Ubuntu 22 says:

/usr/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000003070
/usr/bin/ld: /tmp/ccZWa646.o: in function `mps_arena_release':
mps.c:(.text+0x525): undefined reference to `_setjmp'
/usr/bin/ld: /tmp/ccZWa646.o: in function `mps_arena_start_collect':
mps.c:(.text+0x70d): undefined reference to `_setjmp'
/usr/bin/ld: /tmp/ccZWa646.o: in function `mps_arena_collect':
mps.c:(.text+0x850): undefined reference to `_setjmp'
/usr/bin/ld: /tmp/ccZWa646.o: in function `mps_arena_step':
mps.c:(.text+0x9a3): undefined reference to `_setjmp'
/usr/bin/ld: /tmp/ccZWa646.o: in function `mps_alloc':
mps.c:(.text+0x2369): undefined reference to `_setjmp'
/usr/bin/ld: /tmp/ccZWa646.o:mps.c:(.text+0x34bc): more undefined references to `_setjmp' follow
/usr/bin/ld: /tmp/ccZWa646.o: in function `VMInit':
mps.c:(.text+0xa08a2): undefined reference to `malloc'
/usr/bin/ld: /tmp/ccZWa646.o: in function `VMFinish':
mps.c:(.text+0xa0d31): undefined reference to `free'
collect2: error: ld returned 1 exit status

@rptb1
Copy link
Member Author

rptb1 commented Feb 13, 2023

/usr/bin/ld: /tmp/ccZWa646.o: in function VMInit': mps.c:(.text+0xa08a2): undefined reference to malloc'
/usr/bin/ld: /tmp/ccZWa646.o: in function VMFinish': mps.c:(.text+0xa0d31): undefined reference to free'

These are a consequence of CONFIG_PF_ANSI which says to use malloc and free to supply memory to the arena. A freestanding/embedded implementation is more likely to use the client arena. This check should probably do that too.

@rptb1
Copy link
Member Author

rptb1 commented Feb 13, 2023

These are a consequence of CONFIG_PF_ANSI which says to use malloc and free to supply memory to the arena.

These errors can be eliminated by excluding:

  • vman.c, the ANSI virtual memory mapping, which calls malloc and free to fake virtual memory
  • arenavm.c, the VM arena class, which needs a VM implementation
  • sa.c, the Sparse Array implementation used by the VM arena class, which also needs a VM implementation

It's conceivable that a freestanding / embedded client of the MPS might provide its own VM, this this could be done better by proding a fake "vmfs.c" stub.

@rptb1
Copy link
Member Author

rptb1 commented Feb 13, 2023

See also design.mps.lib.goal which says:

The goals of the MPS library interface are:

  • To control the dependency of the MPS on the hosted ISO C library so that the core MPS remains freestanding (see design.mps.exec-env).

  • To allow the core MPS convenient access to ISO C functionality that is provided on freestanding platforms (see
    design.mps.exec-env).

These documents should be updated as part of this work.

@rptb1
Copy link
Member Author

rptb1 commented Feb 13, 2023

So now gcc -ffreestanding -nostdlib -DCONFIG_PLINTH_NONE -DCONFIG_PF_ANSI --entry mps_lib_assert_fail mps.c mpslibfs.c vmfs.c on Ubuntu 22 says:

/usr/bin/ld: /tmp/cct0FyDm.o: in function `mps_arena_release':
mps.c:(.text+0x525): undefined reference to `_setjmp'
/usr/bin/ld: /tmp/cct0FyDm.o: in function `mps_arena_start_collect':
mps.c:(.text+0x70d): undefined reference to `_setjmp'
/usr/bin/ld: /tmp/cct0FyDm.o: in function `mps_arena_collect':
mps.c:(.text+0x850): undefined reference to `_setjmp'
/usr/bin/ld: /tmp/cct0FyDm.o: in function `mps_arena_step':
mps.c:(.text+0x9a3): undefined reference to `_setjmp'
/usr/bin/ld: /tmp/cct0FyDm.o: in function `mps_alloc':
mps.c:(.text+0x2369): undefined reference to `_setjmp'
/usr/bin/ld: /tmp/cct0FyDm.o:mps.c:(.text+0x34bc): more undefined references to `_setjmp' follow
collect2: error: ld returned 1 exit status

And clang -ffreestanding -nostdlib -DCONFIG_PLINTH_NONE -DCONFIG_PF_ANSI -e mps_lib_assert_fail -Wno-return-type mps.c mpslibfs.c vmfs.c says:

/usr/bin/ld: /tmp/mps-df6167.o: in function `mps_arena_release':
mps.c:(.text+0x1ad0): undefined reference to `_setjmp'
/usr/bin/ld: /tmp/mps-df6167.o: in function `mps_arena_start_collect':
mps.c:(.text+0x20c0): undefined reference to `_setjmp'
/usr/bin/ld: /tmp/mps-df6167.o: in function `mps_arena_collect':
mps.c:(.text+0x2310): undefined reference to `_setjmp'
/usr/bin/ld: /tmp/mps-df6167.o: in function `mps_arena_step':
mps.c:(.text+0x254a): undefined reference to `_setjmp'
/usr/bin/ld: /tmp/mps-df6167.o: in function `mps_alloc':
mps.c:(.text+0x68d9): undefined reference to `_setjmp'
/usr/bin/ld: /tmp/mps-df6167.o:mps.c:(.text+0x88eb): more undefined references to `_setjmp' follow
/usr/bin/ld: /tmp/mps-df6167.o: in function `rootCreate':
mps.c:(.text+0x4daef): undefined reference to `memcpy'
/usr/bin/ld: /tmp/mps-df6167.o: in function `StackScan':
mps.c:(.text+0x8684c): undefined reference to `_setjmp'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

so we've picked up a reference to memcpy, but man clang says:

   -ffreestanding
          Indicate  that  the  file should be compiled for a freestanding,
          not a hosted, environment. Note that it is assumed that a  free‐
          standing  environment will additionally provide memcpy, memmove,
          memset and memcmp implementations, as these are needed for effi‐
          cient codegen for many programs.

and it's not clear whether insertion of this dependency can be suppressed. It may not matter if we use gcc to check. In any case it comes from a transgression of MPS rules with a structure copy, here

mps/code/root.c

Line 204 in 9bc1f98

root->the = *theUnionP;

@rptb1 rptb1 self-assigned this Feb 14, 2023
@rptb1 rptb1 added the optional Will cause failures / of benefit. Worth assigning resources. label Feb 14, 2023
@rptb1
Copy link
Member Author

rptb1 commented Feb 14, 2023

Assigned priority "optional" since it seems very likely that the MPS core is still freestanding from the above. But it would still be good to have a CI test for it.

@rptb1
Copy link
Member Author

rptb1 commented Feb 14, 2023

Revisit this when #38 is resolved. That will probably eliminate the dependencies on setjmp so that the build commands above succeed. Then we can add a simple CI check script.

@rptb1 rptb1 added the blocked Unable to proceed. See comment for reason. label Feb 14, 2023
@rptb1
Copy link
Member Author

rptb1 commented Feb 14, 2023

The index to source code will need updating (see also #153 ) and the manual for the new preprocessor symbols.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Unable to proceed. See comment for reason. optional Will cause failures / of benefit. Worth assigning resources.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant