OSDN Git Service

Prevent LTO from eliminating cross-library virtual methods.
authorNicolas Capens <capn@google.com>
Thu, 11 May 2017 15:25:00 +0000 (11:25 -0400)
committerNicolas Capens <capn@google.com>
Thu, 11 May 2017 17:51:48 +0000 (17:51 +0000)
libEGL has to call virtual methods on objects created withing libGLESv2,
and vice-versa. Clang's aggressive link-time-optimization considers
calls to these methods unreachable, because they're not defined within
the same linkage unit. So when they do get called, we're hitting UD
instructions. It can be fixed by marking these classes with
[[clang::lto_visibility_public]] attributes:
https://clang.llvm.org/docs/LTOVisibility.html

Bug chromium:720933

Change-Id: I87f9b09921a1b2d443121efcdb5525ff4cb5797b
Reviewed-on: https://swiftshader-review.googlesource.com/9688
Tested-by: Nicolas Capens <capn@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
20 files changed:
src/Common/BUILD.gn
src/Main/BUILD.gn
src/Main/FrameBuffer.hpp
src/OpenGL/common/BUILD.gn
src/OpenGL/common/Image.hpp
src/OpenGL/common/Object.hpp
src/OpenGL/compiler/BUILD.gn
src/OpenGL/compiler/Compiler.vcxproj
src/OpenGL/libEGL/BUILD.gn
src/OpenGL/libEGL/Context.hpp
src/OpenGL/libEGL/Display.h
src/OpenGL/libEGL/EGLSurface.h
src/OpenGL/libEGL/libEGL.vcxproj
src/OpenGL/libGLESv2/BUILD.gn
src/OpenGL/libGLESv2/Context.h
src/OpenGL/libGLESv2/libGLESv2.vcxproj
src/Renderer/BUILD.gn
src/Renderer/Surface.hpp
src/Shader/BUILD.gn
src/SwiftShader/SwiftShader.vcxproj

