Author Topic: Possible flaw in C::B build system  (Read 15198 times)

Offline mirai

  • Multiple posting newcomer
  • *
  • Posts: 108
Possible flaw in C::B build system
« 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?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Possible flaw in C::B build system
« Reply #1 on: May 10, 2012, 02:48:12 pm »
Post a demo project...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline mirai

  • Multiple posting newcomer
  • *
  • Posts: 108
Re: Possible flaw in C::B build system
« Reply #2 on: May 10, 2012, 03:03:02 pm »
« Last Edit: May 10, 2012, 10:44:41 pm by mirai »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Possible flaw in C::B build system
« Reply #4 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
Mmmmh... that did change it to this message:
APPLICATION ERROR #1100

Issue 0 not found.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline mirai

  • Multiple posting newcomer
  • *
  • Posts: 108
Re: Possible flaw in C::B build system
« Reply #6 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 ?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Possible flaw in C::B build system
« Reply #7 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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline mirai

  • Multiple posting newcomer
  • *
  • Posts: 108
Re: Possible flaw in C::B build system
« Reply #8 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.
« Last Edit: May 15, 2012, 02:38:33 am by mirai »

Online stahta01

  • Lives here!
  • ****
  • Posts: 7588
    • My Best Post
Re: Possible flaw in C::B build system
« Reply #9 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.
« Last Edit: May 15, 2012, 04:48:23 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline mirai

  • Multiple posting newcomer
  • *
  • Posts: 108
Re: Possible flaw in C::B build system
« Reply #10 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.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Possible flaw in C::B build system
« Reply #11 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.


Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Possible flaw in C::B build system
« Reply #12 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.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Possible flaw in C::B build system
« Reply #13 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...
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Possible flaw in C::B build system
« Reply #14 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.