Page MenuHomeFreeBSD

Mk/Scripts/qa.sh: badlibmix -- Checks that elfs aren't linked to both base and port SSL libraries and same with libgcc_s.so and gfortran
Needs ReviewPublic

Authored by yuri_rawbw.com on Aug 1 2017, 9:09 PM.

Details

Reviewers
None
Group Reviewers
portmgr
Summary

qa stage badlibmix that reports when elfs are linked to both base and port openssl, or both base and port libgcc_s.so. Such mixes often cause crashes, and shouldn't happen.

See https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=221134

Diff Detail

Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

Mk/Scripts/qa.sh
848–860

All these should probably be replaced by things like:

case "${dep_file}"
  (/usr/lib/libssl|/lib/libcrypto).so)
    ​ base_ssl_libs="${base_ssl_libs} ${dep_file}"
esac

saving us many forks

862

You should probably run ldd -a and only use the first block.

863–864

useless use of grep

awk '/=>/ {print $3}'
868
  1. never, ever, use `, always use $()
  2. I am not sure I see the point of using echo to add a string to a string.

This should also work.

"${file} is linked to both base and port SSL libraries: ${base_ssl_libs} and ${port_ssl_libs}"
Mk/Scripts/qa.sh
848–860

Ok, will modify the patch.

862

No, lack of -a is by design. You want to check the whole dependency set, not only an immediate subset.

868
  1. Ok, will modify the patch.
  2. echo ${str} strips the leading space. Otherwise, this space should be taken out of the main echo string which will make it less readable.
Mk/Scripts/qa.sh
862

No, the lack of -a is by design. You want to check the whole dependency set, not only the immediate subset.

Mk/Scripts/qa.sh
863–864

It removes the first line which is an elf name.

Updated according to Mat's suggestions.

Mk/Scripts/qa.sh
868

FYI: The same file contains backquotes in several other places.

Mk/Scripts/qa.sh
863–864

grep 'foo' | awk '{bar}' is equivalent to awk '/foo/ {bar}'. Please remove the grep.

868

If a single space throws you off, then change the code up there to, for example:

port_ssl_libs="${port_ssl_libs:+${port_ssl_libs} }${dep_file}"

or, if it does not work, the more ugly:

port_ssl_libs="${port_ssl_libs}${port_ssl_libs:+ }${dep_file}"
868

Yes, and because I have not had time to fix them does not mean you should use them :-)

Updated according to Mat's suggestions.

Mk/Scripts/qa.sh
853

Unless you are building openssl and friends, you will not have a PREFIX/lib/libssl.so and such, so you can remove the ones with PREFIX here and below for libgcc_s.

874

The message is slightly wrong, it may not really be linked with both, as we are checking recursive linking. But I am not sure how it could be changed.

Mk/Scripts/qa.sh
853

Isn't it better to be general and always include both no matter what?

874

Even only recursive presence of both base and port libgcc_s.so is bad, because libgcc_s.so contains exception processing. libgcc_s.so is primarily, if not solely used for exceptions in various languages. Exception objects tend to go through libraries in arbitrary order. They can't be touched by procedures from different versions of libgcc_s.so. This causes crashes because different libgcc_s.so assume differently structured exception objects.

For the purposes of this check it's right to be conservative, and only consider the whole set of linked libraries.

Mk/Scripts/qa.sh
853

It is better to not do things that make no sense, in this case, there will never be a PREFIX/lib/libssl.so, so don't add it.

Mk/Scripts/qa.sh
868

Out of curiosity, why do you oppose backticks? They are a valid Bourne shell syntax feature. Do you find them aesthetically unappealing? Making code harder to read? Easy to confuse with regular quotes?

Mk/Scripts/qa.sh
868

See [[ https://github.com/koalaman/shellcheck/wiki/SC2006 |
Use $(STATEMENT) instead of legacy STATEMENT ]]:

Backtick command substitution is legacy syntax with several issues.

  1. It has a series of undefined behaviors related to quoting in POSIX.
  2. It imposes a custom escaping mode with surprising results.
  3. It's exceptionally hard to nest.
yuri_rawbw.com added inline comments.
Mk/Scripts/qa.sh
868

Thanks!

I don't know about the libssl case but I can tell you this does not take care of the case where a module referencing a libgcc lib is loaded later. See https://wiki.freebsd.org/libgcc%20problem