Commit 8560e687 by Nicolas Capens

Add dummy key methods for UBSan RTTI.

Chromium UBSan builds require RTTI, for which GCC/Clang requires each class' first non-inline virtual method (the "key method") to have a known definition so that its address can be used as a unique type identifier: https://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html libEGL and libGLESv2 each use objects who's full definition only exists within one or the other. Methods for which the definition is unknown can still be called if they are virtual, because the compiler/linker only needs to know the vtable entry offset. But because of the GCC/Clang requirement of having the first non-inline virtual method be fully defined, we need to add dummy virtual methods and their definitions. Bug swiftshader:31 Change-Id: Ib146cac811388086b29dbb099266c43795d6ed31 Reviewed-on: https://swiftshader-review.googlesource.com/8708Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent f8faed6d
...@@ -36,6 +36,8 @@ namespace sw ...@@ -36,6 +36,8 @@ namespace sw
class FrameBuffer class FrameBuffer
{ {
virtual void typeinfo(); // Dummy key method (https://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html)
public: public:
FrameBuffer(int width, int height, bool fullscreen, bool topLeftOrigin); FrameBuffer(int width, int height, bool fullscreen, bool topLeftOrigin);
...@@ -103,6 +105,8 @@ namespace sw ...@@ -103,6 +105,8 @@ namespace sw
static bool topLeftOrigin; static bool topLeftOrigin;
}; };
inline void FrameBuffer::typeinfo() {}
} }
#endif // sw_FrameBuffer_hpp #endif // sw_FrameBuffer_hpp
...@@ -48,6 +48,8 @@ size_t ComputePackingOffset(GLenum format, GLenum type, GLsizei width, GLsizei h ...@@ -48,6 +48,8 @@ size_t ComputePackingOffset(GLenum format, GLenum type, GLsizei width, GLsizei h
class Image : public sw::Surface, public gl::Object class Image : public sw::Surface, public gl::Object
{ {
virtual void typeinfo(); // Dummy key method (https://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html)
public: public:
// 2D texture image // 2D texture image
Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type) Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type)
...@@ -192,6 +194,8 @@ protected: ...@@ -192,6 +194,8 @@ protected:
void loadD32FS8ImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, int inputPitch, int inputHeight, const void *input, void *buffer); void loadD32FS8ImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, int inputPitch, int inputHeight, const void *input, void *buffer);
}; };
inline void Image::typeinfo() {}
#ifdef __ANDROID__ #ifdef __ANDROID__
inline GLenum GLPixelFormatFromAndroid(int halFormat) inline GLenum GLPixelFormatFromAndroid(int halFormat)
......
...@@ -57,11 +57,6 @@ shared_library("swiftshader_libEGL") { ...@@ -57,11 +57,6 @@ shared_library("swiftshader_libEGL") {
if (is_debug) { if (is_debug) {
sources += [ "../common/debug.cpp" ] sources += [ "../common/debug.cpp" ]
} else if (is_linux) {
sources += [
"../../Renderer/Surface.cpp",
"../common/Image.cpp",
]
} }
if (is_mac) { if (is_mac) {
......
...@@ -37,6 +37,8 @@ namespace egl ...@@ -37,6 +37,8 @@ namespace egl
class Display class Display
{ {
virtual void typeinfo(); // Dummy key method (https://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html)
public: public:
static Display *get(EGLDisplay dpy); static Display *get(EGLDisplay dpy);
...@@ -97,6 +99,8 @@ namespace egl ...@@ -97,6 +99,8 @@ namespace egl
gl::NameSpace<Image> mSharedImageNameSpace; gl::NameSpace<Image> mSharedImageNameSpace;
}; };
inline void Display::typeinfo() {}
} }
#endif // INCLUDE_DISPLAY_H_ #endif // INCLUDE_DISPLAY_H_
...@@ -33,6 +33,8 @@ class Image; ...@@ -33,6 +33,8 @@ class Image;
class Surface : public gl::Object class Surface : public gl::Object
{ {
virtual void typeinfo(); // Dummy key method (https://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html)
public: public:
virtual bool initialize(); virtual bool initialize();
virtual void swap() = 0; virtual void swap() = 0;
...@@ -96,6 +98,8 @@ protected: ...@@ -96,6 +98,8 @@ protected:
EGLint swapInterval; EGLint swapInterval;
}; };
inline void Surface::typeinfo() {}
class WindowSurface : public Surface class WindowSurface : public Surface
{ {
public: public:
......
...@@ -250,6 +250,8 @@ namespace sw ...@@ -250,6 +250,8 @@ namespace sw
bool dirty; bool dirty;
}; };
virtual void typeinfo(); // Dummy key method (https://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html)
public: public:
Surface(int width, int height, int depth, Format format, void *pixels, int pitch, int slice); Surface(int width, int height, int depth, Format format, void *pixels, int pitch, int slice);
Surface(Resource *texture, int width, int height, int depth, Format format, bool lockable, bool renderTarget, int pitchP = 0); Surface(Resource *texture, int width, int height, int depth, Format format, bool lockable, bool renderTarget, int pitchP = 0);
...@@ -475,6 +477,8 @@ namespace sw ...@@ -475,6 +477,8 @@ namespace sw
namespace sw namespace sw
{ {
inline void Surface::typeinfo() {}
void *Surface::lock(int x, int y, int z, Lock lock, Accessor client, bool internal) void *Surface::lock(int x, int y, int z, Lock lock, Accessor client, bool internal)
{ {
return internal ? lockInternal(x, y, z, lock, client) : lockExternal(x, y, z, lock, client); return internal ? lockInternal(x, y, z, lock, client) : lockExternal(x, y, z, lock, client);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment