-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor ABI wrappers to not rely on --wrap
b/330648201
- Loading branch information
Showing
18 changed files
with
535 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Starboard Modular ABI Wrappers | ||
|
||
This directory contains code that will handle translations of data types across | ||
ABI boundaries. | ||
|
||
These wrappers are used in modular builds (including Evergreen). They are needed | ||
to handle dealing with differences in platform-specific toolchain types and | ||
musl-based types. For example, the `struct timespec` and `struct timeval` types | ||
may contain differently sized member fields and when the caller is Cobalt code | ||
compiled with musl it will provide argument data that needs to be adjusted when | ||
passed to platform-specific system libraries. | ||
|
||
To do this adjustment across compilation toolchains, there are 2 sets of files | ||
in this directory that will be compiled in either the Cobalt toolchain or the | ||
Starboard plaform-specific toolchain: | ||
|
||
* `cobalt_layer_posix_XYZ_abi_wrappers.cc` - these are compiled only in the | ||
Cobalt toolchain for modular builds (excluding Evergreen). The logic in | ||
these files simply defines the API we want to wrap and re-calls an external | ||
function named `__abi_wrap_XYZ` using the exact same parameter and return | ||
value types. This is simply to get the libcobalt.so to not link against | ||
the glibc implementations and instead rely on an external implementation | ||
that will be defined in libstarboard.so. Similar logic is done specifically | ||
for Evergreen in exported_symbols.cc, since we have a custom ELF loader in | ||
that case to handle remapping the functions. | ||
* `starboard_layer_posix_XYZ_abi_wrappers.{h,cc}` - these are compiled only | ||
in the Starboard platform-specific toolchain for modular builds (including | ||
Evergreen). The header files define corresponding musl-compatible types | ||
(copying definitions provided in //third_party/musl/include/alltypes.h.in) | ||
for the cases where data types are not guaranteed to match across ABI | ||
boundaries. These files then define the implementation of the | ||
`__abi_wrap_XYZ` functions, which will be called from the Cobalt layer. | ||
Since these functions are being implemented/compiled in the Starboard | ||
layer, they will rely on the platform-specific toolchain to get the | ||
platform-specific type definitions from the system headers (e.g. <time.h>). | ||
The implementations will handle doing data type conversions across the | ||
ABI boundary (both for parameters and return types). | ||
|
||
|
||
To help illustrate how this works, we can use the POSIX function `clock_gettime` | ||
as an example. When we build modularly, the following table shows how the | ||
symbols would look using a tool like `nm`: | ||
|
||
``` | ||
libstarboard.so: | ||
U clock_gettime@GLIBC_2.17 (undefined reference to platform library) | ||
T __abi_wrap_clock_gettime (concrete definition of ABI wrapper function) | ||
libcobalt.so | ||
U __abi_wrap_clock_gettime (undefined reference to the Starboard wrapper) | ||
t clock_gettime (concrete definition that calls __abi_wrap_*) | ||
``` |
33 changes: 33 additions & 0 deletions
33
starboard/shared/modular/cobalt_layer_posix_mmap_abi_wrappers.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2024 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#if SB_API_VERSION >= 16 | ||
|
||
#include <sys/mman.h> | ||
|
||
extern "C" { | ||
|
||
void* __abi_wrap_mmap(void* addr, | ||
size_t len, | ||
int prot, | ||
int flags, | ||
int fildes, | ||
off_t off); | ||
|
||
void* mmap(void* addr, size_t len, int prot, int flags, int fildes, off_t off) { | ||
return __abi_wrap_mmap(addr, len, prot, flags, fildes, off); | ||
} | ||
} | ||
|
||
#endif // SB_API_VERSION >= 16 |
Oops, something went wrong.