Skip to content

Commit

Permalink
[mono] Cleanup main.c/main-sgen.c split, unused glib functions, Apple…
Browse files Browse the repository at this point in the history
… compression etc (#69686)

- Clean up main.c/main-sgen.c split 
   We don't have separate binaries for different GCs anymore so remove the split between main.c and main-sgen.c and just use main.c
- Remove mkbundle leftovers from main.c
- Fix compiler warnings
- Remove unused ves_icall_Interop_Sys_DoubleToString
   It was only used for a test, replace it with an icall which is actually used.
- Cleanup unused glib functions
- Add error message for accept() error in debugger-agent.c
- Remove Apple compression
   We decided not to use it since it doesn't show enough benefits for the actual .ipa size
  • Loading branch information
akoeplinger committed May 24, 2022
1 parent 80a5260 commit 7d864e3
Show file tree
Hide file tree
Showing 25 changed files with 20 additions and 674 deletions.
2 changes: 0 additions & 2 deletions src/mono/CMakeLists.txt
Expand Up @@ -29,8 +29,6 @@ include(CheckFunctionExists)
include(TestBigEndian)
include(CheckCCompilerFlag)

include("cmake/QuietOSXRanlib.cmake")

set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
Expand Down
20 changes: 0 additions & 20 deletions src/mono/cmake/QuietOSXRanlib.cmake

This file was deleted.

3 changes: 0 additions & 3 deletions src/mono/cmake/config.h.in
Expand Up @@ -411,9 +411,6 @@
/* Define to 1 if you have the `sched_getcpu' function. */
#cmakedefine HAVE_SCHED_GETCPU 1

/* Define to 1 if you have the `getpwuid_r' function. */
#cmakedefine HAVE_GETPWUID_R 1

/* Define to 1 if you have the `chmod' function. */
#cmakedefine HAVE_CHMOD 1

Expand Down
6 changes: 2 additions & 4 deletions src/mono/cmake/configure.cmake
Expand Up @@ -77,11 +77,11 @@ ac_check_headers (
ac_check_funcs (
sigaction kill clock_nanosleep backtrace_symbols mkstemp mmap
getrusage dladdr sysconf getrlimit prctl nl_langinfo
sched_getaffinity sched_setaffinity getpwuid_r chmod lstat getdtablesize ftruncate msync
sched_getaffinity sched_setaffinity chmod lstat getdtablesize ftruncate msync
getpeername utime utimes openlog closelog atexit popen strerror_r inet_pton inet_aton
poll getfsstat mremap posix_fadvise vsnprintf statfs statvfs setpgid system
fork execv execve waitpid localtime_r mkdtemp getrandom execvp strlcpy stpcpy strtok_r rewinddir
vasprintf strndup getpwuid_r getprotobyname getprotobyname_r getaddrinfo mach_absolute_time
vasprintf strndup getprotobyname getprotobyname_r getaddrinfo mach_absolute_time
gethrtime read_real_time gethostbyname gethostbyname2 getnameinfo getifaddrs
access inet_ntop Qp2getifaddrs getpid mktemp)

Expand Down Expand Up @@ -245,7 +245,6 @@ if(HOST_WIN32)
set(HAVE_EXECVP 0)
elseif(HOST_IOS)
set(HAVE_SYSTEM 0)
set(HAVE_GETPWUID_R 0)
set(HAVE_SYS_USER_H 0)
set(HAVE_GETENTROPY 0)
if(HOST_TVOS)
Expand Down Expand Up @@ -273,7 +272,6 @@ elseif(HOST_WASI)
set(HAVE_SYS_UN_H 0)
set(HAVE_NETINET_TCP_H 0)
set(HAVE_ARPA_INET_H 0)
set(HAVE_GETPWUID_R 0)
set(HAVE_MKDTEMP 0)
set(HAVE_EXECVE 0)
set(HAVE_FORK 0)
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/component/debugger-agent.c
Expand Up @@ -975,7 +975,7 @@ socket_transport_accept (int socket_fd)
conn_fd = accept (socket_fd, NULL, NULL);

if (conn_fd == -1) {
PRINT_ERROR_MSG ("debugger-agent: Unable to listen on %d\n", socket_fd);
PRINT_ERROR_MSG ("debugger-agent: Unable to listen on %d: %s.\n", socket_fd, strerror (get_last_sock_error()));
} else {
PRINT_DEBUG_MSG (1, "Accepted connection from client, connection fd=%d.\n", conn_fd);
}
Expand Down
5 changes: 0 additions & 5 deletions src/mono/mono/eglib/eglib-remap.h
Expand Up @@ -51,10 +51,7 @@
#define g_free monoeg_g_free
#define g_get_current_dir monoeg_g_get_current_dir
#define g_get_current_time monoeg_g_get_current_time
#define g_get_home_dir monoeg_g_get_home_dir
#define g_get_prgname monoeg_g_get_prgname
#define g_get_tmp_dir monoeg_g_get_tmp_dir
#define g_get_user_name monoeg_g_get_user_name
#define g_getenv monoeg_g_getenv
#define g_hasenv monoeg_g_hasenv
#define g_hash_table_destroy monoeg_g_hash_table_destroy
Expand Down Expand Up @@ -151,7 +148,6 @@
#define g_queue_push_head monoeg_g_queue_push_head
#define g_queue_push_tail monoeg_g_queue_push_tail
#define g_set_error monoeg_g_set_error
#define g_set_prgname monoeg_g_set_prgname
#define g_setenv monoeg_g_setenv
#define g_slist_alloc monoeg_g_slist_alloc
#define g_slist_append monoeg_g_slist_append
Expand Down Expand Up @@ -243,7 +239,6 @@
#define g_utf8_pointer_to_offset monoeg_g_utf8_pointer_to_offset
#define g_utf8_to_ucs4_fast monoeg_g_utf8_to_ucs4_fast
#define g_vasprintf monoeg_g_vasprintf
#define g_win32_getlocale monoeg_g_win32_getlocale
#define g_assertion_disable_global monoeg_assertion_disable_global
#define g_assert_abort monoeg_assert_abort
#define g_assertion_message monoeg_assertion_message
Expand Down
6 changes: 0 additions & 6 deletions src/mono/mono/eglib/glib.h
Expand Up @@ -322,8 +322,6 @@ gchar * g_getenv(const gchar *variable);
G_EXTERN_C // sdks/wasm/driver.c is C and uses this
gboolean g_setenv(const gchar *variable, const gchar *value, gboolean overwrite);

gchar* g_win32_getlocale(void);

/*
* Precondition macros
*/
Expand Down Expand Up @@ -932,11 +930,7 @@ gchar *g_find_program_in_path (const gchar *program);
gchar *g_get_current_dir (void);
gboolean g_path_is_absolute (const char *filename);

const gchar *g_get_home_dir (void);
const gchar *g_get_tmp_dir (void);
const gchar *g_get_user_name (void);
gchar *g_get_prgname (void);
void g_set_prgname (const gchar *prgname);

gboolean g_ensure_directory_exists (const gchar *filename);

Expand Down
64 changes: 0 additions & 64 deletions src/mono/mono/eglib/gmisc-unix.c
Expand Up @@ -97,12 +97,6 @@ g_setenv(const gchar *variable, const gchar *value, gboolean overwrite)
return res;
}

gchar*
g_win32_getlocale(void)
{
return NULL;
}

gboolean
g_path_is_absolute (const char *filename)
{
Expand All @@ -111,64 +105,6 @@ g_path_is_absolute (const char *filename)
return (*filename == '/');
}

static pthread_mutex_t pw_lock = PTHREAD_MUTEX_INITIALIZER;
static const gchar *home_dir;
static const gchar *user_name;

static void
get_pw_data (void)
{
#ifdef HAVE_GETPWUID_R
struct passwd pw;
struct passwd *result = NULL;
char buf [4096];
#endif

if (user_name != NULL)
return;

pthread_mutex_lock (&pw_lock);
if (user_name != NULL) {
pthread_mutex_unlock (&pw_lock);
return;
}

home_dir = g_getenv ("HOME");
user_name = g_getenv ("USER");

#ifdef HAVE_GETPWUID_R
if (home_dir == NULL || user_name == NULL) {
if (getpwuid_r (getuid (), &pw, buf, 4096, &result) == 0 && result) {
if (home_dir == NULL)
home_dir = g_strdup (pw.pw_dir);
if (user_name == NULL)
user_name = g_strdup (pw.pw_name);
}
}
#endif

if (user_name == NULL)
user_name = "somebody";
if (home_dir == NULL)
home_dir = "/";

pthread_mutex_unlock (&pw_lock);
}

const gchar *
g_get_home_dir (void)
{
get_pw_data ();
return home_dir;
}

const gchar *
g_get_user_name (void)
{
get_pw_data ();
return user_name;
}

static const char *tmp_dir;

static pthread_mutex_t tmp_lock = PTHREAD_MUTEX_INITIALIZER;
Expand Down
101 changes: 0 additions & 101 deletions src/mono/mono/eglib/gmisc-win32.c
Expand Up @@ -84,44 +84,6 @@ g_setenv(const gchar *variable, const gchar *value, gboolean overwrite)
return result;
}

#if HAVE_API_SUPPORT_WIN32_LOCAL_INFO || HAVE_API_SUPPORT_WIN32_LOCAL_INFO_EX
gchar*
g_win32_getlocale(void)
{
gunichar2 buf[19];
gint ccBuf = 0;
#if HAVE_API_SUPPORT_WIN32_LOCAL_INFO_EX
ccBuf = GetLocaleInfoEx (LOCALE_NAME_USER_DEFAULT, LOCALE_SISO639LANGNAME, buf, 9);
#elif HAVE_API_SUPPORT_WIN32_LOCAL_INFO
LCID lcid = GetThreadLocale();
ccBuf = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME, buf, 9);
#endif
if (ccBuf != 0) {
buf[ccBuf - 1] = L'-';
#if HAVE_API_SUPPORT_WIN32_LOCAL_INFO_EX
ccBuf = GetLocaleInfoEx (LOCALE_NAME_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, buf + ccBuf, 9);
#elif HAVE_API_SUPPORT_WIN32_LOCAL_INFO
ccBuf = GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME, buf + ccBuf, 9);
#endif
assert (ccBuf <= 9);
}

// Check for failure.
if (ccBuf == 0)
buf[0] = L'\0';

return u16to8 (buf);
}
#elif !HAVE_EXTERN_DEFINED_WIN32_LOCAL_INFO && !HAVE_EXTERN_DEFINED_WIN32_LOCAL_INFO_EX
gchar*
g_win32_getlocale(void)
{
g_unsupported_api ("GetLocaleInfo, GetLocaleInfoEx");
SetLastError (ERROR_NOT_SUPPORTED);
return NULL;
}
#endif /* HAVE_API_SUPPORT_WIN32_LOCAL_INFO || HAVE_API_SUPPORT_WIN32_LOCAL_INFO_EX */

