-
Notifications
You must be signed in to change notification settings - Fork 677
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
Add support for init/fini arrays to libc #1725
Add support for init/fini arrays to libc #1725
Conversation
This patch is a proposed solution for #1722. The constructor/destructor behavior can be tested, e.g., by adding the below two functions anywhere in the compiled sources. (For my experiments, I've copied them into static void __attribute__ ((constructor))
start_jerry (void)
{
printf ("JERRY STARTED\n");
}
static void __attribute__ ((destructor))
finish_jerry (void)
{
printf ("JERRY FINISHED\n");
} If configured properly, $ ./tools/build.py --clean --cmake-param="-DFEATURE_INIT_FINI=ON" --toolchain cmake/toolchain_linux_armv7l.cmake
$ file ./build/bin/jerry
./build/bin/jerry: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, BuildID[sha1]=5863cc6fdcdcf956d6910a266f7ce583fd20c995, stripped
$ qemu-arm-static ./build/bin/jerry ./tests/hello.js
JERRY STARTED
Hello JerryScript!
JERRY FINISHED It also works on x86-64: $ ./tools/build.py --clean --cmake-param="-DFEATURE_INIT_FINI=ON"
$ file ./build/bin/jerry
./build/bin/jerry: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=73dba6c37fed7aa9aea19b533e76f1d2bfcf28e2, stripped
$ ./build/bin/jerry ./tests/hello.js
JERRY STARTED
Hello JerryScript!
JERRY FINISHED Sanity check: if the feature is not enabled in jerry-libc, the constructors/destructors don't run. $ ./tools/build.py --clean
$ ./build/bin/jerry ./tests/hello.js
Hello JerryScript! Note 1: Haven't tested on x86. Note 2: Had to modify cppcheck suppression list, as cppcheck incorrectly reported
|
An additional sanity check: the enhanced jerry-libc works just like the system libc (which needs no extra feature switches, of course). $ ./tools/build.py --clean --jerry-libc=off --jerry-libm=off --static-link=off --link-lib="-lm"
$ file ./build/bin/jerry
./build/bin/jerry: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=138ef44c61b06bb6fe7f5b0b36be1994b6b4d2c0, stripped
$ ./build/bin/jerry ./tests/hello.js
JERRY STARTED
Hello JerryScript!
JERRY FINISHED |
Super-awesome 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
jerry-libc/jerry-libc-init.c
Outdated
extern void _fini (void); | ||
|
||
|
||
/** No-op default _init. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function header comment is different for libc functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might have been sloppy. Will get it right asap.
The arrays contain the addresses of functions annotated with constructor or destructor attributes. The support is optional, requires FEATURE_INIT_FINI cmake option to be set. As of now, the option is _not_ available in tools/build.py directly, only via `--cmake-param="-DFEATURE_INIT_FINI=ON"`. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss [email protected]
3a20c14
to
1d2ec78
Compare
I've fixed the function doc comments in the new file and updated the commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The arrays contain the addresses of functions annotated with
constructor or destructor attributes. The support is optional,
requires FEATURE_INIT_FINI cmake option to be set. As of now, the
option is not available in tools/build.py directly, only via
--cmake-param="-DFEATURE_INIT_FINI=ON"
.JerryScript-DCO-1.0-Signed-off-by: Akos Kiss [email protected]