I'm trying to build spring for the up-coming Fedora 15 release and I'm facing a Lua compilation issue.
/builddir/build/BUILD/spring_0.82.7.1/rts/Lua/LuaMaterial.cpp: In member function 'void LuaMaterial::Execute(const LuaMaterial&) const': /builddir/build/BUILD/spring_0.82.7.1/rts/Lua/LuaMaterial.cpp:382:91: error: taking address of temporary [-fpermissive]
Looking at the code, I can only assume that GCC 4.6 really doesn't like this code part:
Code:
if (shadowParamsLoc >= 0) { glUniform4fv(shadowParamsLoc, 1, const_cast<float*>(&(shadowHandler->GetShadowParams().x))); }
(Most likely a data locality issue with GetShadowParams).
I could simply -fpermissive and drop the error altogether, but I rather find some other (nicer?) solution (E.g. copy the value to a local variable and push it from there).
Joined: 01 Jun 2005, 10:36 Location: The Netherlands
That solution will not work. The "4fv" part at the end of glUniform4fv means it expects to get a pointer to 4 floats, so by copying only the one float to a temporary you solve the compiler error, but introduce a bug. (The other three floats being garbage.)
You'll need to copy the whole float4 to a temporary and then pass in the address of the x component of that temporary. That should probably get rid of the error and not introduce a bug
minor things: don't follow that C rule of declaring local vars at function start, but declare them where they are used. maybe call it something like shadowParams instead of fTemp. add a comment why the temp var is needed, like // GCC 4.6+ requires .... without a comment, someone with GCC 4.5- will undo it in some weeks or months.
That solution will not work. The "4fv" part at the end of glUniform4fv means it expects to get a pointer to 4 floats, so by copying only the one float to a temporary you solve the compiler error, but introduce a bug. (The other three floats being garbage.)
You'll need to copy the whole float4 to a temporary and then pass in the address of the x component of that temporary. That should probably get rid of the error and not introduce a bug
Thanks. I wondered if the count = 1 meant 1 float or one float block. Side question: How many times is function being called; I'd hate to add useless-compiler-warning-killing memcpy to function that's being called 1,000,000 times a second.
the preferred way to submit a patch is, to fork spring on guithub, commit your patch there, and tell us to merge it into master, either by a forum post, a PM, or by using githubs pull request. to be able to fork spring, you need to have an account on github. then go here: https://github.com/spring/spring and use the [Fork] button (3rd line of links/buttons). then commit your patch (to git@github.com:gilboa/spring.git). if you are new to git/github, theres lots of good info here: http://help.github.com/ or just ask for help about specific stuff in the spring dev channel in the lobby. everyone loves to give git help.
if that is too much work for you/you do not plan to make other patches... as this is a relatively simple thing, just tell us to do it/send a patch file (based on a recent master commit) in here.
Sorry for the late reply. It seems that gcc breaks spring in a number of places. (missing includes, local variables, etc). I'll create a mega patch and continue from there.
--- rts/Map/SMF/BFGroundDrawer.cpp.old 2011-03-28 12:51:56.331599362 +0200 +++ rts/Map/SMF/BFGroundDrawer.cpp 2011-03-28 12:54:43.209600038 +0200 @@ -1342,7 +1342,23 @@ smfShaderGLSL->Enable(); smfShaderGLSL->SetUniform3fv(10, &camera->pos[0]); smfShaderGLSL->SetUniformMatrix4fv(12, false, &shadowHandler->shadowMatrix.m[0]); - smfShaderGLSL->SetUniform4fv(13, const_cast<float*>(&(shadowHandler->GetShadowParams().x))); + + { + /* + * GCC 4.6 barfs on having a temporary copy of float4 + * passed as pointer to glUniform4fv. + * Pending a cleaner solution that will include + * changes to shadowHandler and float4, + * the only thing remaining is to manually copy + * the members to temporary stack array and pass + * it down to glUniform4fv. + */ + float4 shadowFloat4 = + shadowHandler->GetShadowParams(); + float shadowFloatArr[4]; + + smfShaderGLSL->SetUniform4fv(13, shadowFloat4.as_float_arr(shadowFloatArr)); + }
if (globalRendering->haveGLSL) { grassShader->SetUniformMatrix4fv(6, false, &shadowHandler->shadowMatrix.m[0]); - grassShader->SetUniform4fv(7, const_cast<float*>(&(shadowHandler->GetShadowParams().x))); + + { + /* + * GCC 4.6 barfs on having a temporary copy of float4 + * passed as pointer to glUniform4fv. + * Pending a cleaner solution that will include + * changes to shadowHandler and float4, + * the only thing remaining is to manually copy + * the members to temporary stack array and pass + * it down to glUniform4fv. + */ + float4 shadowFloat4 = + shadowHandler->GetShadowParams(); + float shadowFloatArr[4]; + + grassShader->SetUniform4fv(7, shadowFloat4.as_float_arr(shadowFloatArr)); + } + grassShader->SetUniform1f(8, gs->frameNum); grassShader->SetUniform3fv(9, const_cast<float*>(&(windSpeed.x))); } else { @@ -585,7 +607,24 @@
if (globalRendering->haveGLSL) { grassShader->SetUniformMatrix4fv(6, false, &shadowHandler->shadowMatrix.m[0]); - grassShader->SetUniform4fv(7, const_cast<float*>(&(shadowHandler->GetShadowParams().x))); + + { + /* + * GCC 4.6 barfs on having a temporary copy of float4 + * passed as pointer to glUniform4fv. + * Pending a cleaner solution that will include + * changes to shadowHandler and float4, + * the only thing remaining is to manually copy + * the members to temporary stack array and pass + * it down to glUniform4fv. + */ + float4 shadowFloat4 = + shadowHandler->GetShadowParams(); + float shadowFloatArr[4]; + + grassShader->SetUniform4fv(7, shadowFloat4.as_float_arr(shadowFloatArr)); + } + grassShader->SetUniform1f(8, gs->frameNum); grassShader->SetUniform3fv(9, const_cast<float*>(&(windSpeed.x))); } --- rts/Rendering/Env/AdvTreeDrawer.cpp.old 2011-03-28 14:29:47.511601193 +0200 +++ rts/Rendering/Env/AdvTreeDrawer.cpp 2011-03-28 14:35:20.958600022 +0200 @@ -458,7 +458,22 @@
if (globalRendering->haveGLSL) { treeShader->SetUniformMatrix4fv(7, false, &shadowHandler->shadowMatrix.m[0]); - treeShader->SetUniform4fv(8, const_cast<float*>(&(shadowHandler->GetShadowParams().x))); + { + /* + * GCC 4.6 barfs on having a temporary copy of float4 + * passed as pointer to glUniform4fv. + * Pending a cleaner solution that will include + * changes to shadowHandler and float4, + * the only thing remaining is to manually copy + * the members to temporary stack array and pass + * it down to glUniform4fv. + */ + float4 shadowFloat4 = + shadowHandler->GetShadowParams(); + float shadowFloatArr[4]; + + treeShader->SetUniform4fv(8, shadowFloat4.as_float_arr(shadowFloatArr)); + } } else { treeShader->SetUniformTarget(GL_FRAGMENT_PROGRAM_ARB); treeShader->SetUniform4f(10, L.groundAmbientColor.x, L.groundAmbientColor.y, L.groundAmbientColor.z, 1.0f); @@ -501,7 +521,23 @@
if (globalRendering->haveGLSL) { treeShader->SetUniformMatrix4fv(7, false, &shadowHandler->shadowMatrix.m[0]); - treeShader->SetUniform4fv(8, const_cast<float*>(&(shadowHandler->GetShadowParams().x))); + + { + /* + * GCC 4.6 barfs on having a temporary copy of float4 + * passed as pointer to glUniform4fv. + * Pending a cleaner solution that will include + * changes to shadowHandler and float4, + * the only thing remaining is to manually copy + * the members to temporary stack array and pass + * it down to glUniform4fv. + */ + float4 shadowFloat4 = + shadowHandler->GetShadowParams(); + float shadowFloatArr[4]; + + treeShader->SetUniform4fv(8, shadowFloat4.as_float_arr(shadowFloatArr)); + } }
if (shadowParamsLoc >= 0) { - glUniform4fv(shadowParamsLoc, 1, const_cast<float*>(&(shadowHandler->GetShadowParams().x))); + /* + * GCC 4.6 barfs on having a temporary copy of float4 + * passed as pointer to glUniform4fv. + * Pending a cleaner solution that will include + * changes to shadowHandler and float4, + * the only thing remaining is to manually copy + * the members to temporary stack array and pass + * it down to glUniform4fv. + */ + float4 shadowFloat4 = + shadowHandler->GetShadowParams(); + float shadowFloatArr[4]; + + glUniform4fv(shadowParamsLoc, 1, shadowFloat4.as_float_arr(shadowFloatArr)); }
const int maxTex = std::max(texCount, prev.texCount); --- rts/Rendering/UnitDrawer.cpp.old 2011-03-28 14:11:57.129599851 +0200 +++ rts/Rendering/UnitDrawer.cpp 2011-03-28 14:14:01.937599970 +0200 @@ -1195,7 +1195,23 @@ modelShaders[MODEL_SHADER_S3O_ACTIVE]->SetUniformMatrix4dv(7, false, const_cast<double*>(camera->GetViewMat())); modelShaders[MODEL_SHADER_S3O_ACTIVE]->SetUniformMatrix4dv(8, false, const_cast<double*>(camera->GetViewMatInv())); modelShaders[MODEL_SHADER_S3O_ACTIVE]->SetUniformMatrix4fv(13, false, &shadowHandler->shadowMatrix.m[0]); - modelShaders[MODEL_SHADER_S3O_ACTIVE]->SetUniform4fv(14, const_cast<float*>(&(shadowHandler->GetShadowParams().x))); + + { + /* + * GCC 4.6 barfs on having a temporary copy of float4 + * passed as pointer to glUniform4fv. + * Pending a cleaner solution that will include + * changes to shadowHandler and float4, + * the only thing remaining is to manually copy + * the members to temporary stack array and pass + * it down to glUniform4fv. + */ + float4 shadowFloat4 = + shadowHandler->GetShadowParams(); + float shadowFloatArr[4]; + + modelShaders[MODEL_SHADER_S3O_ACTIVE]->SetUniform4fv(14, shadowFloat4.as_float_arr(shadowFloatArr)); + } } else { modelShaders[MODEL_SHADER_S3O_ACTIVE]->SetUniformTarget(GL_VERTEX_PROGRAM_ARB); modelShaders[MODEL_SHADER_S3O_ACTIVE]->SetUniform4f(10, mapInfo->light.sunDir.x, mapInfo->light.sunDir.y ,mapInfo->light.sunDir.z, 0.0f); --- rts/System/float4.h.old 2011-03-31 06:13:26.908050146 +0200 +++ rts/System/float4.h 2011-03-31 06:16:38.697117765 +0200 @@ -54,6 +54,13 @@ return !(*this == f); }
Those changes are still much more invasive than necessary. Fix the problem at its source (as has been done in master) instead:
Won't work. As far as I could test, GCC 4.6 (at least when using the default Fedora 15 configuration) barfs on two things: 1. Automatic conversion of float4 to float *. 2. Having a non-local variable (read: not in stack and/or heap) being passed as pointer to a functions.
As far as I could test, I -must- have a local copy of float[4] in the current function's stack, or I trigger a "-fno-permissive" GCC error.
this should be a pretty straightforward issue -- I'm trying to compile Lua (or rather lua-vec, which is a minor variant) on a CentOS Linux install, and I get the following error:
[jt@flyboy src]#make linux make all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses" make[1]: Entering directory `/jt/flyboy/fly/lua/lua-vec/src' gcc -o lua lua.o liblua.a -lm -Wl,-E -ldl -lreadline -lhistory -lncurses /usr/bin/ld: cannot find -lreadline collect2: ld returned 1 exit status make[1]: *** [lua] Error 1
That would suggest the readline lib is not installed. But...
Interestingly, if I rearrange the order of readline/history/ncurses, whichever is first triggers the same error, so I suspect that this is some sort of a folder-specification problem, not a missing library problem.
Users browsing this forum: No registered users and 1 guest
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum