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

feat: stricter emcc linker options in external file #41

Merged
merged 1 commit into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ CHECK_INCLUDE_FILE(sys/types.h HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILE(sys/stat.h HAVE_SYS_STAT_H)
CHECK_SYMBOL_EXISTS(snprintf stdio.h HAVE_SNPRINTF)
CHECK_SYMBOL_EXISTS(popen stdio.h HAVE_POPEN)
CHECK_SYMBOL_EXISTS(getrusage sys/resource.h HAVE_GETRUSAGE)

# Testing endianness is stupidly hard with CMake
if(EMSCRIPTEN)
# FIXME: and doesn't work at all with emscripten, maybe it's just
# always little-endian?
# Emscripten is always little-endian (requires a linker flag to work
# on big-endian platforms though)
set(WORDS_BIGENDIAN 0)
else()
test_big_endian(WORDS_BIGENDIAN)
Expand Down
1 change: 1 addition & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#cmakedefine HAVE_SYS_STAT_H
#cmakedefine HAVE_SNPRINTF
#cmakedefine HAVE_POPEN
#cmakedefine HAVE_GETRUSAGE
#cmakedefine WITH_PTM_MGAU
#cmakedefine WITH_S2_SEMI_MGAU
#cmakedefine01 WORDS_BIGENDIAN
5 changes: 2 additions & 3 deletions js/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ target_compile_options(ssjs PRIVATE -Oz)
# https://stackoverflow.com/questions/68775616/how-not-to-have-dollar-sign-in-target-link-options-mangled
# https://discourse.cmake.org/t/how-not-to-have-dollar-sign-in-target-link-options-mangled/3939/3
target_link_options(ssjs PRIVATE
-Oz
@${CMAKE_SOURCE_DIR}/js/linker_options.txt
-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=@${CMAKE_SOURCE_DIR}/js/library_funcs.txt
-sEXPORTED_FUNCTIONS=@${CMAKE_SOURCE_DIR}/js/exported_functions.txt
-sFILESYSTEM=0 -sMODULARIZE=1 -sALLOW_MEMORY_GROWTH=1 -sINITIAL_MEMORY=33554432)
-sEXPORTED_FUNCTIONS=@${CMAKE_SOURCE_DIR}/js/exported_functions.txt)
# See
# https://github.com/emscripten-core/emscripten/blob/main/cmake/Modules/Platform/Emscripten.cmake
# ...sure would be nice if this were documented
Expand Down
8 changes: 8 additions & 0 deletions js/linker_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-Oz
-sFILESYSTEM=0
-sMODULARIZE=1
-sALLOW_MEMORY_GROWTH=1
-sINITIAL_MEMORY=33554432
-sSUPPORT_BIG_ENDIAN=1
-sSTRICT=1
-sSTRICT_JS=1
54 changes: 9 additions & 45 deletions src/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,8 @@
#include <stdlib.h>
#include <string.h>

#if defined(_WIN32) && !defined(__SYMBIAN32__)
#if defined(_WIN32)
# include <windows.h>
# ifndef _WIN32_WCE
# include <time.h>
# endif
#elif defined(HAVE_UNISTD_H) /* I know this, this is Unix... */
# include <unistd.h>
# include <sys/time.h>
Expand All @@ -85,23 +82,6 @@
#include <soundswallower/err.h>
#include <soundswallower/ckd_alloc.h>

#if defined(_WIN32_WCE) || defined(_WIN32_WP)
DWORD unlink(const char *filename)
{
WCHAR *wfilename;
DWORD rv;
size_t len;

len = mbstowcs(NULL, filename, 0);
wfilename = ckd_calloc(len+1, sizeof(*wfilename));
mbstowcs(wfilename, filename, len);
rv = DeleteFileW(wfilename);
ckd_free(wfilename);

return rv;
}
#endif

pctr_t *
pctr_new(char *nm)
{
Expand Down Expand Up @@ -139,7 +119,7 @@ pctr_free(pctr_t * pc)
}


#if defined(_WIN32) && !defined(GNUWINCE) && !defined(__SYMBIAN32__)
#if defined(_WIN32)

#define TM_LOWSCALE 1e-7
#define TM_HIGHSCALE (4294967296.0 * TM_LOWSCALE);
Expand Down Expand Up @@ -169,17 +149,10 @@ make_sec(struct timeval *s)
void
ptmr_start(ptmr_t * tm)
{
#if (!defined(_WIN32)) || defined(GNUWINCE) || defined(__SYMBIAN32__)
#if !defined(_WIN32)
struct timeval e_start; /* Elapsed time */
gettimeofday(&e_start, 0);
tm->start_elapsed = make_sec(&e_start);
#elif defined(_WIN32_WP)
tm->start_cpu = GetTickCount64() / 1000;
tm->start_elapsed = GetTickCount64() / 1000;
#elif defined(_WIN32_WCE)
/* No GetProcessTimes() on WinCE. (Note CPU time will be bogus) */
tm->start_cpu = GetTickCount() / 1000;
tm->start_elapsed = GetTickCount() / 1000;
#else
HANDLE pid;
FILETIME t_create, t_exit, kst, ust;
Expand All @@ -199,31 +172,22 @@ ptmr_stop(ptmr_t * tm)
{
float64 dt_cpu, dt_elapsed;

#if (! defined(_WIN32)) || defined(GNUWINCE) || defined(__SYMBIAN32__)
#if !defined(_WIN32)
/* Unix */
struct timeval e_stop; /* Elapsed time */

#if (! defined(_HPUX_SOURCE)) && (! defined(__SYMBIAN32__))
# if defined(HAVE_GETRUSAGE) && !defined(__EMSCRIPTEN__) /* Which LIES */
struct rusage stop; /* CPU time */

/* Unix but not HPUX */
getrusage(RUSAGE_SELF, &stop);
dt_cpu =
make_sec(&stop.ru_utime) + make_sec(&stop.ru_stime) -
tm->start_cpu;
#else
# else
dt_cpu = 0.0;
#endif
/* Unix + HP */
# endif
gettimeofday(&e_stop, 0);
dt_elapsed = (make_sec(&e_stop) - tm->start_elapsed);
#elif defined(_WIN32_WP)
dt_cpu = GetTickCount64() / 1000 - tm->start_cpu;
dt_elapsed = GetTickCount64() / 1000 - tm->start_elapsed;
#elif defined(_WIN32_WCE)
/* No GetProcessTimes() on WinCE. (Note CPU time will be bogus) */
dt_cpu = GetTickCount() / 1000 - tm->start_cpu;
dt_elapsed = GetTickCount() / 1000 - tm->start_elapsed;
#else
/* Windows */
HANDLE pid;
FILETIME t_create, t_exit, kst, ust;

Expand Down