Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: mirai on May 10, 2012, 02:44:31 pm

Title: Possible flaw in C::B build system
Post by: mirai on May 10, 2012, 02:44:31 pm
I think I found a flaw in Code::Blocks build system.

While trying to fix a recent bug about relative file paths found in cbp2make, I was playing around with a test dummy project supplied by the reporter. After reproducing the bug the next thing I tried is checking how C::B is compiling this project and I found that it puts all object files for sources in upper directories to the same "root" object directory. But what if a project is big and there are few files with different content, but with just the same file names? I added another .cpp file to the project with the same name to another directory. When at least one of such files is higher in directory tree and is referenced by a relative path, C::B fails to build the project, but, if both files are not above the project file (same level or below) then everything works perfectly.

Aside from telling that one should not create such projects intentionally I would suggest to make corrections to C::B build system. I would try fix this by replacing ".." in relative paths with something like underscores as an easiest way to put mistakenly interfering files apart in object files' directory.

What do C::B devs think about this problem?
Title: Re: Possible flaw in C::B build system
Post by: oBFusCATed on May 10, 2012, 02:48:12 pm
Post a demo project...
Title: Re: Possible flaw in C::B build system
Post by: mirai on May 10, 2012, 03:03:02 pm
Test projects: https://sourceforge.net/apps/mantisbt/cbp2make/file_download.php?file_id=2&type=bug (https://sourceforge.net/apps/mantisbt/cbp2make/file_download.php?file_id=2&type=bug)

p.s. Sorry for broken link :)
Title: Re: Possible flaw in C::B build system
Post by: MortenMacFly on May 10, 2012, 03:10:54 pm
Test projects: https://sourceforge.net/apps/mantisbt/cbp2make/file_download.php?file_id=2&type=bug (https://sourceforge.net/apps/mantisbt/cbp2make/file_download.php?file_id=1&type=bug)
There I see:
Issue 0 not found.
???
Title: Re: Possible flaw in C::B build system
Post by: MortenMacFly on May 10, 2012, 07:47:52 pm
Argh... I've uploaded the file to a wrong issue and then moved it to the right one... Here's the link: https://sourceforge.net/apps/mantisbt/cbp2make/file_download.php?file_id=1&type=bug (https://sourceforge.net/apps/mantisbt/cbp2make/file_download.php?file_id=1&type=bug)
Mmmmh... that did change it to this message:
APPLICATION ERROR #1100

Issue 0 not found.
Title: Re: Possible flaw in C::B build system
Post by: oBFusCATed on May 10, 2012, 08:03:58 pm
http://sourceforge.net/apps/mantisbt/cbp2make/view.php?id=2
Title: Re: Possible flaw in C::B build system
Post by: mirai on May 11, 2012, 11:08:09 am
Well, you finally got the file. :)  Sorry for accidentally posting wrong link twice...

