Skip to content

Commit

Permalink
[rebase this later] Try to compile on windows as well
Browse files Browse the repository at this point in the history
  • Loading branch information
ludfjig committed Dec 5, 2024
1 parent 470aef4 commit 82dac3f
Show file tree
Hide file tree
Showing 21 changed files with 34 additions and 44 deletions.
12 changes: 3 additions & 9 deletions src/hyperlight_guest/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,7 @@ fn cargo_main() {
feature = "libc",
feature = "alloca"
)) {
if is_pe {
cfg.define("hidden", "");
cfg.define("weak_alias(old, new) ", " ");
cfg.define("__DEFINED_va_list", None);
cfg.define("__DEFINED___isoc_va_list", None);
}
cfg.define("__x86_64__", None);
cfg.define("__LITTLE_ENDIAN__", None);
cfg.define("HYPERLIGHT", None);
cfg.define("HYPERLIGHT", None); // used in certain musl files for conditional compilation

// silence compiler warnings
cfg.flag("-Wno-unused-command-line-argument") // including .s files makes clang believe arguments are unused
Expand All @@ -99,6 +91,8 @@ fn cargo_main() {
.flag("-Wno-string-plus-int");

if is_pe {
cfg.flag("-Wno-unused-label");
cfg.flag("-Wno-unused-variable");
cfg.compiler("clang-cl");
} else {
cfg.flag("-fPIC");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@

#ifndef __cplusplus
#if defined(__NEED_wchar_t) && !defined(__DEFINED_wchar_t)
#ifdef _MSC_VER
typedef unsigned short wchar_t;
#else
typedef int wchar_t;
#endif
#define __DEFINED_wchar_t
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@
#define FLT_EVAL_METHOD 0
#endif

#ifdef _MSC_VER
#define LDBL_TRUE_MIN 4.9406564584124654e-324
#define LDBL_MIN 2.2250738585072014e-308
#define LDBL_MAX 1.7976931348623158e+308
#define LDBL_EPSILON 2.2204460492503131e-016

#define LDBL_MANT_DIG 53
#define LDBL_MIN_EXP (-1021)
#define LDBL_MAX_EXP 1024

#define LDBL_DIG 15
#define LDBL_MIN_10_EXP (-307)
#define LDBL_MAX_10_EXP308

#define DECIMAL_DIG 17
#else
#define LDBL_TRUE_MIN 3.6451995318824746025e-4951L
#define LDBL_MIN 3.3621031431120935063e-4932L
#define LDBL_MAX 1.1897314953572317650e+4932L
Expand All @@ -18,3 +34,4 @@
#define LDBL_MAX_10_EXP 4932

#define DECIMAL_DIG 21
#endif
2 changes: 1 addition & 1 deletion src/hyperlight_guest/third_party/libc/musl/include/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern "C" {
#define __NEED_double_t
#include <bits/alltypes.h>

#if 100*__GNUC__+__GNUC_MINOR__ >= 303
#if 100*__GNUC__+__GNUC_MINOR__ >= 303 || defined (HYPERLIGHT)
#define NAN __builtin_nanf("")
#define INFINITY __builtin_inff()
#else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.global feclearexcept
.type feclearexcept,@function
feclearexcept:
# maintain exceptions in the sse mxcsr, clear x87 exceptions
mov %edi,%ecx
Expand All @@ -20,7 +19,6 @@ feclearexcept:
ret

.global feraiseexcept
.type feraiseexcept,@function
feraiseexcept:
and $0x3f,%edi
stmxcsr -8(%rsp)
Expand All @@ -30,8 +28,6 @@ feraiseexcept:
ret

.global __fesetround
.hidden __fesetround
.type __fesetround,@function
__fesetround:
push %rax
xor %eax,%eax
Expand All @@ -49,7 +45,6 @@ __fesetround:
ret

.global fegetround
.type fegetround,@function
fegetround:
push %rax
stmxcsr (%rsp)
Expand All @@ -59,15 +54,13 @@ fegetround:
ret

.global fegetenv
.type fegetenv,@function
fegetenv:
xor %eax,%eax
fnstenv (%rdi)
stmxcsr 28(%rdi)
ret

.global fesetenv
.type fesetenv,@function
fesetenv:
xor %eax,%eax
inc %rdi
Expand All @@ -86,7 +79,6 @@ fesetenv:
ret

.global fetestexcept
.type fetestexcept,@function
fetestexcept:
and $0x3f,%edi
push %rax
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@

#include "../../include/features.h"

#ifndef _MSC_VER
#define weak __attribute__((__weak__))
#define hidden __attribute__((__visibility__("hidden")))

#define weak_alias(old, new) \
extern __typeof(old) new __attribute__((__weak__, __alias__(#old)))
#endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
#define _STDIO_IMPL_H

#include <stdio.h>
#ifndef HYPERLIGHT
#include "syscall.h"

#define UNGET 8

#define FFINALLOCK(f) ((f)->lock>=0 ? __lockfile((f)) : 0)
#define FLOCK(f) int __need_unlock = ((f)->lock>=0 ? __lockfile((f)) : 0)
#define FUNLOCK(f) do { if (__need_unlock) __unlockfile((f)); } while (0)
#endif // HYPERLIGHT

#define F_PERM 1
#define F_NORD 4
Expand Down Expand Up @@ -47,6 +49,11 @@ struct _IO_FILE {
struct __locale_struct *locale;
};

hidden int __toread(FILE *);
hidden int __towrite(FILE *);
int __uflow(FILE *);

#ifndef HYPERLIGHT
extern hidden FILE *volatile __stdin_used;
extern hidden FILE *volatile __stdout_used;
extern hidden FILE *volatile __stderr_used;
Expand All @@ -60,16 +67,13 @@ hidden size_t __stdout_write(FILE *, const unsigned char *, size_t);
hidden off_t __stdio_seek(FILE *, off_t, int);
hidden int __stdio_close(FILE *);

hidden int __toread(FILE *);
hidden int __towrite(FILE *);

hidden void __stdio_exit(void);
hidden void __stdio_exit_needed(void);

#if defined(__PIC__) && (100*__GNUC__+__GNUC_MINOR__ >= 303)
__attribute__((visibility("protected")))
#endif
int __overflow(FILE *, int), __uflow(FILE *);
int __overflow(FILE *, int);

hidden int __fseeko(FILE *, off_t, int);
hidden int __fseeko_unlocked(FILE *, off_t, int);
Expand Down Expand Up @@ -110,3 +114,4 @@ hidden FILE *__fopen_rb_ca(const char *, FILE *, unsigned char *, size_t);
hidden int __fclose_ca(FILE *);

#endif
#endif
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# see ../i386/acos.s

.global acosl
.type acosl,@function
acosl:
fldt 8(%rsp)
1: fld %st(0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.global asinl
.type asinl,@function
asinl:
fldt 8(%rsp)
1: fld %st(0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.global atan2l
.type atan2l,@function
atan2l:
fldt 8(%rsp)
fldt 24(%rsp)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.global atanl
.type atanl,@function
atanl:
fldt 8(%rsp)
fld1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.global expm1l
.type expm1l,@function
expm1l:
fldt 8(%rsp)
fldl2e
Expand Down Expand Up @@ -28,7 +27,6 @@ expm1l:
ret

.global exp2l
.type exp2l,@function
exp2l:
fldt 8(%rsp)
1: fld %st(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# using the exact multiplication method of Dekker and Veltkamp

.global expl
.type expl,@function
expl:
fldt 8(%rsp)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.global floorl
.type floorl,@function
floorl:
fldt 8(%rsp)
1: mov $0x7,%al
Expand All @@ -13,14 +12,12 @@ floorl:
ret

.global ceill
.type ceill,@function
ceill:
fldt 8(%rsp)
mov $0xb,%al
jmp 1b

.global truncl
.type truncl,@function
truncl:
fldt 8(%rsp)
mov $0xf,%al
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.global log10l
.type log10l,@function
log10l:
fldlg2
fldt 8(%rsp)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.global log1pl
.type log1pl,@function
log1pl:
mov 14(%rsp),%eax
fldln2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.global log2l
.type log2l,@function
log2l:
fld1
fldt 8(%rsp)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.global logl
.type logl,@function
logl:
fldln2
fldt 8(%rsp)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
.global memcpy
.global __memcpy_fwd
.hidden __memcpy_fwd
.type memcpy,@function
memcpy:
__memcpy_fwd:
mov %rdi,%rax
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
.global memmove
.type memmove,@function
memmove:
mov %rdi,%rax
sub %rsi,%rax
cmp %rdx,%rax
.hidden __memcpy_fwd
jae __memcpy_fwd
mov %rdx,%rcx
lea -1(%rdi,%rdx),%rdi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.global memset
.type memset,@function
memset:
movzbq %sil,%rax
mov $0x101010101010101,%r8
Expand Down

0 comments on commit 82dac3f

Please sign in to comment.