gboolean
g_path_is_absolute (const char *filename)
{
Expand All @@ -140,69 +102,6 @@ g_path_is_absolute (const char *filename)
return FALSE;
}

#if _MSC_VER && HAVE_API_SUPPORT_WIN32_SH_GET_FOLDER_PATH
#include <shlobj.h>
static gchar*
g_get_known_folder_path (void)
{
gchar *folder_path = NULL;
PWSTR profile_path = NULL;
#ifdef __cplusplus
REFGUID folderid = FOLDERID_Profile;
#else
REFGUID folderid = &FOLDERID_Profile;
#endif
HRESULT hr = SHGetKnownFolderPath (folderid, KF_FLAG_DEFAULT, NULL, &profile_path);
if (SUCCEEDED(hr)) {
folder_path = u16to8 (profile_path);
CoTaskMemFree (profile_path);
}

return folder_path;
}
#elif !HAVE_EXTERN_DEFINED_WIN32_SH_GET_FOLDER_PATH
static inline gchar *
g_get_known_folder_path (void)
{
return NULL;
}
#endif /* HAVE_API_SUPPORT_WIN32_SH_GET_FOLDER_PATH */

const gchar *
g_get_home_dir (void)
{
gchar *home_dir = g_get_known_folder_path ();

if (!home_dir) {
home_dir = (gchar *) g_getenv ("USERPROFILE");
}

if (!home_dir) {
const gchar *drive = g_getenv ("HOMEDRIVE");
const gchar *path = g_getenv ("HOMEPATH");

if (drive && path) {
home_dir = g_malloc (strlen (drive) + strlen (path) + 1);
if (home_dir) {
sprintf (home_dir, "%s%s", drive, path);
}
}
g_free ((void*)drive);
g_free ((void*)path);
}

return home_dir;
}

