From 193d1a864f732b8589243d93dfa2fbb4f08f45e5 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 2 Jul 2024 23:55:51 -0700 Subject: [PATCH 1/3] Document `qjsc -s` flag in help output The `-s` flag added in #388 was missing in the `-h` help output. --- qjsc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/qjsc.c b/qjsc.c index f9a07db5..95a22d66 100644 --- a/qjsc.c +++ b/qjsc.c @@ -332,6 +332,7 @@ void help(void) "-D module_name compile a dynamically loaded module or worker\n" "-M module_name[,cname] add initialization code for an external C module\n" "-p prefix set the prefix of the generated C names\n" + "-s strip the source code, specify twice to also strip debug info\n" "-S n set the maximum stack size to 'n' bytes (default=%d)\n", JS_GetVersion(), JS_DEFAULT_STACK_SIZE); From ba9b4a82ec72470b10fcc549750e06b49b4b4b58 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Wed, 3 Jul 2024 00:51:30 -0700 Subject: [PATCH 2/3] Add `qjsc -n` parameter to override script name stored in bytecode (#459) --- qjsc.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/qjsc.c b/qjsc.c index 95a22d66..33c6cf4e 100644 --- a/qjsc.c +++ b/qjsc.c @@ -261,6 +261,7 @@ JSModuleDef *jsc_module_loader(JSContext *ctx, static void compile_file(JSContext *ctx, FILE *fo, const char *filename, + const char *script_name, const char *c_name1, int module) { @@ -284,7 +285,7 @@ static void compile_file(JSContext *ctx, FILE *fo, eval_flags |= JS_EVAL_TYPE_MODULE; else eval_flags |= JS_EVAL_TYPE_GLOBAL; - obj = JS_Eval(ctx, (const char *)buf, buf_len, filename, eval_flags); + obj = JS_Eval(ctx, (const char *)buf, buf_len, script_name ? script_name : filename, eval_flags); if (JS_IsException(obj)) { js_std_dump_error(ctx); exit(1); @@ -327,6 +328,7 @@ void help(void) "options are:\n" "-e output main() and bytecode in a C file\n" "-o output set the output filename\n" + "-n script_name set the script name (as used in stack traces)\n" "-N cname set the C name of the generated data\n" "-m compile as Javascript module (default=autodetect)\n" "-D module_name compile a dynamically loaded module or worker\n" @@ -347,7 +349,7 @@ typedef enum { int main(int argc, char **argv) { int c, i, verbose; - const char *out_filename, *cname; + const char *out_filename, *cname, *script_name; char cfilename[1024]; FILE *fo; JSRuntime *rt; @@ -358,6 +360,7 @@ int main(int argc, char **argv) namelist_t dynamic_module_list; out_filename = NULL; + script_name = NULL; output_type = OUTPUT_C; cname = NULL; module = -1; @@ -371,7 +374,7 @@ int main(int argc, char **argv) namelist_add(&cmodule_list, "os", "os", 0); for(;;) { - c = getopt(argc, argv, "ho:N:mxesvM:p:S:D:"); + c = getopt(argc, argv, "ho:N:mn:mxesvM:p:S:D:"); if (c == -1) break; switch(c) { @@ -383,6 +386,9 @@ int main(int argc, char **argv) case 'e': output_type = OUTPUT_C_MAIN; break; + case 'n': + script_name = optarg; + break; case 'N': cname = optarg; break; @@ -462,7 +468,7 @@ int main(int argc, char **argv) for(i = optind; i < argc; i++) { const char *filename = argv[i]; - compile_file(ctx, fo, filename, cname, module); + compile_file(ctx, fo, filename, script_name, cname, module); cname = NULL; } From 76f99007f784fcf716908abd6ccd87290db890d9 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Wed, 3 Jul 2024 03:00:20 +0300 Subject: [PATCH 3/3] Reduce duplication in Linux and MacOS CI file, improve flexibility --- .github/workflows/ci.yml | 384 +++++++++++---------------------------- 1 file changed, 108 insertions(+), 276 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 860818a0..2fd5d852 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,93 +24,137 @@ jobs: make codegen - name: Check if the git repository is clean run: $(exit $(git status --porcelain --untracked-files=no | head -255 | wc -l)) || (echo "Dirty git tree"; git diff; exit 1) - linux: - runs-on: ubuntu-latest + + ci: + runs-on: ${{ matrix.config.os }} + name: ${{ matrix.config.os }} (${{ matrix.config.configType }}${{ matrix.config.arch }}) + env: + ASAN_OPTIONS: halt_on_error=1 + MSAN_OPTIONS: halt_on_error=1 + UBSAN_OPTIONS: halt_on_error=1 + defaults: + run: + shell: ${{ matrix.config.arch == '' && 'sh' || 'alpine.sh' }} {0} + strategy: fail-fast: false matrix: - buildType: [Debug, Release] + config: + - { os: ubuntu-latest, configType: Debug } + - { os: ubuntu-latest, configType: Release, runTest262: true, runV8: true } + - { os: ubuntu-latest, configType: examples } + - { os: ubuntu-latest, configType: shared } + - { os: ubuntu-latest, configType: asan, runTest262: true } + - { os: ubuntu-latest, configType: ubsan, runTest262: true } + - { os: ubuntu-latest, configType: msan } + - { os: ubuntu-latest, configType: tcc } + - { os: ubuntu-latest, arch: x86 } + - { os: ubuntu-latest, arch: riscv64 } + - { os: ubuntu-latest, arch: s390x } + + - { os: macos-14, configType: Debug } + - { os: macos-14, configType: Release } + - { os: macos-14, configType: examples } + - { os: macos-14, configType: shared } + - { os: macos-14, configType: asan } + - { os: macos-14, configType: ubsan } + + - { os: macos-12, configType: Debug } + - { os: macos-12, configType: Release } + - { os: macos-12, configType: examples } + - { os: macos-12, configType: shared } + - { os: macos-12, configType: asan } + - { os: macos-12, configType: ubsan } steps: - uses: actions/checkout@v4 with: submodules: true - - name: build - run: | - make BUILD_TYPE=${{matrix.buildType}} - - name: stats - run: | - make stats - - name: test - run: | - make test - - name: test 262 - if: ${{ matrix.buildType == 'Release' }} - run: | - time make test262 - - name: test v8 mjsunit - if: ${{ matrix.buildType == 'Release' }} + + # ASLR with big PIE slides does not work well with [AM]San + - name: disable ASLR + if: ${{ matrix.config.os == 'ubuntu-latest' && (matrix.config.configType == 'asan' || matrix.config.configType == 'ubsan' || matrix.config.configType == 'msan')}} run: | - ./v8.sh - linux-32bits: - runs-on: ubuntu-latest - defaults: - run: - shell: alpine.sh {0} - steps: - - uses: actions/checkout@v4 - - uses: jirutka/setup-alpine@v1 - with: - arch: x86 - packages: "build-base make cmake" - - name: build + sudo sysctl -w kernel.randomize_va_space=0 + + - name: install TCC + if: ${{ matrix.config.configType == 'tcc' }} run: | + pushd /tmp + git clone https://repo.or.cz/tinycc.git + cd tinycc + git checkout 9d2068c6309dc50dfdbbc30a5d6757683d3f884c + ./configure make - - name: stats - run: | - make stats - - name: test - run: | - make test - linux-riscv64: - runs-on: ubuntu-latest - defaults: - run: - shell: alpine.sh {0} - steps: - - uses: actions/checkout@v3 - - uses: jirutka/setup-alpine@v1 + sudo make install + tcc -v + popd + echo "CC=tcc" >> $GITHUB_ENV; + + - name: Setup Alpine + if: ${{ matrix.config.arch != '' }} + uses: jirutka/setup-alpine@v1 with: - arch: riscv64 + arch: ${{ matrix.config.arch }} packages: "build-base make cmake" + + - name: Set build ENV vars + run: | + if [ "${{ matrix.config.configType }}" = "Debug" ]; then + echo "BUILD_TYPE=Debug" >> $GITHUB_ENV; + elif [ "${{ matrix.config.configType }}" = "examples" ]; then + echo "BUILD_EXAMPLES=ON" >> $GITHUB_ENV; + elif [ "${{ matrix.config.configType }}" = "shared" ]; then + echo "BUILD_SHARED_LIBS=ON" >> $GITHUB_ENV; + elif [ "${{ matrix.config.configType }}" = "asan" ]; then + echo "CONFIG_ASAN=ON" >> $GITHUB_ENV; + elif [ "${{ matrix.config.configType }}" = "ubsan" ]; then + echo "CONFIG_UBSAN=ON" >> $GITHUB_ENV; + elif [ "${{ matrix.config.configType }}" = "msan" ]; then + echo "CONFIG_MSAN=ON" >> $GITHUB_ENV; + echo "CC=clang" >> $GITHUB_ENV; + fi + - name: build run: | - make + make \ + BUILD_TYPE=$BUILD_TYPE \ + BUILD_EXAMPLES=$BUILD_EXAMPLES \ + BUILD_SHARED_LIBS=$BUILD_SHARED_LIBS \ + CONFIG_ASAN=$CONFIG_ASAN \ + CONFIG_UBSAN=$CONFIG_UBSAN \ + CONFIG_MSAN=$CONFIG_MSAN + - name: stats + if: ${{ matrix.config.configType != 'examples' }} run: | make stats + - name: test + if: ${{ matrix.config.configType != 'examples' }} run: | make test - linux-s390x: - runs-on: ubuntu-latest - defaults: - run: - shell: alpine.sh {0} - steps: - - uses: actions/checkout@v3 - - uses: jirutka/setup-alpine@v1 - with: - arch: s390x - packages: "build-base make cmake" - - name: build + + - name: test examples + if: ${{ matrix.config.configType == 'examples' }} run: | - make - - name: stats + cp build/fib.so examples/ + cp build/point.so examples/ + cp build/bjson.so tests/ + ./build/qjs examples/test_fib.js + ./build/qjs examples/test_point.js + ./build/qjs tests/test_bjson.js + ./build/function_source + + - name: test 262 + if: ${{ matrix.config.runTest262 }} run: | - make stats - - name: test + time make test262 + + - name: test v8 mjsunit + if: ${{ matrix.config.runV8 }} run: | - make test + ./v8.sh + linux-gcc48: runs-on: ubuntu-latest container: @@ -138,218 +182,6 @@ jobs: - name: stats run: | ./build/qjs -qd - linux-examples: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: build - run: | - make BUILD_EXAMPLES=ON - - name: test - run: | - ldd build/hello - ldd build/hello_module - ldd build/test_fib - ./build/hello - ./build/hello_module - ./build/test_fib - cp build/fib.so examples/ - cp build/point.so examples/ - cp build/bjson.so tests/ - ./build/qjs examples/test_fib.js - ./build/qjs examples/test_point.js - ./build/qjs tests/test_bjson.js - ./build/function_source - linux-shared: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: build - run: | - make BUILD_SHARED_LIBS=ON - ldd build/qjs - - name: stats - run: | - make stats - linux-asan: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: true - # ASLR with big PIE slides does not work well with [AM]San - - name: disable ASLR - run: | - sudo sysctl -w kernel.randomize_va_space=0 - - name: build - run: | - make CONFIG_ASAN=ON - - name: test - env: - ASAN_OPTIONS: halt_on_error=1 - run: | - make test - - name: test 262 - env: - ASAN_OPTIONS: halt_on_error=1 - run: | - time make test262 - linux-msan: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: true - # ASLR with big PIE slides does not work well with [AM]San - - name: disable ASLR - run: | - sudo sysctl -w kernel.randomize_va_space=0 - - name: build - env: - CC: clang - run: | - make CONFIG_MSAN=ON - - name: test - env: - MSAN_OPTIONS: halt_on_error=1 - run: | - make test - linux-ubsan: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - name: build - run: | - make CONFIG_UBSAN=ON - - name: test - env: - UBSAN_OPTIONS: halt_on_error=1 - run: | - make test - - name: test 262 - env: - UBSAN_OPTIONS: halt_on_error=1 - run: | - time make test262 - linux-tcc: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - name: install TCC - run: | - pushd /tmp - git clone https://repo.or.cz/tinycc.git - cd tinycc - git checkout 9d2068c6309dc50dfdbbc30a5d6757683d3f884c - ./configure - make - sudo make install - tcc -v - popd - - name: build - env: - CC: tcc - run: | - make - - name: stats - run: | - make stats - - macos: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - buildType: [Debug, Release] - os: [macos-12, macos-14] - steps: - - uses: actions/checkout@v4 - - name: build - run: | - make BUILD_TYPE=${{matrix.buildType}} - - name: stats - run: | - make stats - - name: test - run: | - make test - macos-examples: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [macos-12, macos-14] - steps: - - uses: actions/checkout@v4 - - name: build - run: | - make BUILD_EXAMPLES=ON - - name: test - run: | - otool -L build/hello - otool -L build/hello_module - otool -L build/test_fib - ./build/hello - ./build/hello_module - ./build/test_fib - cp build/fib.so examples/ - cp build/point.so examples/ - cp build/bjson.so tests/ - ./build/qjs examples/test_fib.js - ./build/qjs examples/test_point.js - ./build/qjs tests/test_bjson.js - ./build/function_source - macos-shared: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [macos-12, macos-14] - steps: - - uses: actions/checkout@v4 - - name: build - run: | - make BUILD_SHARED_LIBS=ON - otool -L build/qjs - - name: stats - run: | - make stats - macos-asan: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [macos-12, macos-14] - steps: - - uses: actions/checkout@v4 - - name: build - run: | - make CONFIG_ASAN=ON - - name: test - env: - ASAN_OPTIONS: halt_on_error=1 - run: | - make test - macos-ubsan: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [macos-12, macos-14] - steps: - - uses: actions/checkout@v4 - - name: build - run: | - make CONFIG_UBSAN=ON - - name: test - env: - UBSAN_OPTIONS: halt_on_error=1 - run: | - make test windows-msvc: runs-on: windows-latest