index b13c4f7..2fd4885 100644 (file)
 # Need a separate config to ensure the warnings are added to the end.
 config("swiftshader_common_private_config") {
   if (is_win) {
-    cflags = [ "/wd4201" ]  # nameless struct/union
+    cflags = [
+      "/wd4201",  # nameless struct/union
+      "/wd5030",  # attribute is not recognized
+    ]
   } else {
     cflags = [ "-msse2" ]
     defines = [ "LOG_TAG=\"swiftshader_common\"" ]
index 23105e6..150d559 100644 (file)
 # Need a separate config to ensure the warnings are added to the end.
 config("swiftshader_main_private_config") {
   if (is_win) {
-    cflags = [ "/wd4201" ]  # nameless struct/union
+    cflags = [
+      "/wd4201",  # nameless struct/union
+      "/wd5030",  # attribute is not recognized
+    ]
 
     if (is_clang) {
       cflags += [
index a888c86..10ef6bc 100644 (file)
@@ -34,7 +34,7 @@ namespace sw
                int cursorHeight;
        };
 
-       class FrameBuffer
+       class [[clang::lto_visibility_public]] FrameBuffer
        {
                virtual void typeinfo();   // Dummy key method (https://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html)
 
index 03acd48..cb58ab8 100644 (file)
@@ -18,6 +18,7 @@ config("swiftshader_opengl_common_private_config") {
     cflags = [
       "/wd4201",  # nameless struct/union
       "/wd4324",  # structure was padded due to alignment specifier
+      "/wd5030",  # attribute is not recognized
     ]
   } else {
     defines = [ "LOG_TAG=\"swiftshader_opengl_common\"" ]
index c3ce604..63375b0 100644 (file)
@@ -46,7 +46,7 @@ GLsizei ComputePitch(GLsizei width, GLenum format, GLenum type, GLint alignment)
 GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format);
 size_t ComputePackingOffset(GLenum format, GLenum type, GLsizei width, GLsizei height, GLint alignment, GLint skipImages, GLint skipRows, GLint skipPixels);
 
-class Image : public sw::Surface, public gl::Object
+class [[clang::lto_visibility_public]] Image : public sw::Surface, public gl::Object
 {
        virtual void typeinfo();   // Dummy key method (https://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html)
 
index c9584e1..c6243ac 100644 (file)
@@ -28,7 +28,7 @@ typedef unsigned int GLuint;
 namespace gl
 {
 
-class Object
+class [[clang::lto_visibility_public]] Object
 {
 public:
        Object();
index 0a85bbe..5da9390 100644 (file)
@@ -20,6 +20,7 @@ config("swiftshader_opengl_compiler_private_config") {
       "/wd4201",  # nameless struct/union
       "/wd4267",  # conversion from size_t to int/unsigned int
       "/wd4702",  # unreachable code (in autogenerated code)
+      "/wd5030",  # attribute is not recognized
     ]
 
     if (!is_debug) {
index fa47d12..58a0e5a 100644 (file)
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
       <BrowseInformation>true</BrowseInformation>\r
       <TreatWarningAsError>true</TreatWarningAsError>\r
-      <DisableSpecificWarnings>4005;</DisableSpecificWarnings>\r
+      <DisableSpecificWarnings>5030;4005;</DisableSpecificWarnings>\r
       <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
     </ClCompile>\r
   </ItemDefinitionGroup>\r
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
       <BrowseInformation>true</BrowseInformation>\r
       <TreatWarningAsError>true</TreatWarningAsError>\r
-      <DisableSpecificWarnings>4005;4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
+      <DisableSpecificWarnings>5030;4005;4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
       <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
     </ClCompile>\r
   </ItemDefinitionGroup>\r
       <WarningLevel>Level3</WarningLevel>\r
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
       <TreatWarningAsError>true</TreatWarningAsError>\r
-      <DisableSpecificWarnings>4005;</DisableSpecificWarnings>\r
+      <DisableSpecificWarnings>5030;4005;</DisableSpecificWarnings>\r
       <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
     </ClCompile>\r
   </ItemDefinitionGroup>\r
       <WarningLevel>Level3</WarningLevel>\r
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
       <TreatWarningAsError>true</TreatWarningAsError>\r
-      <DisableSpecificWarnings>4005;4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
+      <DisableSpecificWarnings>5030;4005;4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
       <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
     </ClCompile>\r
   </ItemDefinitionGroup>\r
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
       <OmitFramePointers>false</OmitFramePointers>\r
       <TreatWarningAsError>true</TreatWarningAsError>\r
-      <DisableSpecificWarnings>4005;</DisableSpecificWarnings>\r
+      <DisableSpecificWarnings>5030;4005;</DisableSpecificWarnings>\r
     </ClCompile>\r
   </ItemDefinitionGroup>\r
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">\r
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
       <OmitFramePointers>false</OmitFramePointers>\r
       <TreatWarningAsError>true</TreatWarningAsError>\r
-      <DisableSpecificWarnings>4005;4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
+      <DisableSpecificWarnings>5030;4005;4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
     </ClCompile>\r
   </ItemDefinitionGroup>\r
   <ItemGroup>\r
index bcfbdc0..6286070 100644 (file)
@@ -22,6 +22,7 @@ config("swiftshader_libEGL_private_config") {
     cflags = [
       "/wd4201",  # nameless struct/union
       "/wd4065",  # switch statement contains 'default' but no 'case' labels
+      "/wd5030",  # attribute is not recognized
     ]
 
     defines += [
index 182516e..da3246c 100644 (file)
@@ -26,7 +26,7 @@ class Display;
 class Surface;
 class Image;
 
-class Context : public gl::Object
+class [[clang::lto_visibility_public]] Context : public gl::Object
 {
 public:
        Context(egl::Display *display) : display(display) {}
index 7677c6c..3fba9e7 100644 (file)
@@ -35,7 +35,7 @@ namespace egl
        const EGLDisplay PRIMARY_DISPLAY  = reinterpret_cast<EGLDisplay>((intptr_t)1);
        const EGLDisplay HEADLESS_DISPLAY = reinterpret_cast<EGLDisplay>((intptr_t)0xFACE1E55);
 
-       class Display
+       class [[clang::lto_visibility_public]] Display
        {
                virtual void typeinfo();   // Dummy key method (https://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html)
 
index 555520e..3ebc2e4 100644 (file)
@@ -31,7 +31,7 @@ class Config;
 class Texture;
 class Image;
 
-class Surface : public gl::Object
+class [[clang::lto_visibility_public]] Surface : public gl::Object
 {
        virtual void typeinfo();   // Dummy key method (https://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html)
 
index 0c0cbaa..795d598 100644 (file)
       <BrowseInformation>true</BrowseInformation>\r
       <TreatWarningAsError>true</TreatWarningAsError>\r
       <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+      <DisableSpecificWarnings>5030</DisableSpecificWarnings>\r
     </ClCompile>\r
     <Link>\r
       <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>\r
@@ -160,6 +161,7 @@ copy "$(OutDir)libEGL.dll" "$(SolutionDir)lib\$(Configuration)_$(Platform)\trans
       <BrowseInformation>true</BrowseInformation>\r
       <TreatWarningAsError>true</TreatWarningAsError>\r
       <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+      <DisableSpecificWarnings>5030</DisableSpecificWarnings>\r
     </ClCompile>\r
     <Link>\r
       <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>\r
@@ -191,6 +193,7 @@ copy "$(OutDir)libEGL.dll" "$(SolutionDir)lib\$(Configuration)_$(Platform)\trans
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
       <TreatWarningAsError>true</TreatWarningAsError>\r
       <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+      <DisableSpecificWarnings>5030</DisableSpecificWarnings>\r
     </ClCompile>\r
     <Link>\r
       <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>\r
@@ -222,6 +225,7 @@ copy "$(OutDir)libEGL.dll" "$(SolutionDir)lib\$(Configuration)_$(Platform)\trans
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
       <TreatWarningAsError>true</TreatWarningAsError>\r
       <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
+      <DisableSpecificWarnings>5030</DisableSpecificWarnings>\r
     </ClCompile>\r
     <Link>\r
       <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>\r
@@ -255,6 +259,7 @@ copy "$(OutDir)libEGL.dll" "$(SolutionDir)lib\$(Configuration)_$(Platform)\trans
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
       <OmitFramePointers>false</OmitFramePointers>\r
       <TreatWarningAsError>true</TreatWarningAsError>\r
+      <DisableSpecificWarnings>5030</DisableSpecificWarnings>\r
     </ClCompile>\r
     <Link>\r
       <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>\r
@@ -286,6 +291,7 @@ copy "$(OutDir)libEGL.dll" "$(SolutionDir)lib\$(Configuration)_$(Platform)\trans
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
       <OmitFramePointers>false</OmitFramePointers>\r
       <TreatWarningAsError>true</TreatWarningAsError>\r
+      <DisableSpecificWarnings>5030</DisableSpecificWarnings>\r
     </ClCompile>\r
     <Link>\r
       <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>\r
index 46a9bfe..59f4f6d 100644 (file)
@@ -25,6 +25,7 @@ config("swiftshader_libGLESv2_private_config") {
     cflags = [
       "/wd4201",  # nameless struct/union
       "/wd4324",  # structure was padded due to alignment specifier
+      "/wd5030",  # attribute is not recognized
     ]
 
     defines += [
index 3a7431a..a6c6e71 100644 (file)
@@ -426,12 +426,12 @@ struct State
        GLint packSkipImages;
 };
 
-class Context : public egl::Context
+class [[clang::lto_visibility_public]] Context : public egl::Context
 {
 public:
        Context(egl::Display *display, const Context *shareContext, EGLint clientVersion);
 
-       virtual void makeCurrent(egl::Surface *surface);
+       void makeCurrent(egl::Surface *surface) override;
        virtual EGLint getClientVersion() const;
 
        void markAllStateDirty();
@@ -673,7 +673,7 @@ public:
        void clearStencilBuffer(const GLint value);
        void drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount = 1);
        void drawElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLsizei instanceCount = 1);
-       void finish();
+       void finish() override;
        void flush();
 
        void recordInvalidEnum();
@@ -690,9 +690,9 @@ public:
                             GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
                             GLbitfield mask, bool filter, bool allowPartialDepthStencilBlit);
 
-       virtual void bindTexImage(egl::Surface *surface);
-       virtual EGLenum validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel);
-       virtual egl::Image *createSharedImage(EGLenum target, GLuint name, GLuint textureLevel);
+       void bindTexImage(egl::Surface *surface) override;
+       EGLenum validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel) override;
+       egl::Image *createSharedImage(EGLenum target, GLuint name, GLuint textureLevel) override;
        egl::Image *getSharedImage(GLeglImageOES image);
 
        Device *getDevice();
index 767c43e..5750080 100644 (file)
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
       <BrowseInformation>true</BrowseInformation>\r
       <TreatWarningAsError>true</TreatWarningAsError>\r
-      <DisableSpecificWarnings>%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
+      <DisableSpecificWarnings>5030;%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
       <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
     </ClCompile>\r
     <Link>\r
@@ -165,7 +165,7 @@ copy "$(OutDir)libGLESv2.dll" "$(SolutionDir)lib\$(Configuration)_$(Platform)\tr
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
       <BrowseInformation>true</BrowseInformation>\r
       <TreatWarningAsError>true</TreatWarningAsError>\r
-      <DisableSpecificWarnings>%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
+      <DisableSpecificWarnings>5030;%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
       <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
     </ClCompile>\r
     <Link>\r
@@ -202,7 +202,7 @@ copy "$(OutDir)libGLESv2.dll" "$(SolutionDir)lib\$(Configuration)_$(Platform)\tr
       <WholeProgramOptimization>true</WholeProgramOptimization>\r
       <IntrinsicFunctions>false</IntrinsicFunctions>\r
       <TreatWarningAsError>true</TreatWarningAsError>\r
-      <DisableSpecificWarnings>%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
+      <DisableSpecificWarnings>5030;%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
       <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
     </ClCompile>\r
     <Link>\r
@@ -240,7 +240,7 @@ copy "$(OutDir)libGLESv2.dll" "$(SolutionDir)lib\$(Configuration)_$(Platform)\tr
       <WholeProgramOptimization>true</WholeProgramOptimization>\r
       <IntrinsicFunctions>false</IntrinsicFunctions>\r
       <TreatWarningAsError>true</TreatWarningAsError>\r
-      <DisableSpecificWarnings>%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
+      <DisableSpecificWarnings>5030;%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
       <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
     </ClCompile>\r
     <Link>\r
@@ -279,7 +279,7 @@ copy "$(OutDir)libGLESv2.dll" "$(SolutionDir)lib\$(Configuration)_$(Platform)\tr
       <WholeProgramOptimization>true</WholeProgramOptimization>\r
       <IntrinsicFunctions>false</IntrinsicFunctions>\r
       <TreatWarningAsError>true</TreatWarningAsError>\r
-      <DisableSpecificWarnings>%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
+      <DisableSpecificWarnings>5030;%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
     </ClCompile>\r
     <Link>\r
       <AdditionalDependencies>dxguid.lib;WS2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
@@ -315,7 +315,7 @@ copy "$(OutDir)libGLESv2.dll" "$(SolutionDir)lib\$(Configuration)_$(Platform)\tr
       <WholeProgramOptimization>true</WholeProgramOptimization>\r
       <IntrinsicFunctions>false</IntrinsicFunctions>\r
       <TreatWarningAsError>true</TreatWarningAsError>\r
-      <DisableSpecificWarnings>%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
+      <DisableSpecificWarnings>5030;%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
     </ClCompile>\r
     <Link>\r
       <AdditionalDependencies>dxguid.lib;WS2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
index d53efc4..301b106 100644 (file)
@@ -18,6 +18,7 @@ config("swiftshader_renderer_private_config") {
     cflags = [
       "/wd4201",  # nameless struct/union
       "/wd4324",  # structure was padded due to alignment specifier
+      "/wd5030",  # attribute is not recognized
     ]
   } else {
     cflags = [
index 4268a3a..fa04393 100644 (file)
@@ -217,7 +217,7 @@ namespace sw
                LOCK_DISCARD
        };
 
-       class Surface
+       class [[clang::lto_visibility_public]] Surface
        {
        private:
                struct Buffer
index 9482ef6..d1323f7 100644 (file)
@@ -18,6 +18,7 @@ config("swiftshader_shader_private_config") {
     cflags = [
       "/wd4201",  # nameless struct/union
       "/wd4324",  # structure was padded due to alignment specifier
+      "/wd5030",  # attribute is not recognized
     ]
 
     if (is_clang) {
index 26062f1..1ab5865 100644 (file)
       <BrowseInformation>true</BrowseInformation>\r
       <WarningLevel>Level3</WarningLevel>\r
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
-      <DisableSpecificWarnings>%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
+      <DisableSpecificWarnings>5030;%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
       <RuntimeTypeInfo>false</RuntimeTypeInfo>\r
       <TreatWarningAsError>true</TreatWarningAsError>\r
       <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
       <BrowseInformation>true</BrowseInformation>\r
       <WarningLevel>Level3</WarningLevel>\r
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
-      <DisableSpecificWarnings>%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
+      <DisableSpecificWarnings>5030;%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
       <RuntimeTypeInfo>false</RuntimeTypeInfo>\r
       <TreatWarningAsError>true</TreatWarningAsError>\r
       <MultiProcessorCompilation>true</MultiProcessorCompilation>\r
       <WarningLevel>Level3</WarningLevel>\r
       <DebugInformationFormat>\r
       </DebugInformationFormat>\r
-      <DisableSpecificWarnings>%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
+      <DisableSpecificWarnings>5030;%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
       <ForcedIncludeFiles>%(ForcedIncludeFiles)</ForcedIncludeFiles>\r
       <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>\r
       <StringPooling>true</StringPooling>\r
       </PrecompiledHeader>\r
       <WarningLevel>Level3</WarningLevel>\r
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
-      <DisableSpecificWarnings>%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
+      <DisableSpecificWarnings>5030;%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
       <ForcedIncludeFiles>%(ForcedIncludeFiles)</ForcedIncludeFiles>\r
       <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>\r
       <StringPooling>true</StringPooling>\r
       <WarningLevel>Level3</WarningLevel>\r
       <DebugInformationFormat>\r
       </DebugInformationFormat>\r
-      <DisableSpecificWarnings>%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
+      <DisableSpecificWarnings>5030;%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
       <ForcedIncludeFiles>%(ForcedIncludeFiles)</ForcedIncludeFiles>\r
       <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>\r
       <StringPooling>true</StringPooling>\r
       </PrecompiledHeader>\r
       <WarningLevel>Level3</WarningLevel>\r
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
-      <DisableSpecificWarnings>%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
+      <DisableSpecificWarnings>5030;%(DisableSpecificWarnings)</DisableSpecificWarnings>\r
       <ForcedIncludeFiles>%(ForcedIncludeFiles)</ForcedIncludeFiles>\r
       <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>\r
       <StringPooling>true</StringPooling>\r