[Mesa-dev] [PATCH 1/2] glsl: don't attempt to link empty program

Timothy Arceri timothy.arceri at collabora.com
Mon Jan 25 03:56:11 PST 2016


Previously an empty program would go through the entire
link_shaders() function and we would have to be careful
not to cause a segfault.

We also now set link_status to false by throwing an error,
it was previously set to true.

>From Section 7.3 (PROGRAM OBJECTS) of the OpenGL 4.5 spec:

   "Linking can fail for a variety of reasons as specified in the
   OpenGL Shading Language Specification, as well as any of the
   following reasons:

    - No shader objects are attached to program."

"# Please enter the commit message for your changes. Lines starting
---

 Fixes required in piglit due to the change in the link_status flag:

 http://patchwork.freedesktop.org/patch/71555/

 src/glsl/linker.cpp | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index 6657777..927e2f3 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -4105,14 +4105,21 @@ disable_varying_optimizations_for_sso(struct gl_shader_program *prog)
 void
 link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
 {
+   prog->Validated = false;
+   prog->_Used = false;
+
+   /* Don't attempt to link an empty program */
+   if (prog->NumShaders == 0) {
+      linker_error(prog, "no shaders attached to the program\n");
+      return;
+   }
+
    tfeedback_decl *tfeedback_decls = NULL;
    unsigned num_tfeedback_decls = prog->TransformFeedback.NumVarying;
 
    void *mem_ctx = ralloc_context(NULL); // temporary linker context
 
    prog->LinkStatus = true; /* All error paths will set this to false */
-   prog->Validated = false;
-   prog->_Used = false;
 
    prog->ARB_fragment_coord_conventions_enable = false;
 
-- 
2.4.3



More information about the mesa-dev mailing list