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

Update core wasm32 typedefs to be compatible with reference-sysroot. #7799

Closed
Closed
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
2 changes: 1 addition & 1 deletion emscripten-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"1.38.21"
"1.38.22"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of bumping minor version, we should bump to 1.39.0, because this is a breaking ABI change. (like we did in #5916 (comment))

Copy link
Member

Choose a reason for hiding this comment

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

I'm not opposed to that, but I don't think we have a strict rule here - even minor version number updates can break ABI, e.g. with an LLVM update. I did agree in the linked issue that we should do a major one because it was a large change, and because it could be particularly confusing and error-prone, but in this PR here the change is minor (unless I'm missing something), so I don't feel strongly either way.

Copy link
Member

Choose a reason for hiding this comment

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

+1, I think this is worth bumping to 1.39
I don't recall whether we came to a strict rule but I hope we can eventually (soon) get to the point where we can have a strict rule of bumping the minor for ABI breaks.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good. Then we should land this with a minor version, wait to see we are reasonably stable, then bump the major version, as documented here: https://github.com/kripken/emscripten/blob/incoming/docs/process.md#major-version-update-1xy-to-1x10

21 changes: 12 additions & 9 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ LibraryManager.library = {
var time;
if (times) {
var offset = {{{ C_STRUCTS.timeval.__size__ }}} + {{{ C_STRUCTS.timeval.tv_sec }}};
time = {{{ makeGetValue('times', 'offset', 'i32') }}} * 1000;
time = {{{ makeGetValue('times', 'offset', 'i64') }}} * 1000;
offset = {{{ C_STRUCTS.timeval.__size__ }}} + {{{ C_STRUCTS.timeval.tv_usec }}};
time += {{{ makeGetValue('times', 'offset', 'i32') }}} / 1000;
time += {{{ makeGetValue('times', 'offset', 'i64') }}} / 1000;
} else {
time = Date.now();
}
Expand Down Expand Up @@ -1917,13 +1917,16 @@ LibraryManager.library = {
time: function(ptr) {
var ret = (Date.now()/1000)|0;
if (ptr) {
{{{ makeSetValue('ptr', 0, 'ret', 'i32') }}};
{{{ makeSetValue('ptr', 0, 'ret', 'i64') }}};
}
return ret;
},

difftime: function(time1, time0) {
return time1 - time0;
difftime: function(time1l, time1h, time0l, time0h) {
// For now, just support 32-bit time values.
assert(time0h == (time1l >> 31));
assert(time1h == (time1l >> 31));
return time1l - time0l;
},

// Statically allocated time struct.
Expand Down Expand Up @@ -2783,7 +2786,7 @@ LibraryManager.library = {
___setErrNo(ERRNO_CODES.EINVAL);
return -1;
}
{{{ makeSetValue('tp', C_STRUCTS.timespec.tv_sec, '(now/1000)|0', 'i32') }}}; // seconds
{{{ makeSetValue('tp', C_STRUCTS.timespec.tv_sec, '(now/1000)|0', 'i64') }}}; // seconds
{{{ makeSetValue('tp', C_STRUCTS.timespec.tv_nsec, '((now % 1000)*1000*1000)|0', 'i32') }}}; // nanoseconds
return 0;
},
Expand All @@ -2808,7 +2811,7 @@ LibraryManager.library = {
___setErrNo(ERRNO_CODES.EINVAL);
return -1;
}
{{{ makeSetValue('res', C_STRUCTS.timespec.tv_sec, '(nsec/1000000000)|0', 'i32') }}};
{{{ makeSetValue('res', C_STRUCTS.timespec.tv_sec, '(nsec/1000000000)|0', 'i64') }}};
{{{ makeSetValue('res', C_STRUCTS.timespec.tv_nsec, 'nsec', 'i32') }}} // resolution is nanoseconds
return 0;
},
Expand All @@ -2822,8 +2825,8 @@ LibraryManager.library = {
// http://pubs.opengroup.org/onlinepubs/000095399/basedefs/sys/time.h.html
gettimeofday: function(ptr) {
var now = Date.now();
{{{ makeSetValue('ptr', C_STRUCTS.timeval.tv_sec, '(now/1000)|0', 'i32') }}}; // seconds
{{{ makeSetValue('ptr', C_STRUCTS.timeval.tv_usec, '((now % 1000)*1000)|0', 'i32') }}}; // microseconds
{{{ makeSetValue('ptr', C_STRUCTS.timeval.tv_sec, '(now/1000)|0', 'i64') }}}; // seconds
{{{ makeSetValue('ptr', C_STRUCTS.timeval.tv_usec, '((now % 1000)*1000)|0', 'i64') }}}; // microseconds
return 0;
},

Expand Down
4 changes: 2 additions & 2 deletions src/library_pthread_stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ var LibraryPThreadStub = {
nanosleep__deps: ['usleep'],
nanosleep: function(rqtp, rmtp) {
// int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
var seconds = {{{ makeGetValue('rqtp', C_STRUCTS.timespec.tv_sec, 'i32') }}};
var seconds = {{{ makeGetValue('rqtp', C_STRUCTS.timespec.tv_sec, 'i64') }}};
var nanoseconds = {{{ makeGetValue('rqtp', C_STRUCTS.timespec.tv_nsec, 'i32') }}};
if (rmtp !== 0) {
{{{ makeSetValue('rmtp', C_STRUCTS.timespec.tv_sec, '0', 'i32') }}};
{{{ makeSetValue('rmtp', C_STRUCTS.timespec.tv_sec, '0', 'i64') }}};
{{{ makeSetValue('rmtp', C_STRUCTS.timespec.tv_nsec, '0', 'i32') }}};
}
return _usleep((seconds * 1e6) + (nanoseconds / 1000));
Expand Down
66 changes: 38 additions & 28 deletions src/library_syscall.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,26 @@ var SyscallsLibrary = {
}
throw e;
}
{{{ makeSetValue('buf', C_STRUCTS.stat.st_dev, 'stat.dev', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.__st_dev_padding, '0', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.__st_ino_truncated, 'stat.ino', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_dev, 'stat.dev', 'i64') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_ino, 'stat.ino', 'i64') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_nlink, 'stat.nlink', 'i64') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_mode, 'stat.mode', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_nlink, 'stat.nlink', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_uid, 'stat.uid', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_gid, 'stat.gid', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_rdev, 'stat.rdev', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.__st_rdev_padding, '0', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_size, 'stat.size', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_blksize, '4096', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_blocks, 'stat.blocks', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_atim.tv_sec, '(stat.atime.getTime() / 1000)|0', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.__pad0, '0', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_rdev, 'stat.rdev', 'i64') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_size, 'stat.size', 'i64') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_blksize, '4096', 'i64') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_blocks, 'stat.blocks', 'i64') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_atim.tv_sec, '(stat.atime.getTime() / 1000)|0', 'i64') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_atim.tv_nsec, '0', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_mtim.tv_sec, '(stat.mtime.getTime() / 1000)|0', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_mtim.tv_sec, '(stat.mtime.getTime() / 1000)|0', 'i64') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_mtim.tv_nsec, '0', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_ctim.tv_sec, '(stat.ctime.getTime() / 1000)|0', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_ctim.tv_sec, '(stat.ctime.getTime() / 1000)|0', 'i64') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_ctim.tv_nsec, '0', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.st_ino, 'stat.ino', 'i32') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.__unused, '0', 'i64') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.__unused+8, '0', 'i64') }}};
{{{ makeSetValue('buf', C_STRUCTS.stat.__unused+16, '0', 'i64') }}};
return 0;
},
doMsync: function(addr, stream, len, flags) {
Expand Down Expand Up @@ -218,8 +219,16 @@ var SyscallsLibrary = {
#endif // FILESYSTEM
get64: function() {
var low = SYSCALLS.get(), high = SYSCALLS.get();
if (low >= 0) assert(high === 0);
else assert(high === -1);
assert(high == (low >> 31));
#if SYSCALL_DEBUG
err(' (i64: "' + low + '")');
#endif
return low;
},
// Like get64, but read high first and low second.
get64reversed: function() {
var high = SYSCALLS.get(), low = SYSCALLS.get();
assert(high == (low >> 31));
#if SYSCALL_DEBUG
err(' (i64: "' + low + '")');
#endif
Expand Down Expand Up @@ -434,10 +443,10 @@ var SyscallsLibrary = {
#endif
var who = SYSCALLS.get(), usage = SYSCALLS.get();
_memset(usage, 0, {{{ C_STRUCTS.rusage.__size__ }}});
{{{ makeSetValue('usage', C_STRUCTS.rusage.ru_utime.tv_sec, '1', 'i32') }}}; // fake some values
{{{ makeSetValue('usage', C_STRUCTS.rusage.ru_utime.tv_usec, '2', 'i32') }}};
{{{ makeSetValue('usage', C_STRUCTS.rusage.ru_stime.tv_sec, '3', 'i32') }}};
{{{ makeSetValue('usage', C_STRUCTS.rusage.ru_stime.tv_usec, '4', 'i32') }}};
{{{ makeSetValue('usage', C_STRUCTS.rusage.ru_utime.tv_sec, '1', 'i64') }}}; // fake some values
{{{ makeSetValue('usage', C_STRUCTS.rusage.ru_utime.tv_usec, '2', 'i64') }}};
{{{ makeSetValue('usage', C_STRUCTS.rusage.ru_stime.tv_sec, '3', 'i64') }}};
{{{ makeSetValue('usage', C_STRUCTS.rusage.ru_stime.tv_usec, '4', 'i64') }}};
return 0;
},
__syscall83: function(which, varargs) { // symlink
Expand Down Expand Up @@ -718,11 +727,12 @@ var SyscallsLibrary = {
return 0;
},
__syscall140: function(which, varargs) { // llseek
var stream = SYSCALLS.getStreamFromFD(), offset_high = SYSCALLS.get(), offset_low = SYSCALLS.get(), result = SYSCALLS.get(), whence = SYSCALLS.get();
// NOTE: offset_high is unused - Emscripten's off_t is 32-bit
var offset = offset_low;
// Note that the llseek system call passes the offset with the high part
// before the low part, which differs from how 64-bit arguments are handled
// elsewhere, so we use get64reversed instead of plain get64.
var stream = SYSCALLS.getStreamFromFD(), offset = SYSCALLS.get64reversed(), result = SYSCALLS.get(), whence = SYSCALLS.get();
FS.llseek(stream, offset, whence);
{{{ makeSetValue('result', '0', 'stream.position', 'i32') }}};
{{{ makeSetValue('result', '0', 'stream.position', 'i64') }}};
if (stream.getdents && offset === 0 && whence === {{{ cDefine('SEEK_SET') }}}) stream.getdents = null; // reset readdir state
return 0;
},
Expand Down Expand Up @@ -926,7 +936,7 @@ var SyscallsLibrary = {
return 0; // just report no limits
},
__syscall192: function(which, varargs) { // mmap2
var addr = SYSCALLS.get(), len = SYSCALLS.get(), prot = SYSCALLS.get(), flags = SYSCALLS.get(), fd = SYSCALLS.get(), off = SYSCALLS.get()
var addr = SYSCALLS.get(), len = SYSCALLS.get(), prot = SYSCALLS.get(), flags = SYSCALLS.get(), fd = SYSCALLS.get(), off = SYSCALLS.get64()
off <<= 12; // undo pgoffset
var ptr;
var allocated = false;
Expand Down Expand Up @@ -1259,11 +1269,11 @@ var SyscallsLibrary = {
var dirfd = SYSCALLS.get(), path = SYSCALLS.getStr(), times = SYSCALLS.get(), flags = SYSCALLS.get();
assert(flags === 0);
path = SYSCALLS.calculateAt(dirfd, path);
var seconds = {{{ makeGetValue('times', C_STRUCTS.timespec.tv_sec, 'i32') }}};
var seconds = {{{ makeGetValue('times', C_STRUCTS.timespec.tv_sec, 'i64') }}};
var nanoseconds = {{{ makeGetValue('times', C_STRUCTS.timespec.tv_nsec, 'i32') }}};
var atime = (seconds*1000) + (nanoseconds/(1000*1000));
times += {{{ C_STRUCTS.timespec.__size__ }}};
seconds = {{{ makeGetValue('times', C_STRUCTS.timespec.tv_sec, 'i32') }}};
seconds = {{{ makeGetValue('times', C_STRUCTS.timespec.tv_sec, 'i64') }}};
nanoseconds = {{{ makeGetValue('times', C_STRUCTS.timespec.tv_nsec, 'i32') }}};
var mtime = (seconds*1000) + (nanoseconds/(1000*1000));
FS.utime(path, atime, mtime);
Expand Down Expand Up @@ -1291,14 +1301,14 @@ var SyscallsLibrary = {
#if SYSCALL_DEBUG
err('warning: untested syscall');
#endif
var stream = SYSCALLS.getStreamFromFD(), iov = SYSCALLS.get(), iovcnt = SYSCALLS.get(), offset = SYSCALLS.get();
var stream = SYSCALLS.getStreamFromFD(), iov = SYSCALLS.get(), iovcnt = SYSCALLS.get(), offset = SYSCALLS.get64();
return SYSCALLS.doReadv(stream, iov, iovcnt, offset);
},
__syscall334: function(which, varargs) { // pwritev
#if SYSCALL_DEBUG
err('warning: untested syscall');
#endif
var stream = SYSCALLS.getStreamFromFD(), iov = SYSCALLS.get(), iovcnt = SYSCALLS.get(), offset = SYSCALLS.get();
var stream = SYSCALLS.getStreamFromFD(), iov = SYSCALLS.get(), iovcnt = SYSCALLS.get(), offset = SYSCALLS.get64();
return SYSCALLS.doWritev(stream, iov, iovcnt, offset);
},
__syscall337: function(which, varargs) { // recvmmsg
Expand Down
11 changes: 5 additions & 6 deletions src/struct_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@
"structs": {
"stat": [
"st_dev",
"__st_dev_padding",
"__st_ino_truncated",
"st_mode",
"st_ino",
"st_nlink",
"st_mode",
"st_uid",
"st_gid",
"__pad0",
"st_rdev",
"__st_rdev_padding",
"st_size",
"st_blksize",
"st_blocks",
Expand All @@ -75,8 +74,8 @@
"tv_sec",
"tv_nsec"
]
},
"st_ino"
},
"__unused"
]
}
},
Expand Down
24 changes: 12 additions & 12 deletions system/lib/libc/musl/arch/emscripten/bits/alltypes.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#define _Addr __PTRDIFF_TYPE__
#define _Int64 __INT64_TYPE__
#define _Reg __PTRDIFF_TYPE__
#define _Reg __INT64_TYPE__

#if __GNUC__ >= 3
#if defined(__NEED_va_list) && !defined(__DEFINED_va_list)
Expand Down Expand Up @@ -35,14 +35,14 @@ typedef __WCHAR_TYPE__ wchar_t;

#else
#if defined(__NEED_wchar_t) && !defined(__DEFINED_wchar_t)
typedef long wchar_t;
typedef int wchar_t;
#define __DEFINED_wchar_t
#endif

#endif
#endif
#if defined(__NEED_wint_t) && !defined(__DEFINED_wint_t)
typedef unsigned wint_t;
typedef int wint_t;
#define __DEFINED_wint_t
#endif

Expand Down Expand Up @@ -72,12 +72,12 @@ typedef long double double_t;
#endif

#if defined(__NEED_time_t) && !defined(__DEFINED_time_t)
typedef long time_t;
typedef long long time_t;
#define __DEFINED_time_t
#endif

#if defined(__NEED_suseconds_t) && !defined(__DEFINED_suseconds_t)
typedef long suseconds_t;
typedef long long suseconds_t;
#define __DEFINED_suseconds_t
#endif

Expand Down Expand Up @@ -219,17 +219,17 @@ typedef unsigned _Reg nlink_t;
#endif

#if defined(__NEED_off_t) && !defined(__DEFINED_off_t)
typedef int off_t;
typedef long long off_t;
#define __DEFINED_off_t
#endif

#if defined(__NEED_ino_t) && !defined(__DEFINED_ino_t)
typedef unsigned int ino_t;
typedef unsigned long long ino_t;
#define __DEFINED_ino_t
#endif

#if defined(__NEED_dev_t) && !defined(__DEFINED_dev_t)
typedef unsigned int dev_t;
typedef unsigned long long dev_t;
#define __DEFINED_dev_t
#endif

Expand All @@ -239,22 +239,22 @@ typedef long blksize_t;
#endif

#if defined(__NEED_blkcnt_t) && !defined(__DEFINED_blkcnt_t)
typedef int blkcnt_t;
typedef long long blkcnt_t;
#define __DEFINED_blkcnt_t
#endif

#if defined(__NEED_fsblkcnt_t) && !defined(__DEFINED_fsblkcnt_t)
typedef unsigned int fsblkcnt_t;
typedef unsigned long long fsblkcnt_t;
#define __DEFINED_fsblkcnt_t
#endif

#if defined(__NEED_fsfilcnt_t) && !defined(__DEFINED_fsfilcnt_t)
typedef unsigned int fsfilcnt_t;
typedef unsigned long long fsfilcnt_t;
#define __DEFINED_fsfilcnt_t
#endif

#if defined(__NEED_wint_t) && !defined(__DEFINED_wint_t)
typedef unsigned wint_t;
typedef int wint_t;
#define __DEFINED_wint_t
#endif

Expand Down
10 changes: 5 additions & 5 deletions system/lib/libc/musl/arch/emscripten/bits/alltypes.h.in
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#define _Addr __PTRDIFF_TYPE__
#define _Int64 __INT64_TYPE__
#define _Reg __PTRDIFF_TYPE__
#define _Reg __INT64_TYPE__

TYPEDEF __builtin_va_list va_list;
TYPEDEF __builtin_va_list __isoc_va_list;

#ifndef __cplusplus
TYPEDEF unsigned wchar_t;
TYPEDEF int wchar_t;
#endif
TYPEDEF unsigned wint_t;
TYPEDEF int wint_t;

TYPEDEF float float_t;
TYPEDEF double double_t;

TYPEDEF long time_t;
TYPEDEF long suseconds_t;
TYPEDEF long long time_t;
TYPEDEF long long suseconds_t;

TYPEDEF struct { union { int __i[10]; unsigned __s[10]; } __u; } pthread_attr_t;
TYPEDEF struct { union { int __i[7]; void *__p[7]; } __u; } pthread_mutex_t;
Expand Down
20 changes: 12 additions & 8 deletions system/lib/libc/musl/arch/emscripten/bits/stat.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
/* copied from kernel definition, but with padding replaced
* by the corresponding correctly-sized userspace types. */

/*
* This definition happens to match the x32 and x86-64 stat layouts.
* Direct compatibility with them isn't essential, but they are good
* examples to follow. Note that there's no implicit padding, and
* there's room for future expansion.
*/
struct stat
Copy link
Contributor

@rianhunter rianhunter Jan 3, 2019

Choose a reason for hiding this comment

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

what struct stat definition is this mirroring? is it the stat used in the x32 linux ABI?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it's the x32 linux ABI. I've now added a comment.

{
dev_t st_dev;
int __st_dev_padding;
long __st_ino_truncated;
mode_t st_mode;
ino_t st_ino;
nlink_t st_nlink;

mode_t st_mode;
uid_t st_uid;
gid_t st_gid;
unsigned int __pad0;
dev_t st_rdev;
int __st_rdev_padding;
off_t st_size;
blksize_t st_blksize;
blkcnt_t st_blocks;

struct timespec st_atim;
struct timespec st_mtim;
struct timespec st_ctim;
ino_t st_ino;
long long __unused[3];
};
Binary file modified tests/python/python.bc
Binary file not shown.
Loading