Skip to content

Commit

Permalink
support new symbol names on older systems
Browse files Browse the repository at this point in the history
__bzero does not exist on older system but bzero does.
dirfd is macro on older systems but a library symbol on newer ones.
fstatat$INODE64 exists on newer systems.
Its functionality can replicated by fstatat64.
  • Loading branch information
MarcusCalhoun-Lopez committed Mar 31, 2024
1 parent 61263ec commit a1e2bb0
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,21 @@ Wrapped headers and replaced functions are:
<code>TARGET_OS_WATCH</code> and <code>TARGET_OS_OSX</code> if needed.</td>
<td>OSX10.10</td>
</tr>
<tr>
<td><code>-</code></td>
<td>Adds <code>__bzero</code> library symbol</td>
<td>OSX10.5</td>
</tr>
<tr>
<td><code>-</code></td>
<td>Adds <code>_dirfd</code> library symbol</td>
<td>OSX10.7</td>
</tr>
<tr>
<td><code>-</code></td>
<td>Adds <code>_fstatat$INODE64</code> library symbol</td>
<td>OSX10.9</td>
</tr>
</table>

For information on building this library outside MacPorts, see BUILDING.txt.
6 changes: 6 additions & 0 deletions include/MacportsLegacySupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,10 @@
/* os_unfair_lock structure and its associated functions */
#define __MP_LEGACY_SUPPORT_OS_UNFAIR_LOCK__ (__APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200)

/* library symbol ___bzero */
#define __MP_LEGACY_SUPPORT_SYMBOL____bzero__ (__APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1060)

/* library symbol _dirfd */
#define __MP_LEGACY_SUPPORT_SYMBOL__dirfd__ (__APPLE__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1080)

#endif /* _MACPORTS_LEGACYSUPPORTDEFS_H_ */
20 changes: 20 additions & 0 deletions src/add_symbols.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,23 @@ extern const char clock_gettime_tmp9 __asm("$ld$add$os10.9$_clock_gettime"); __a
extern const char clock_gettime_tmp10 __asm("$ld$add$os10.10$_clock_gettime"); __attribute__((visibility("default"))) const char clock_gettime_tmp10 = 0;
extern const char clock_gettime_tmp11 __asm("$ld$add$os10.11$_clock_gettime"); __attribute__((visibility("default"))) const char clock_gettime_tmp11 = 0;
#endif

#if !(__MP_LEGACY_SUPPORT_SYMBOL____bzero__)
extern const char __bzero_tmp4 __asm("$ld$add$os10.4$___bzero"); __attribute__((visibility("default"))) const char __bzero_tmp4 = 0;
extern const char __bzero_tmp5 __asm("$ld$add$os10.5$___bzero"); __attribute__((visibility("default"))) const char __bzero_tmp5 = 0;
#endif

#if !(__MP_LEGACY_SUPPORT_SYMBOL__dirfd__)
extern const char dirfd_tmp4 __asm("$ld$add$os10.4$_dirfd"); __attribute__((visibility("default"))) const char dirfd_tmp4 = 0;
extern const char dirfd_tmp5 __asm("$ld$add$os10.5$_dirfd"); __attribute__((visibility("default"))) const char dirfd_tmp5 = 0;
extern const char dirfd_tmp6 __asm("$ld$add$os10.6$_dirfd"); __attribute__((visibility("default"))) const char dirfd_tmp6 = 0;
extern const char dirfd_tmp7 __asm("$ld$add$os10.7$_dirfd"); __attribute__((visibility("default"))) const char dirfd_tmp7 = 0;
#endif

#if !(__MP_LEGACY_SUPPORT_ATCALLS__)
extern const char fstatat$INODE64_tmp5 __asm("$ld$add$os10.5$_fstatat$INODE64"); __attribute__((visibility("default"))) const char fstatat$INODE64_tmp5 = 0;
extern const char fstatat$INODE64_tmp6 __asm("$ld$add$os10.6$_fstatat$INODE64"); __attribute__((visibility("default"))) const char fstatat$INODE64_tmp6 = 0;
extern const char fstatat$INODE64_tmp7 __asm("$ld$add$os10.7$_fstatat$INODE64"); __attribute__((visibility("default"))) const char fstatat$INODE64_tmp7 = 0;
extern const char fstatat$INODE64_tmp8 __asm("$ld$add$os10.8$_fstatat$INODE64"); __attribute__((visibility("default"))) const char fstatat$INODE64_tmp8 = 0;
extern const char fstatat$INODE64_tmp9 __asm("$ld$add$os10.9$_fstatat$INODE64"); __attribute__((visibility("default"))) const char fstatat$INODE64_tmp9 = 0;
#endif
62 changes: 62 additions & 0 deletions src/macports_legacy_symbol_aliases.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2024
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

/* MP support header */
#include "MacportsLegacySupport.h"

#if __MP_LEGACY_SUPPORT_SYMBOL____bzero__
#include <strings.h>
/*
The need for this function is highly limited.
The symbol `__bzero` does not exist prior to 10.6.
When the Rust stage0 compiler for 10.5 is built on newer machines, it bakes `__bzero` into librustc_driver-xxx.dylib.
This may be due to the fact that on newer machines, the `_bzero` symbol is an indirect reference to another symbol.
*/
void __bzero(void *s, size_t n) { bzero(s, n); }
#endif /* __MP_LEGACY_SUPPORT_SYMBOL_ALIASES__ */

#if __MP_LEGACY_SUPPORT_SYMBOL__dirfd__
#include <dirent.h>
#include <errno.h>
/*
The need for this function is highly limited.
Prior to 10.8, `dirfd` was a macro`.
The Rust compiler requires `dirfd` to be a library symbol.
*/
#undef dirfd
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050
#define __dd_fd dd_fd
#endif /* __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050 */
int dirfd(DIR *dirp)
{
if (dirp == NULL || dirp->__dd_fd < 0)
{
errno = EINVAL;
return -1;
}
else
return dirp->__dd_fd;
}
#endif /* __MP_LEGACY_SUPPORT_SYMBOL__dirfd__ */

#if __MP_LEGACY_SUPPORT_ATCALLS__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050
#include <sys/stat.h>
/*
The need for this function is highly limited.
The Rust compiler requires `fstatat$INODE64` to be a library symbol.
*/
int fstatat$INODE64(int dirfd, const char *pathname, struct stat64 *buf, int flags) { return fstatat64(dirfd, pathname, buf, flags); }
#endif /* __MP_LEGACY_SUPPORT_ATCALLS__ && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 */
26 changes: 26 additions & 0 deletions test/test_symbol_aliases.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <dlfcn.h>
#include <assert.h>
#include <stdio.h>

int main()
{
void (*fptr)();

// void __bzero(void *s, size_t n);
fptr = dlsym(RTLD_DEFAULT, "__bzero");
assert( fptr!=0 && "__bzero symbol does not exist");

// int dirfd(DIR *dirp);
fptr = dlsym(RTLD_DEFAULT, "dirfd");
assert( fptr!=0 && "dirfd symbol does not exist");

#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 && !defined(__arm64__)
// int fstatat$INODE64(int dirfd, const char *pathname, struct stat64 *buf, int flags);
fptr = dlsym(RTLD_DEFAULT, "fstatat$INODE64");
assert( fptr!=0 && "fstatat$INODE64 symbol does not exist");
#endif

printf("All symbol aliases found\n");

return 0;
}

2 comments on commit a1e2bb0

@barracuda156
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarcusCalhoun-Lopez Some header was forgotten? Or it builds for everyone but me?

@MarcusCalhoun-Lopez
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarcusCalhoun-Lopez Some header was forgotten? Or it builds for everyone but me?

Thank you for pointing out this error.
It should be fixed by #81.

Please sign in to comment.