const gchar *
g_get_user_name (void)
{
const char * retName = g_getenv ("USER");
if (!retName)
retName = g_getenv ("USERNAME");
return retName;
}

static const char *tmp_dir;

const gchar *
Expand Down
14 changes: 0 additions & 14 deletions src/mono/mono/eglib/gpath.c
Expand Up @@ -287,20 +287,6 @@ g_find_program_in_path (const gchar *program)
return NULL;
}

static char *name;

void
g_set_prgname (const gchar *prgname)
{
name = g_strdup (prgname);
}

gchar *
g_get_prgname (void)
{
return name;
}

gboolean
g_ensure_directory_exists (const gchar *filename)
{
Expand Down
4 changes: 0 additions & 4 deletions src/mono/mono/eglib/test/path.c
Expand Up @@ -332,12 +332,8 @@ test_cwd (void)
static gchar *
test_misc (void)
{
const char *home = g_get_home_dir ();
const char *tmp = g_get_tmp_dir ();

if (home == NULL)
return FAILED ("Where did my home go?");

if (tmp == NULL)
return FAILED ("Where did my /tmp go?");

Expand Down
1 change: 0 additions & 1 deletion src/mono/mono/metadata/icall-decl.h
Expand Up @@ -120,7 +120,6 @@ ICALL_EXPORT gint32 ves_icall_System_Environment_get_ProcessorCount (void);
ICALL_EXPORT gint32 ves_icall_System_Environment_get_TickCount (void);
ICALL_EXPORT gint64 ves_icall_System_Environment_get_TickCount64 (void);
ICALL_EXPORT gint64 ves_icall_System_GC_GetTotalMemory (MonoBoolean forceCollection);
ICALL_EXPORT int ves_icall_Interop_Sys_DoubleToString (double, char*, char*, int);
ICALL_EXPORT int ves_icall_System_GC_GetCollectionCount (int);
ICALL_EXPORT int ves_icall_System_GC_GetMaxGeneration (void);
ICALL_EXPORT gint64 ves_icall_System_GC_GetAllocatedBytesForCurrentThread (void);
Expand Down
18 changes: 0 additions & 18 deletions src/mono/mono/metadata/icall.c
Expand Up @@ -6294,24 +6294,6 @@ ves_icall_System_Runtime_InteropServices_Marshal_Prelink (MonoReflectionMethodHa
/* create the wrapper, too? */
}

int
ves_icall_Interop_Sys_DoubleToString(double value, char *format, char *buffer, int bufferLength)
{
#if defined(TARGET_ARM)
/* workaround for faulty vcmp.f64 implementation on some 32bit ARM CPUs */
guint64 bits = *(guint64 *) &value;
if (bits == 0x1) { /* 4.9406564584124654E-324 */
g_assert (!strcmp (format, "%.40e"));
return snprintf (buffer, bufferLength, "%s", "4.9406564584124654417656879286822137236506e-324");
} else if (bits == 0x4) { /* 2E-323 */
g_assert (!strcmp (format, "%.40e"));
return snprintf (buffer, bufferLength, "%s", "1.9762625833649861767062751714728854894602e-323");
}
#endif

return snprintf(buffer, bufferLength, format, value);
}

static gboolean
add_modifier_to_array (MonoType *type, MonoArrayHandle dest, int dest_idx, MonoError *error)
{
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/native-library.c
Expand Up @@ -803,7 +803,7 @@ netcore_check_alc_cache (MonoAssemblyLoadContext *alc, const char *scope)
}

static MonoDl*
netcore_lookup_self_native_handle()
netcore_lookup_self_native_handle (void)
{
ERROR_DECL (load_error);
if (!internal_module)
Expand Down

0 comments on commit 7d864e3

Please sign in to comment.