Skip to content

Conversation

practicalswift
Copy link
Contributor

By generating a trap for signed overflow on addition, subtraction, multiplication operations in the Travis testing we are more likely to identify problematic code prior to merging it.

@fanquake
Copy link
Member

fanquake commented Mar 14, 2018

HOST=x86_64-unknown-linux-gnu

The command "test -n "$USE_SHELL" && eval '"$USE_SHELL" -c "./autogen.sh"' || ./autogen.sh" exited with 0.
$ mkdir build && cd build

The command "mkdir build && cd build" exited with 0.
$ ../configure --cache-file=config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( cat config.log && false)
configure: error: unrecognized option: `-ftrapv''
Try `../configure --help' for more information
cat: config.log: No such file or directory

The command "../configure --cache-file=config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( cat config.log && false)" exited with 1.
$ make distdir VERSION=$HOST
make: *** No rule to make target `distdir'.  Stop.

@eklitzke
Copy link
Contributor

eklitzke commented Mar 14, 2018

This is cool, concept ack.

Looks like there are some problems:

  • -fwrapv belongs in CXXFLAGS not in CPPFLAGS
  • Travis is being weird. The builders that passed seem to have used some kind of cached config and didn't actually pick up -ftrapv. The one that's failing is failing because there's a shell quoting issue with how configure is invoked.

GCC 4.8 also supports -fsanitize=address and -fsanitize=thread (and newer GCC versions have a whole plethora or really interesting options). What do you think about using those options in Travis as well?

Copy link
Contributor

@eklitzke eklitzke left a comment

Choose a reason for hiding this comment

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

There's a shell quoting issue with how travis is running this.

@eklitzke
Copy link
Contributor

eklitzke commented Mar 14, 2018

Here's an idea for another way to do this: eklitzke@635e378 . The idea is to add -ftrapv when --enable-debug is used, and then use that option on all of the Travis jobs. --enable-debug also sets -DDEBUG_LOCKORDER.

What do you think of this approach?

@sipa
Copy link
Member

sipa commented Mar 14, 2018

@eklitzke There was some work earlier to get the code to run cleanly under sanitizers (see #9743 and #9512), though I don't think we ever made it perfectly runnable without warnings.

@eklitzke
Copy link
Contributor

BTW the right way to fix the quoting issue in Travis is to use a bash array. It looks like Travis doesn't support these properly. If you still wanted to use this approach instead of modifying configure.ac as in my example two options:

  • IFS hacks
  • Create yet-another-Travis-variable and pass it down to the configure call

@practicalswift
Copy link
Contributor Author

@eklitzke Thanks for reviewing. I've now cherry-picked your commit (which is the better solution) into this PR.

Please re-review :-)

@practicalswift
Copy link
Contributor Author

practicalswift commented Mar 15, 2018

@eklitzke Enabling -fsanitize=address and -fsanitize=thread in Travis (after cleaning up remaining violations) would be really really nice!

@eklitzke
Copy link
Contributor

eklitzke commented Mar 15, 2018

It looks like this doesn't work for the MingW builds, I got timeouts in my travis runs that match the ones you just cherry-picked: https://travis-ci.org/eklitzke/bitcoin/builds/353587968 . Let's disable the option for those two builders.

I added some -fsanitize support to the configure script in #12692, which is a good start since it will make using those flags easier (even if the code isn't currently clean under asan/tsan).

@practicalswift practicalswift changed the title travis: Generate a trap for signed arithmetic overflows (enable -ftrapv) Add -ftrapv to CFLAGS and CXXFLAGS when --enable-debug is used. Enable -ftrapv in Travis. Mar 15, 2018
@practicalswift
Copy link
Contributor Author

practicalswift commented Mar 15, 2018

@eklitzke To keep the changes as small as possible I've now enabled -ftrapv (via --enable-debug) only for one of the Travis jobs (job: "Qt4 & system libs"). Makes sense?

Please re-review :-)

@fanquake
Copy link
Member

@practicalswift I don't think you've cherry-picked correctly, looks like you just swapped out the changes in your commit with @eklitzke's ?

@eklitzke
Copy link
Contributor

This looks right to me, utACK e23dfbb01df044e6d0dc65f6b9333e6547202fa7.

@practicalswift
Copy link
Contributor Author

@fanquake The cherry-pick was a previous version. e23dfbb01df044e6d0dc65f6b9333e6547202fa7 is correct. Please review :-)

@eklitzke
Copy link
Contributor

FYI this is going to conflict with #12695 . Should be an easy merge conflict though.

@laanwj
Copy link
Member

laanwj commented Apr 2, 2018

@theuni Can you take a look?

@practicalswift
Copy link
Contributor Author

Rebased! Please re-review :-)

@practicalswift practicalswift force-pushed the trapv branch 2 times, most recently from 3fc534a to bb2d161 Compare April 16, 2018 19:55
@practicalswift
Copy link
Contributor Author

practicalswift commented Apr 23, 2018

Interesting – judging from the Travis testing it seems that the trap is trigged indicating that we have a signed overflow taking place when running the tests. Let's find out where!

@theuni
Copy link
Member

theuni commented Apr 23, 2018

Concept ACK. Please put this on top of #13005 though, as it needs the same treatment.

This needs to be checked with AX_CHECK_COMPILE_FLAG, the same way that -DDEBUG/-DDEBUG_LOCKORDER are checked there.

.travis.yml Outdated
@@ -30,7 +30,7 @@ env:
# 32-bit + dash
- HOST=i686-pc-linux-gnu PACKAGES="g++-multilib python3-zmq" DEP_OPTS="NO_QT=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-zmq --enable-glibc-back-compat --enable-reduce-exports LDFLAGS=-static-libstdc++" USE_SHELL="/bin/dash"
# x86_64 Linux (uses qt5 dev package instead of depends Qt to speed up build and avoid timeout)
- HOST=x86_64-unknown-linux-gnu PACKAGES="python3-zmq qtbase5-dev qttools5-dev-tools protobuf-compiler libdbus-1-dev libharfbuzz-dev" DEP_OPTS="NO_QT=1 NO_UPNP=1 DEBUG=1 ALLOW_HOST_PACKAGES=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-zmq --with-gui=qt5 --enable-glibc-back-compat --enable-reduce-exports CPPFLAGS=-DDEBUG_LOCKORDER"
Copy link
Member

Choose a reason for hiding this comment

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

Removing DEBUG=1 here should cause depends to no longer build as debug.

+1 on using --enable-debug, though.

Copy link
Contributor Author

@practicalswift practicalswift May 5, 2018

Choose a reason for hiding this comment

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

Updated: Re-introduced DEBUG=1 :-)

@DrahtBot
Copy link
Contributor

Needs rebase

@practicalswift
Copy link
Contributor Author

Rebased!

@maflcko
Copy link
Member

maflcko commented Jun 24, 2018

ACK 98d842c (that the rebase was done correctly, didn't look at anything else)

@sipa
Copy link
Member

sipa commented Jun 27, 2018

utACK 98d842c

@sipa sipa merged commit 98d842c into bitcoin:master Jun 27, 2018
sipa added a commit that referenced this pull request Jun 27, 2018
…is used. Enable -ftrapv in Travis.

98d842c travis: Build with --enable-debug (x86_64-unknown-linux-gnu) (practicalswift)
94e52d1 Add -ftrapv to DEBUG_CXXFLAGS when --enable-debug is used (practicalswift)

Pull request description:

  By generating a trap for signed overflow on addition, subtraction, multiplication operations in the Travis testing we are more likely to identify problematic code prior to merging it.

Tree-SHA512: 47712da53b4ff451b8f22f16ddc3b53100a09060a3b04cda4b8fbbb74e6f666fc07a9cc7abc64cacb87a0aa3f62dc8e3c91a1a0ed12bf82bb2a5624a5d104389
maflcko pushed a commit that referenced this pull request Jul 24, 2018
14788fb [travis] Don't store debug info if --enable-debug is set (Chun Kuan Lee)

Pull request description:

  After #12686 merged, ccache store huge size of .o files, simply get rid of those useless debug info.

  Fixes #13748

Tree-SHA512: fb404e2c7d52cd8266548433955c41683ede062f97c8fb7098a887f164bcde48b60e5e533a0a27c7e095fdd9ef88db018b8689adebb2c0e32c8957828629e346
zkbot added a commit to zcash/zcash that referenced this pull request Jan 30, 2020
maflcko pushed a commit that referenced this pull request Jul 2, 2020
…se of uninitialized memory

870f0cd build: Add MemorySanitizer (MSan) in Travis to detect use of uninitialized memory (practicalswift)

Pull request description:

  Add MemorySanitizer (MSan) in Travis to detect use of uninitialized memory.

  First UBSan, then ASan followed by TSan... and now: yes, the wait is over -- **MSan is finally here!** :)

  Some historical context:
  * 2017: Continuous compilation with Clang Thread Safety analysis enabled (#10866, #10923)
  * 2018: Continuous testing with trapping on signed integer overflows (`-ftrapv`) (#12686)
  * 2018: Continuous testing of use of locale dependent functions (#13041)
  * 2018: Continuous testing of format strings (#13705)
  * 2018: Continuous compilation with MSVC `TreatWarningAsError` (#14151)
  * 2018: Continuous testing under UndefinedBehaviorSanitizer – UBSan (#14252, #14673, #17006)
  * 2018: Continuous testing under AddressSanitizer – ASan (#14794, #17205, #17674)
  * 2018: Continuous testing under ThreadSanitizer – TSan (#14829)
  * 2019: Continuous testing in an unsigned char environment (`-funsigned-char`) (#15134)
  * 2019: Continuous compile-time testing of assumptions we're making (#15391)
  * 2019: Continuous testing of fuzz test cases under Valgrind (#17633, #18159, #18166)
  * 2020: Finally... MemorySanitizer – MSAN! :)

  What is the next step? What tools should we add to CI to keep bugs from entering `master`? :)

ACKs for top commit:
  MarcoFalke:
    ACK 870f0cd

Tree-SHA512: 38327c8b75679d97d469fe42e704cacd1217447a5a603701dd8a58ee50b3be2c10248f8d68a479ed081c0c4b254589d3081c9183f991640b06ef689061f75578
@practicalswift practicalswift deleted the trapv branch April 10, 2021 19:35
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jun 29, 2021
…-debug is used. Enable -ftrapv in Travis.

98d842c travis: Build with --enable-debug (x86_64-unknown-linux-gnu) (practicalswift)
94e52d1 Add -ftrapv to DEBUG_CXXFLAGS when --enable-debug is used (practicalswift)

Pull request description:

  By generating a trap for signed overflow on addition, subtraction, multiplication operations in the Travis testing we are more likely to identify problematic code prior to merging it.

Tree-SHA512: 47712da53b4ff451b8f22f16ddc3b53100a09060a3b04cda4b8fbbb74e6f666fc07a9cc7abc64cacb87a0aa3f62dc8e3c91a1a0ed12bf82bb2a5624a5d104389
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jun 29, 2021
…-debug is used. Enable -ftrapv in Travis.

98d842c travis: Build with --enable-debug (x86_64-unknown-linux-gnu) (practicalswift)
94e52d1 Add -ftrapv to DEBUG_CXXFLAGS when --enable-debug is used (practicalswift)

Pull request description:

  By generating a trap for signed overflow on addition, subtraction, multiplication operations in the Travis testing we are more likely to identify problematic code prior to merging it.

Tree-SHA512: 47712da53b4ff451b8f22f16ddc3b53100a09060a3b04cda4b8fbbb74e6f666fc07a9cc7abc64cacb87a0aa3f62dc8e3c91a1a0ed12bf82bb2a5624a5d104389
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Jul 1, 2021
…-debug is used. Enable -ftrapv in Travis.

98d842c travis: Build with --enable-debug (x86_64-unknown-linux-gnu) (practicalswift)
94e52d1 Add -ftrapv to DEBUG_CXXFLAGS when --enable-debug is used (practicalswift)

Pull request description:

  By generating a trap for signed overflow on addition, subtraction, multiplication operations in the Travis testing we are more likely to identify problematic code prior to merging it.

Tree-SHA512: 47712da53b4ff451b8f22f16ddc3b53100a09060a3b04cda4b8fbbb74e6f666fc07a9cc7abc64cacb87a0aa3f62dc8e3c91a1a0ed12bf82bb2a5624a5d104389
vijaydasmp pushed a commit to vijaydasmp/dash that referenced this pull request Oct 4, 2021
…etect use of uninitialized memory

870f0cd build: Add MemorySanitizer (MSan) in Travis to detect use of uninitialized memory (practicalswift)

Pull request description:

  Add MemorySanitizer (MSan) in Travis to detect use of uninitialized memory.

  First UBSan, then ASan followed by TSan... and now: yes, the wait is over -- **MSan is finally here!** :)

  Some historical context:
  * 2017: Continuous compilation with Clang Thread Safety analysis enabled (bitcoin#10866, bitcoin#10923)
  * 2018: Continuous testing with trapping on signed integer overflows (`-ftrapv`) (bitcoin#12686)
  * 2018: Continuous testing of use of locale dependent functions (bitcoin#13041)
  * 2018: Continuous testing of format strings (bitcoin#13705)
  * 2018: Continuous compilation with MSVC `TreatWarningAsError` (bitcoin#14151)
  * 2018: Continuous testing under UndefinedBehaviorSanitizer – UBSan (bitcoin#14252, bitcoin#14673, bitcoin#17006)
  * 2018: Continuous testing under AddressSanitizer – ASan (bitcoin#14794, bitcoin#17205, bitcoin#17674)
  * 2018: Continuous testing under ThreadSanitizer – TSan (bitcoin#14829)
  * 2019: Continuous testing in an unsigned char environment (`-funsigned-char`) (bitcoin#15134)
  * 2019: Continuous compile-time testing of assumptions we're making (bitcoin#15391)
  * 2019: Continuous testing of fuzz test cases under Valgrind (bitcoin#17633, bitcoin#18159, bitcoin#18166)
  * 2020: Finally... MemorySanitizer – MSAN! :)

  What is the next step? What tools should we add to CI to keep bugs from entering `master`? :)

ACKs for top commit:
  MarcoFalke:
    ACK 870f0cd

Tree-SHA512: 38327c8b75679d97d469fe42e704cacd1217447a5a603701dd8a58ee50b3be2c10248f8d68a479ed081c0c4b254589d3081c9183f991640b06ef689061f75578
Munkybooty pushed a commit to Munkybooty/dash that referenced this pull request Apr 26, 2022
…-debug is used. Enable -ftrapv in Travis.

98d842c travis: Build with --enable-debug (x86_64-unknown-linux-gnu) (practicalswift)
94e52d1 Add -ftrapv to DEBUG_CXXFLAGS when --enable-debug is used (practicalswift)

Pull request description:

  By generating a trap for signed overflow on addition, subtraction, multiplication operations in the Travis testing we are more likely to identify problematic code prior to merging it.

Tree-SHA512: 47712da53b4ff451b8f22f16ddc3b53100a09060a3b04cda4b8fbbb74e6f666fc07a9cc7abc64cacb87a0aa3f62dc8e3c91a1a0ed12bf82bb2a5624a5d104389
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants