From 4b97ab98a8e90ae5403058b73c345974247bf01e Mon Sep 17 00:00:00 2001
From: Alexei Podtelezhnikov
Date: Tue, 24 Jul 2018 23:01:34 -0400
Subject: [PATCH] [build] Fortify dllexport/dllimport attributes
(#53969,#54330).
We no longer use predefined _DLL, which can be defined for static
builds too with /MD. We use DLL_EXPORT and DLL_IMPORT instead,
following libtool convention.
* CMakeLists.txt [WIN32], builds/windows/vc2010/freetype.vcxproj:
Define DLL_EXPORT manually.
* include/freetype/config/ftconfig.h, builds/unix/ftconfig.in,
builds/vms/ftconfig.h, builds/windows/vc2010/index.html,
src/base/ftver.rc: /_DLL/d, s/FT2_DLLIMPORT/DLL_IMPORT/.
---
CMakeLists.txt | 4 ++++
ChangeLog | 15 +++++++++++++++
builds/unix/ftconfig.in | 4 ++--
builds/vms/ftconfig.h | 4 ++--
builds/windows/vc2010/freetype.vcxproj | 16 ++++++++--------
builds/windows/vc2010/index.html | 2 +-
include/freetype/config/ftconfig.h | 4 ++--
src/base/ftver.rc | 2 +-
8 files changed, 35 insertions(+), 16 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f54e68871..3f583373a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -353,6 +353,10 @@ target_compile_definitions(
if (WIN32)
target_compile_definitions(
freetype PRIVATE _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_WARNINGS)
+ if (BUILD_SHARED_LIBS)
+ target_compile_definitions(
+ freetype PRIVATE DLL_EXPORT)
+ endif ()
endif ()
if (BUILD_SHARED_LIBS)
diff --git a/ChangeLog b/ChangeLog
index bdfb41c5e..0096724e3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2018-07-24 Alexei Podtelezhnikov
+
+ [build] Fortify dllexport/dllimport attributes (#53969,#54330).
+
+ We no longer use predefined _DLL, which can be defined for static
+ builds too with /MD. We use DLL_EXPORT and DLL_IMPORT instead,
+ following libtool convention.
+
+ * CMakeLists.txt [WIN32], builds/windows/vc2010/freetype.vcxproj:
+ Define DLL_EXPORT manually.
+
+ * include/freetype/config/ftconfig.h, builds/unix/ftconfig.in,
+ builds/vms/ftconfig.h, builds/windows/vc2010/index.html,
+ src/base/ftver.rc: /_DLL/d, s/FT2_DLLIMPORT/DLL_IMPORT/.
+
2018-07-24 Werner Lemberg
[type1] Check relationship between number of axes and designs.
diff --git a/builds/unix/ftconfig.in b/builds/unix/ftconfig.in
index dc4aff75c..cdb7f22e5 100644
--- a/builds/unix/ftconfig.in
+++ b/builds/unix/ftconfig.in
@@ -489,7 +489,7 @@ FT_BEGIN_HEADER
#ifdef FT2_BUILD_LIBRARY
-#if defined( _WIN32 ) && ( defined( _DLL ) || defined( DLL_EXPORT ) )
+#if defined( _WIN32 ) && defined( DLL_EXPORT )
#define FT_EXPORT( x ) __declspec( dllexport ) x
#elif defined( __GNUC__ ) && __GNUC__ >= 4
#define FT_EXPORT( x ) __attribute__(( visibility( "default" ) )) x
@@ -503,7 +503,7 @@ FT_BEGIN_HEADER
#else
-#if defined( FT2_DLLIMPORT )
+#if defined( _WIN32 ) && defined( DLL_IMPORT )
#define FT_EXPORT( x ) __declspec( dllimport ) x
#elif defined( __cplusplus )
#define FT_EXPORT( x ) extern "C" x
diff --git a/builds/vms/ftconfig.h b/builds/vms/ftconfig.h
index 77bca5459..733b09b49 100644
--- a/builds/vms/ftconfig.h
+++ b/builds/vms/ftconfig.h
@@ -441,7 +441,7 @@ FT_BEGIN_HEADER
#ifdef FT2_BUILD_LIBRARY
-#if defined( _WIN32 ) && ( defined( _DLL ) || defined( DLL_EXPORT ) )
+#if defined( _WIN32 ) && defined( DLL_EXPORT )
#define FT_EXPORT( x ) __declspec( dllexport ) x
#elif defined( __GNUC__ ) && __GNUC__ >= 4
#define FT_EXPORT( x ) __attribute__(( visibility( "default" ) )) x
@@ -455,7 +455,7 @@ FT_BEGIN_HEADER
#else
-#if defined( FT2_DLLIMPORT )
+#if defined( _WIN32 ) && defined( DLL_IMPORT )
#define FT_EXPORT( x ) __declspec( dllimport ) x
#elif defined( __cplusplus )
#define FT_EXPORT( x ) extern "C" x
diff --git a/builds/windows/vc2010/freetype.vcxproj b/builds/windows/vc2010/freetype.vcxproj
index fe2fe6880..7052c6c42 100644
--- a/builds/windows/vc2010/freetype.vcxproj
+++ b/builds/windows/vc2010/freetype.vcxproj
@@ -121,7 +121,7 @@
Disabled
$(UserOptionDirectory);..\..\..\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories)
- WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;FT_DEBUG_LEVEL_ERROR;FT_DEBUG_LEVEL_TRACE;FT2_BUILD_LIBRARY;$(UserDefines);%(PreprocessorDefinitions)
+ WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;FT_DEBUG_LEVEL_ERROR;FT_DEBUG_LEVEL_TRACE;FT2_BUILD_LIBRARY;DLL_EXPORT;$(UserDefines);%(PreprocessorDefinitions)
EnableFastChecks
MultiThreadedDebugDLL
true
@@ -135,7 +135,7 @@
Disabled
- _DEBUG;_DLL;$(UserDefines);%(PreprocessorDefinitions)
+ _DEBUG;DLL_EXPORT;$(UserDefines);%(PreprocessorDefinitions)
0x0409
@@ -149,7 +149,7 @@
Disabled
$(UserOptionDirectory);..\..\..\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories)
- WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;FT_DEBUG_LEVEL_ERROR;FT_DEBUG_LEVEL_TRACE;FT2_BUILD_LIBRARY;$(UserDefines);%(PreprocessorDefinitions)
+ WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;FT_DEBUG_LEVEL_ERROR;FT_DEBUG_LEVEL_TRACE;FT2_BUILD_LIBRARY;DLL_EXPORT;$(UserDefines);%(PreprocessorDefinitions)
EnableFastChecks
MultiThreadedDebugDLL
true
@@ -163,7 +163,7 @@
Disabled
- _DEBUG;_DLL;$(UserDefines);%(PreprocessorDefinitions)
+ _DEBUG;DLL_EXPORT;$(UserDefines);%(PreprocessorDefinitions)
0x0409
@@ -234,7 +234,7 @@
MaxSpeed
AnySuitable
$(UserOptionDirectory);..\..\..\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories)
- WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;FT2_BUILD_LIBRARY;$(UserDefines);%(PreprocessorDefinitions)
+ WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;FT2_BUILD_LIBRARY;DLL_EXPORT;$(UserDefines);%(PreprocessorDefinitions)
true
MultiThreadedDLL
true
@@ -258,7 +258,7 @@
true
- NDEBUG;_DLL;$(UserDefines);%(PreprocessorDefinitions)
+ NDEBUG;DLL_EXPORT;$(UserDefines);%(PreprocessorDefinitions)
0x0409
@@ -274,7 +274,7 @@
MaxSpeed
AnySuitable
$(UserOptionDirectory);..\..\..\include;$(UserIncludeDirectories);%(AdditionalIncludeDirectories)
- WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;FT2_BUILD_LIBRARY;$(UserDefines);%(PreprocessorDefinitions)
+ WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;FT2_BUILD_LIBRARY;DLL_EXPORT;$(UserDefines);%(PreprocessorDefinitions)
true
MultiThreadedDLL
true
@@ -298,7 +298,7 @@
true
- NDEBUG;_DLL;$(UserDefines);%(PreprocessorDefinitions)
+ NDEBUG;DLL_EXPORT;$(UserDefines);%(PreprocessorDefinitions)
0x0409
diff --git a/builds/windows/vc2010/index.html b/builds/windows/vc2010/index.html
index c3e604034..634ea9305 100644
--- a/builds/windows/vc2010/index.html
+++ b/builds/windows/vc2010/index.html
@@ -33,7 +33,7 @@ simplifies automated (command-line) builds using msbuild.
To link your executable with FreeType DLL, you may want to define
-FT2_DLLIMPORT so that the imported functions are appropriately
+DLL_IMPORT so that the imported functions are appropriately
attributed with dllimport.