Skip to content

Commit

Permalink
Bug 1861365 - Detect statically linking with libstdc++ r=glandium
Browse files Browse the repository at this point in the history
Do this by scanning for lib(std)c++ in the dynamic section.

Differential Revision: https://phabricator.services.mozilla.com/D194744

UltraBlame original commit: cc5b886ea3a22863d452fc7455c03b0834eee27e
  • Loading branch information
marco-c committed Jan 16, 2024
1 parent b0ba4f2 commit a8588da
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions build/autoconf/compiler-opts.m4
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,36 @@ if test "$GNU_CC" -a "$GCC_USE_GNU_LD" -a -z "$MOZ_DISABLE_ICF" -a -z "$DEVELOPE
fi
fi
dnl ========================================================
dnl = Detect static linkage of libstdc++
dnl ========================================================
AC_CACHE_CHECK([whether we're trying to statically link with libstdc++],
moz_cv_opt_static_libstdcxx,
[moz_cv_opt_static_libstdcxx=no
AC_LANG_SAVE
AC_LANG_CPLUSPLUS
cat > conftest.$ac_ext <<EOF
#include <iostream>
int main() { std::cout << 1; }
EOF
dnl This test is quite conservative: it assumes dynamic linkage if the compilation step fails or if
dnl the binary format is not supported. But it still detects basic issues.
if AC_TRY_EVAL([ac_link]) && test -s conftest${ac_exeext} && $LLVM_OBJDUMP --private-headers conftest${ac_exeext} 2> conftest.err 1> conftest.out
then
if test -s conftest.err
then :
elif grep -q -E 'NEEDED.*lib(std)?c\+\+' conftest.out
then :
else moz_cv_opt_static_libstdcxx=yes
fi
fi
AC_LANG_RESTORE
rm -f conftest*
])
if test "$moz_cv_opt_static_libstdcxx" = "yes"; then
AC_MSG_ERROR([Firefox does not support linking statically with libstdc++])
fi
dnl ========================================================
dnl = Automatically remove dead symbols
dnl ========================================================
Expand Down

0 comments on commit a8588da

Please sign in to comment.