Skip to content

Commit 93bddb5

Browse files
RafaelGSSsantigimeno
authored andcommitted
build,tools: add test-ubsan ci
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com> Co-Authored-By: Santiago Gimeno <santiago.gimeno@gmail.com> PR-URL: #46297 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Jan Krems <jan.krems@gmail.com>
1 parent 6930205 commit 93bddb5

File tree

7 files changed

+110
-2
lines changed

7 files changed

+110
-2
lines changed

.github/workflows/test-ubsan.yml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Test UBSan
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, ready_for_review]
6+
paths-ignore:
7+
- .mailmap
8+
- '**.md'
9+
- AUTHORS
10+
- doc/**
11+
- .github/**
12+
- '!.github/workflows/ubsan-asan.yml'
13+
push:
14+
branches:
15+
- main
16+
- canary
17+
- v[0-9]+.x-staging
18+
- v[0-9]+.x
19+
paths-ignore:
20+
- .mailmap
21+
- '**.md'
22+
- AUTHORS
23+
- doc/**
24+
- .github/**
25+
- '!.github/workflows/ubsan-asan.yml'
26+
27+
concurrency:
28+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
29+
cancel-in-progress: true
30+
31+
env:
32+
PYTHON_VERSION: '3.11'
33+
FLAKY_TESTS: keep_retrying
34+
35+
permissions:
36+
contents: read
37+
38+
jobs:
39+
test-ubsan:
40+
if: github.event.pull_request.draft == false
41+
runs-on: ubuntu-20.04
42+
env:
43+
CC: gcc
44+
CXX: g++
45+
LINK: g++
46+
CONFIG_FLAGS: --enable-ubsan
47+
steps:
48+
- uses: actions/checkout@v3
49+
with:
50+
persist-credentials: false
51+
- name: Store suppressions path
52+
run: |
53+
echo "UBSAN_OPTIONS=suppressions=$GITHUB_WORKSPACE/suppressions.supp" >> $GITHUB_ENV
54+
- name: Set up Python ${{ env.PYTHON_VERSION }}
55+
uses: actions/setup-python@v4
56+
with:
57+
python-version: ${{ env.PYTHON_VERSION }}
58+
- name: Environment Information
59+
run: npx envinfo
60+
- name: Build
61+
run: make build-ci -j2 V=1
62+
- name: Test
63+
run: make run-ci -j2 V=1 TEST_CI_ARGS="-p actions -t 300 --measure-flakiness 9"

common.gypi

+24
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
'variables': {
33
'configuring_node%': 0,
44
'asan%': 0,
5+
'ubsan%': 0,
56
'werror': '', # Turn off -Werror in V8 build.
67
'visibility%': 'hidden', # V8's visibility setting
78
'target_arch%': 'ia32', # set v8's target architecture
@@ -374,6 +375,29 @@
374375
}],
375376
],
376377
}],
378+
['ubsan == 1 and OS != "mac" and OS != "zos"', {
379+
'cflags+': [
380+
'-fno-omit-frame-pointer',
381+
'-fsanitize=undefined',
382+
],
383+
'defines': [ 'UNDEFINED_SANITIZER'],
384+
'cflags!': [ '-fno-omit-frame-pointer' ],
385+
'ldflags': [ '-fsanitize=undefined' ],
386+
}],
387+
['ubsan == 1 and OS == "mac"', {
388+
'xcode_settings': {
389+
'OTHER_CFLAGS+': [
390+
'-fno-omit-frame-pointer',
391+
'-fsanitize=undefined',
392+
'-DUNDEFINED_SANITIZER'
393+
],
394+
},
395+
'target_conditions': [
396+
['_type!="static_library"', {
397+
'xcode_settings': {'OTHER_LDFLAGS': ['-fsanitize=undefined']},
398+
}],
399+
],
400+
}],
377401
# The defines bellow must include all things from the external_v8_defines
378402
# list in v8/BUILD.gn.
379403
['v8_enable_v8_checks == 1', {

configure.py

+7
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,12 @@
724724
default=None,
725725
help='compile for Address Sanitizer to find memory bugs')
726726

727+
parser.add_argument('--enable-ubsan',
728+
action='store_true',
729+
dest='enable_ubsan',
730+
default=None,
731+
help='compile for Undefined Behavior Sanitizer')
732+
727733
parser.add_argument('--enable-static',
728734
action='store_true',
729735
dest='enable_static',
@@ -1437,6 +1443,7 @@ def configure_node(o):
14371443
o['variables']['linked_module_files'] = options.linked_module
14381444

14391445
o['variables']['asan'] = int(options.enable_asan or 0)
1446+
o['variables']['ubsan'] = int(options.enable_ubsan or 0)
14401447

14411448
if options.coverage:
14421449
o['variables']['coverage'] = 'true'

src/spawn_sync.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void SyncProcessOutputBuffer::OnRead(const uv_buf_t* buf, size_t nread) {
6868

6969

7070
size_t SyncProcessOutputBuffer::Copy(char* dest) const {
71-
memcpy(dest, data_, used());
71+
if (dest != nullptr) memcpy(dest, data_, used());
7272
return used();
7373
}
7474

suppressions.supp

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
vptr:deps/icu-small/source/common/uloc_tag.cpp
2+
vptr:deps/icu-small/source/common/unistr.cpp
3+
shift-base:deps/v8/src/wasm/decoder.h
4+
vptr:deps/icu-small/source/common/sharedobject.cpp
5+
vptr:deps/icu-small/source/i18n/coll.cpp
6+
nonnull-attribute:deps/v8/src/snapshot/snapshot-source-sink.h

test/common/sea.js

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ function skipIfSingleExecutableIsNotSupported() {
4646
}
4747
}
4848

49+
if (process.config.variables.ubsan) {
50+
common.skip('UndefinedBehavior Sanitizer is not supported');
51+
}
52+
4953
tmpdir.refresh();
5054

5155
// The SEA tests involve making a copy of the executable and writing some fixtures

test/parallel/test-node-output-console.mjs

+5-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ describe('console output', { concurrency: true }, () => {
3131
.transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, replaceStackTrace);
3232
for (const { name, transform, env } of tests) {
3333
it(name, async () => {
34-
await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { env });
34+
await snapshot.spawnAndAssert(
35+
fixtures.path(name),
36+
transform ?? defaultTransform,
37+
{ env: { ...env, ...process.env } },
38+
);
3539
});
3640
}
3741
});

0 commit comments

Comments
 (0)