OSDN Git Service

Fixed link time warnings on MacOS
authorAlexis Hetu <sugoi@google.com>
Mon, 26 Nov 2018 22:25:23 +0000 (17:25 -0500)
committerAlexis Hétu <sugoi@google.com>
Thu, 6 Dec 2018 17:52:07 +0000 (17:52 +0000)
MacOS' linker dislikes local static variables that are used
in two separate libraries. Removing them from the header files
fixes all the warnings.

Bug b/chromium:907088

Change-Id: I7b8ed44bf9a3180489a7407980740fd3f3863046
Reviewed-on: https://swiftshader-review.googlesource.com/c/22889
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
15 files changed:
src/Common/SharedLibrary.cpp [new file with mode: 0644]
src/Common/SharedLibrary.hpp
src/OpenGL/libEGL/Android.mk
src/OpenGL/libEGL/BUILD.gn
src/OpenGL/libEGL/libEGL.vcxproj
src/OpenGL/libEGL/libEGL.vcxproj.filters
src/OpenGL/libGLES_CM/Android.mk
src/OpenGL/libGLES_CM/libGLES_CM.vcxproj
src/OpenGL/libGLES_CM/libGLES_CM.vcxproj.filters
src/OpenGL/libGLESv2/Android.mk
src/OpenGL/libGLESv2/BUILD.gn
src/OpenGL/libGLESv2/Texture.cpp
src/OpenGL/libGLESv2/Texture.h
src/OpenGL/libGLESv2/libGLESv2.vcxproj
src/OpenGL/libGLESv2/libGLESv2.vcxproj.filters

diff --git a/src/Common/SharedLibrary.cpp b/src/Common/SharedLibrary.cpp
new file mode 100644 (file)
index 0000000..982292d
--- /dev/null
@@ -0,0 +1,52 @@
+// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "SharedLibrary.hpp"
+
+#if defined(_WIN32)
+std::string getModuleDirectory()
+{
+       static int dummy_symbol = 0;
+
+       HMODULE module = NULL;
+       GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCTSTR)&dummy_symbol, &module);
+
+       char filename[1024];
+       if(module && (GetModuleFileName(module, filename, sizeof(filename)) != 0))
+       {
+               std::string directory(filename);
+               return directory.substr(0, directory.find_last_of("\\/") + 1).c_str();
+       }
+       else
+       {
+               return "";
+       }
+}
+#else
+std::string getModuleDirectory()
+{
+       static int dummy_symbol = 0;
+
+       Dl_info dl_info;
+       if(dladdr(&dummy_symbol, &dl_info) != 0)
+       {
+               std::string directory(dl_info.dli_fname);
+               return directory.substr(0, directory.find_last_of("\\/") + 1).c_str();
+       }
+       else
+       {
+               return "";
+       }
+}
+#endif
index 8a8c3a1..2af7998 100644 (file)
@@ -27,6 +27,7 @@ void *getLibraryHandle(const char *path);
 void *loadLibrary(const char *path);
 void freeLibrary(void *library);
 void *getProcAddress(void *library, const char *name);
+std::string getModuleDirectory();
 
 template<int n>
 void *loadLibrary(const std::string &libraryDirectory, const char *(&names)[n], const char *mustContainSymbol = nullptr)
