Skip to content

Commit

Permalink
Move LIBC_FILENAME to the utilities header
Browse files Browse the repository at this point in the history
  • Loading branch information
simonrozsival committed Dec 15, 2021
1 parent d0b040c commit 4e67687
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
25 changes: 25 additions & 0 deletions src/native/libs/Common/pal_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include <unistd.h>
#include <limits.h>

#if HAVE_GNU_LIBNAMES_H
#include <gnu/lib-names.h>
#endif

#ifdef DEBUG
#define assert_err(cond, msg, err) do \
{ \
Expand Down Expand Up @@ -130,3 +134,24 @@ inline static int32_t SizeTToInt32(size_t value)
assert(value <= INT_MAX);
return (int32_t)value;
}

/**
* libc file name:
* - For Linux, use the full name of the library that is defined in <gnu/lib-names.h> by the
* LIBC_SO constant. The problem is that calling dlopen("libc.so") will fail for libc even
* though it works for other libraries. The reason is that libc.so is just linker script
* (i.e. a test file).
* As a result, we have to use the full name (i.e. lib.so.6) that is defined by LIBC_SO.
* - For macOS, use constant value absolute path "/usr/lib/libc.dylib".
* - For FreeBSD, use constant value "libc.so.7".
* - For rest of Unices, use constant value "libc.so".
*/
#if defined(__APPLE__)
#define LIBC_FILENAME "/usr/lib/libc.dylib"
#elif defined(__FreeBSD__)
#define LIBC_FILENAME "libc.so.7"
#elif defined(LIBC_SO)
#define LIBC_FILENAME LIBC_SO
#else
#define LIBC_FILENAME "libc.so"
#endif
1 change: 1 addition & 0 deletions src/native/libs/System.Native/pal_dynamicload.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "pal_config.h"
#include "pal_dynamicload.h"
#include "pal_utilities.h"

#include <dlfcn.h>
#include <string.h>
Expand Down
23 changes: 0 additions & 23 deletions src/native/libs/System.Native/pal_dynamicload.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,6 @@
#include "pal_compiler.h"
#include "pal_types.h"

#if HAVE_GNU_LIBNAMES_H
#include <gnu/lib-names.h>
#endif

// libc file name:
// * For Linux, use the full name of the library that is defined in <gnu/lib-names.h> by the
// LIBC_SO constant. The problem is that calling dlopen("libc.so") will fail for libc even
// though it works for other libraries. The reason is that libc.so is just linker script
// (i.e. a test file).
// As a result, we have to use the full name (i.e. lib.so.6) that is defined by LIBC_SO.
// * For macOS, use constant value absolute path "/usr/lib/libc.dylib".
// * For FreeBSD, use constant value "libc.so.7".
// * For rest of Unices, use constant value "libc.so".
#if defined(__APPLE__)
#define LIBC_FILENAME "/usr/lib/libc.dylib"
#elif defined(__FreeBSD__)
#define LIBC_FILENAME "libc.so.7"
#elif defined(LIBC_SO)
#define LIBC_FILENAME LIBC_SO
#else
#define LIBC_FILENAME "libc.so"
#endif

PALEXPORT void* SystemNative_LoadLibrary(const char* filename);

PALEXPORT void* SystemNative_GetProcAddress(void* handle, const char* symbol);
Expand Down
1 change: 0 additions & 1 deletion src/native/libs/System.Native/pal_interfaceaddresses.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "pal_utilities.h"
#include "pal_safecrt.h"
#include "pal_networking.h"
#include "pal_dynamicload.h"

#include <stdlib.h>
#include <sys/types.h>
Expand Down

0 comments on commit 4e67687

Please sign in to comment.