So, what do you think about the topic ?
Title: Re: Possible flaw in C::B build system
Post by: MortenMacFly on May 14, 2012, 08:51:37 am
So, what do you think about the topic ?
I tried. All 3 examples work just fine for me inside C::B (I didn't try cbp2make). I had to create project files for the dummy 1/2 as they were not provided.

So wither you are using flat objects /which is certain to fail in this case, but also a setting you must explicitly set), or your project files are wrong. The latter I could not verify.
Title: Re: Possible flaw in C::B build system
Post by: mirai on May 15, 2012, 02:36:00 am
I tried. All 3 examples work just fine for me inside C::B (I didn't try cbp2make). I had to create project files for the dummy 1/2 as they were not provided.
Wait, you seem to did this wrong way. Project files are provided, but they are located two(three) levels down from top directory.
Indeed, this is the one of important test conditions.
The way you did it C::B system won't fail, because you made 1&2 cases into normal build as in 3rd case.

Nor the reporter nor me are using flat objects and the topic is not related to them because the build system will work or fail whenever objects are flat or not, this is just irrelevant.
Title: Re: Possible flaw in C::B build system
Post by: stahta01 on May 15, 2012, 04:26:43 am
2 out of 3 work for me; without modification using CB SVN 7965 self-built.

Code
-------------- Build: Debug in level2 (compiler: GNU GCC Compiler Dwarf 2)---------------

g++.exe -Wall  -g     -c C:\Users\stahta01\Downloads\relpath_tests\relpath_tests\dummy-3\level1\level2\level1.cpp -o obj\Debug\level1\level2\level1.o
g++.exe -Wall  -g     -c C:\Users\stahta01\Downloads\relpath_tests\relpath_tests\dummy-3\main.cpp -o obj\Debug\main.o
g++.exe -Wall  -g     -c C:\Users\stahta01\Downloads\relpath_tests\relpath_tests\dummy-3\root.cpp -o obj\Debug\root.o
g++.exe -Wall  -g     -c C:\Users\stahta01\Downloads\relpath_tests\relpath_tests\dummy-3\level1\level1.cpp -o obj\Debug\level1\level1.o
g++.exe  -o bin\Debug\level2.exe obj\Debug\level1\level2\level1.o obj\Debug\main.o obj\Debug\root.o obj\Debug\level1\level1.o    
Output size is 36.34 KB

-------------- Build: Debug in level2 (compiler: GNU GCC Compiler Dwarf 2)---------------

g++.exe -Wall  -g     -c C:\Users\stahta01\Downloads\relpath_tests\relpath_tests\dummy-1\level1\level2\main.cpp -o obj\Debug\main.o
g++.exe -Wall  -g     -c C:\Users\stahta01\Downloads\relpath_tests\relpath_tests\dummy-1\root.cpp -o obj\Debug\root.o
g++.exe -Wall  -g     -c C:\Users\stahta01\Downloads\relpath_tests\relpath_tests\dummy-1\level1\level1.cpp -o obj\Debug\level1.o
g++.exe  -o bin\Debug\level2.exe obj\Debug\main.o obj\Debug\root.o obj\Debug\level1.o    

You might want to post more info; note, naming the projects with different title might also help.

Got the last one to build after I renamed the file containing the function level2 to level2.cpp

Code
-------------- Build: Debug in level2 (compiler: GNU GCC Compiler Dwarf 2)---------------

g++.exe -Wmissing-include-dirs -Wextra -Wall  -g     -c C:\Users\stahta01\Downloads\relpath_tests\relpath_tests\dummy-2\level1\level2\main.cpp -o obj\Debug\main.o
g++.exe -Wmissing-include-dirs -Wextra -Wall  -g     -c C:\Users\stahta01\Downloads\relpath_tests\relpath_tests\dummy-2\root.cpp -o obj\Debug\root.o
g++.exe -Wmissing-include-dirs -Wextra -Wall  -g     -c C:\Users\stahta01\Downloads\relpath_tests\relpath_tests\dummy-2\level1\level1.cpp -o obj\Debug\level1.o
g++.exe -Wmissing-include-dirs -Wextra -Wall  -g     -c C:\Users\stahta01\Downloads\relpath_tests\relpath_tests\dummy-2\level1\level2\level2.cpp -o obj\Debug\level2.o
g++.exe  -o bin\Debug\level2.exe obj\Debug\main.o obj\Debug\root.o obj\Debug\level1.o obj\Debug\level2.o    
Output size is 36.34 KB

Tim S.
Title: Re: Possible flaw in C::B build system
Post by: mirai on May 15, 2012, 06:43:22 am
2 out of 3 work for me; without modification using CB SVN 7965 self-built.
Yes, this is how it should be, 2 of 3, exactly.

You might want to post more info; note, naming the projects with different title might also help.
These are not actually my projects, the first of them is supplied by the bug reporter, and two consequent are my modifications to the first one. I've made them very quickly and didn't try to make them look any nicer than they were in the first place.

Got the last one to build after I renamed the file containing the function level2 to level2.cpp
And this is exactly what you shouldn't do. The project has to compile without making any changes to it. The GNU toolchain itself is perfectly happy with having two different "level1.o" objects to link when they are in different locations, but of course it won't work if both of them have same name AND location. The C::B build system fails here when it gives the same location of object files to sources with different initial locations. In a big project with 3rd party libraries [located outside project tree] this situation may happen purely accidentally and the project won't be built while it should.

Code
-------------- Build: Debug in level2 (compiler: GNU GCC Compiler Dwarf 2)---------------

g++.exe -Wmissing-include-dirs -Wextra -Wall  -g     -c C:\Users\stahta01\Downloads\relpath_tests\relpath_tests\dummy-2\level1\level2\main.cpp -o obj\Debug\main.o
g++.exe -Wmissing-include-dirs -Wextra -Wall  -g     -c C:\Users\stahta01\Downloads\relpath_tests\relpath_tests\dummy-2\root.cpp -o obj\Debug\root.o
g++.exe -Wmissing-include-dirs -Wextra -Wall  -g     -c C:\Users\stahta01\Downloads\relpath_tests\relpath_tests\dummy-2\level1\level1.cpp -o obj\Debug\level1.o
g++.exe -Wmissing-include-dirs -Wextra -Wall  -g     -c C:\Users\stahta01\Downloads\relpath_tests\relpath_tests\dummy-2\level1\level2\level2.cpp -o obj\Debug\level2.o
g++.exe  -o bin\Debug\level2.exe obj\Debug\main.o obj\Debug\root.o obj\Debug\level1.o obj\Debug\level2.o    
Output size is 36.34 KB
Tim S.
This log clearly displays the flaw, just don't do that renaming.
Title: Re: Possible flaw in C::B build system
Post by: Jenna on May 15, 2012, 10:53:16 am
I can confirm this issue.
A possible fix might be to always use the common toplevel path as relative path below the object output directory.
It seems we do not do that, but use the path relative to the project-file and just cut off all ".."'s.

Title: Re: Possible flaw in C::B build system
Post by: Jenna on May 15, 2012, 02:50:11 pm
Can you (and other devs) please test the attached patch ?

I did not test what happens, if files in a project are on different drives in windows.
Title: Re: Possible flaw in C::B build system
Post by: MortenMacFly on May 17, 2012, 06:37:51 am
Can you (and other devs) please test the attached patch ?
Tested. All three projects build now. "Go ahead" from my side...
Title: Re: Possible flaw in C::B build system
Post by: Jenna on May 19, 2012, 04:32:54 pm
Can you (and other devs) please test the attached patch ?
Tested. All three projects build now. "Go ahead" from my side...
There have been no objections from others, so I committed it in svn r7986.