@@ -88,25 +89,6 @@ void *loadLibrary(const std::string &libraryDirectory, const char *(&names)[n],
        {
                return (void*)GetProcAddress((HMODULE)library, name);
        }
-
-       inline std::string getModuleDirectory()
-       {
-               static int dummy_symbol = 0;
-
-               HMODULE module = NULL;
-               GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCTSTR)&dummy_symbol, &module);
-
-               char filename[1024];
-               if(module && (GetModuleFileName(module, filename, sizeof(filename)) != 0))
-               {
-                       std::string directory(filename);
-                       return directory.substr(0, directory.find_last_of("\\/") + 1).c_str();
-               }
-               else
-               {
-                       return "";
-               }
-       }
 #else
        inline void *loadLibrary(const char *path)
        {
@@ -150,22 +132,6 @@ void *loadLibrary(const std::string &libraryDirectory, const char *(&names)[n],
 
                return symbol;
        }
-
-       inline std::string getModuleDirectory()
-       {
-               static int dummy_symbol = 0;
-
-               Dl_info dl_info;
-               if(dladdr(&dummy_symbol, &dl_info) != 0)
-               {
-                       std::string directory(dl_info.dli_fname);
-                       return directory.substr(0, directory.find_last_of("\\/") + 1).c_str();
-               }
-               else
-               {
-                       return "";
-               }
-       }
 #endif
 
 #endif   // SharedLibrary_hpp
index f62cbdd..4ade568 100644 (file)
@@ -31,7 +31,8 @@ COMMON_SRC_FILES := \
        Display.cpp \
        Surface.cpp \
        libEGL.cpp \
-       main.cpp
+       main.cpp \
+       ../../Common/SharedLibrary.cpp
 
 COMMON_C_INCLUDES := \
        bionic \
index 2c610d1..ab9b6fe 100644 (file)
@@ -52,6 +52,7 @@ swiftshader_shared_library("swiftshader_libEGL") {
   }
 
   sources = [
+    "../../Common/SharedLibrary.cpp",
     "../common/debug.cpp",
     "../common/Object.cpp",
     "Config.cpp",
index 2115019..bfc2132 100644 (file)
@@ -326,6 +326,7 @@ copy "$(OutDir)libEGL.dll" "$(SolutionDir)out\$(Configuration)_$(Platform)\trans
     </ResourceCompile>\r
   </ItemDefinitionGroup>\r
   <ItemGroup>\r
+    <ClCompile Include="..\..\Common\SharedLibrary.cpp" />\r
     <ClCompile Include="..\common\Object.cpp" />\r
     <ClCompile Include="Config.cpp" />\r
     <ClCompile Include="..\Common\debug.cpp" />\r
index 7e4fcb1..6994820 100644 (file)
@@ -32,6 +32,9 @@
     <ClCompile Include="Surface.cpp">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="..\..\Common\SharedLibrary.cpp">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="Config.h">\r
index 9b00f42..6240d5d 100644 (file)
@@ -44,7 +44,8 @@ COMMON_SRC_FILES := \
        ResourceManager.cpp \
        Texture.cpp \
        utilities.cpp \
-       VertexDataManager.cpp
+       VertexDataManager.cpp \
+       ../../Common/SharedLibrary.cpp
 
 COMMON_C_INCLUDES := \
        bionic \
index cf1ac82..a720f24 100644 (file)
@@ -338,6 +338,7 @@ copy "$(OutDir)libGLES_CM.dll" "$(SolutionDir)out\$(Configuration)_$(Platform)\t
     </ResourceCompile>\r
   </ItemDefinitionGroup>\r
   <ItemGroup>\r
+    <ClCompile Include="..\..\Common\SharedLibrary.cpp" />\r
     <ClCompile Include="..\common\Image.cpp" />\r
     <ClCompile Include="..\common\MatrixStack.cpp" />\r
     <ClCompile Include="..\common\Object.cpp" />\r
index 41e0002..0029212 100644 (file)
@@ -59,6 +59,9 @@
     <ClCompile Include="..\common\Image.cpp">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="..\..\Common\SharedLibrary.cpp">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="Buffer.h">\r
index 747a6b0..2368bd5 100644 (file)
@@ -54,6 +54,7 @@ COMMON_SRC_FILES := \
        utilities.cpp \
        VertexArray.cpp \
        VertexDataManager.cpp \
+       ../../Common/SharedLibrary.cpp
 
 COMMON_C_INCLUDES := \
        bionic \
index e6543cf..cf12aaf 100644 (file)
@@ -68,6 +68,7 @@ swiftshader_static_library("swiftshader_libGLESv2_static") {
   ]
 
   sources = [
+    "../../Common/SharedLibrary.cpp",
     "Buffer.cpp",
     "Context.cpp",
     "Device.cpp",
index 0cf4084..d6742d9 100644 (file)
 namespace es2
 {
 
+egl::Image*& ImageLevels::getNullImage()
+{
+    static egl::Image* nullImage;
+    nullImage = nullptr;
+    return nullImage;
+}
+
 Texture::Texture(GLuint name) : egl::Texture(name)
 {
        mMinFilter = GL_NEAREST_MIPMAP_LINEAR;
index 4f57d32..f27879d 100644 (file)
@@ -60,9 +60,7 @@ public:
                        return image[index];
                }
 
-               static egl::Image* nullImage;
-               nullImage = nullptr;
-               return nullImage;
+               return getNullImage();
        }
 
        inline void release()
@@ -91,6 +89,7 @@ public:
 
 private:
        egl::Image *image[IMPLEMENTATION_MAX_TEXTURE_LEVELS] = {};
+    static egl::Image*& getNullImage();
 };
 
 class Texture : public egl::Texture
index 5c0e73e..8748629 100644 (file)
@@ -350,6 +350,7 @@ copy "$(OutDir)libGLESv2.dll" "$(SolutionDir)out\$(Configuration)_$(Platform)\tr
     </ResourceCompile>\r
   </ItemDefinitionGroup>\r
   <ItemGroup>\r
+    <ClCompile Include="..\..\Common\SharedLibrary.cpp" />\r
     <ClCompile Include="..\common\Image.cpp" />\r
     <ClCompile Include="..\common\Object.cpp" />\r
     <ClCompile Include="Buffer.cpp" />\r
index 004a944..295eeca 100644 (file)
@@ -80,6 +80,9 @@
     <ClCompile Include="entry_points.cpp">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="..\..\Common\SharedLibrary.cpp">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="Buffer.h">\r