Bug 1416183 - Build LZ4 as C instead of including it as C++. r=froydnj
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 15 Nov 2017 12:51:01 +0900
changeset 392070 6f31b7226512260726dbd618b94751024a06909f
parent 392069 962c46110aac6f795ff1eba03856a6e671700179
child 392071 b98f2fff0e174ca3e7a677255bd9049431860f3d
push id32910
push userrgurzau@mozilla.com
push dateThu, 16 Nov 2017 10:02:59 +0000
treeherdermozilla-central@9941e68b5a53 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1416183
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1416183 - Build LZ4 as C instead of including it as C++. r=froydnj Apply https://github.com/lz4/lz4/commit/63a7f34fee5e2ecac452aee3731b7390a1eb8328 to our copy of lz4.h to allow to flag the lz4 symbols as not exported.
mfbt/Compression.cpp
mfbt/lz4.h
mfbt/moz.build
--- a/mfbt/Compression.cpp
+++ b/mfbt/Compression.cpp
@@ -7,37 +7,20 @@
 #include "mozilla/Compression.h"
 #include "mozilla/CheckedInt.h"
 
 // Without including <string>, MSVC 2015 complains about e.g. the impossibility
 // to convert `const void* const` to `void*` when calling memchr from
 // corecrt_memory.h.
 #include <string>
 
-// Because we wrap lz4.c in an anonymous namespace, all of its #includes
-// go in the anonymous namespace too. This would create conflicting
-// declarations for intrinsic functions that are internally defined
-// at top-level. Including intrin.h here prevents it from being included
-// later within the anonymous namespace.
-#ifdef _MSC_VER
-#include <intrin.h>
-#endif
+#include "lz4.h"
 
 using namespace mozilla::Compression;
 
-namespace {
-
-extern "C" {
-
-#include "lz4.c"
-
-}
-
-}/* anonymous namespace */
-
 /* Our wrappers */
 
 size_t
 LZ4::compress(const char* aSource, size_t aInputSize, char* aDest)
 {
   CheckedInt<int> inputSizeChecked = aInputSize;
   MOZ_ASSERT(inputSizeChecked.isValid());
   return LZ4_compress_default(aSource, aDest, inputSizeChecked.value(),
--- a/mfbt/lz4.h
+++ b/mfbt/lz4.h
@@ -67,30 +67,34 @@ extern "C" {
 */
 
 /*^***************************************************************
 *  Export parameters
 *****************************************************************/
 /*
 *  LZ4_DLL_EXPORT :
 *  Enable exporting of functions when building a Windows DLL
-*  LZ4LIB_API :
+*  LZ4LIB_VISIBILITY :
 *  Control library symbols visibility.
 */
+#ifndef LZ4LIB_VISIBILITY
+#  if defined(__GNUC__) && (__GNUC__ >= 4)
+#    define LZ4LIB_VISIBILITY __attribute__ ((visibility ("default")))
+#  else
+#    define LZ4LIB_VISIBILITY
+#  endif
+#endif
 #if defined(LZ4_DLL_EXPORT) && (LZ4_DLL_EXPORT==1)
-#  define LZ4LIB_API __declspec(dllexport)
+#  define LZ4LIB_API __declspec(dllexport) LZ4LIB_VISIBILITY
 #elif defined(LZ4_DLL_IMPORT) && (LZ4_DLL_IMPORT==1)
-#  define LZ4LIB_API __declspec(dllimport) /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
-#elif defined(__GNUC__) && (__GNUC__ >= 4)
-#  define LZ4LIB_API __attribute__ ((__visibility__ ("default")))
+#  define LZ4LIB_API __declspec(dllimport) LZ4LIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
 #else
-#  define LZ4LIB_API
+#  define LZ4LIB_API LZ4LIB_VISIBILITY
 #endif
 
-
 /*------   Version   ------*/
 #define LZ4_VERSION_MAJOR    1    /* for breaking interface changes  */
 #define LZ4_VERSION_MINOR    8    /* for new (non-breaking) interface capabilities */
 #define LZ4_VERSION_RELEASE  0    /* for tweaks, bug-fixes, or development */
 
 #define LZ4_VERSION_NUMBER (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE)
 
 #define LZ4_LIB_VERSION LZ4_VERSION_MAJOR.LZ4_VERSION_MINOR.LZ4_VERSION_RELEASE
--- a/mfbt/moz.build
+++ b/mfbt/moz.build
@@ -142,29 +142,21 @@ UNIFIED_SOURCES += [
     'Unused.cpp',
 ]
 
 DEFINES['IMPL_MFBT'] = True
 
 SOURCES += [
     'Compression.cpp',
     'decimal/Decimal.cpp',
+    'lz4.c',
 ]
 
 DisableStlWrapping()
 
-# Suppress warnings in third-party LZ4 code.
-# TODO: Remove these suppressions after bug 993267 is fixed.
-
-if CONFIG['GNU_CXX']:
-    SOURCES['Compression.cpp'].flags += ['-Wno-unused-function']
-    CXXFLAGS += ['-Wno-error=shadow']
-
 if CONFIG['CLANG_CXX']:
     # Suppress warnings from third-party V8 Decimal code.
     SOURCES['decimal/Decimal.cpp'].flags += ['-Wno-implicit-fallthrough']
 
-if CONFIG['_MSC_VER']:
-    # Error 4804 is "'>' : unsafe use of type 'bool' in operation"
-    SOURCES['Compression.cpp'].flags += ['-wd4804']
-
 if CONFIG['MOZ_NEEDS_LIBATOMIC']:
     OS_LIBS += ['atomic']
+
+DEFINES['LZ4LIB_VISIBILITY'] = ''