Author Topic: GCC 4.4.0-tdm-1 for MinGW (with installer)  (Read 69666 times)

sahasranaman

  • Guest
Re: GCC 4.4.0-tdm-1 for MinGW (with installer)
« Reply #30 on: June 13, 2009, 09:20:12 am »
Hi.

I tried rebuilding libsigc++ from source with GCC 4.4.0-tdm-1 (r2), and the .a file I get here appears to have the _Unwind_* symbols.

I downloaded libsigc++-2.2.3 and tried building with the newer release. I did a make, and the library file got built successfully, but the test programs that come with the source didn't get built, and it gave the same redefinition of _Unwind_* found, even when it was using the newly built library files built by the same make command. I'm pasting the output here.

I'm not sure if I have missed something. Or is there something I should change in the makefile? Please advice.

Code: [Select]
g++ -shared -nostdlib c:/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../dllcrt2.o c:/mingw/bin/../lib/gcc/mingw32/4.4.0/crtbegin.o  .libs/signal.o .libs/signal_base.o .libs/trackable.o .libs/connection.o .libs/slot.o .libs/slot_base.o .libs/lambda.o  -Lc:/mingw/bin/../lib/gcc/mingw32/4.4.0 -Lc:/mingw/bin/../lib/gcc -Lc:/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/lib -Lc:/mingw/bin/../lib/gcc/mingw32/4.4.0/../../.. -L/mingw/lib -lstdc++ -lmingw32 -lgcc_eh -lgcc -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell32 -lmingw32 -lgcc_eh -lgcc -lmoldname -lmingwex -lmsvcrt c:/mingw/bin/../lib/gcc/mingw32/4.4.0/crtend.o  -Wl,--export-all-symbols -o .libs/libsigc-2.0-0.dll -Wl,--enable-auto-image-base -Xlinker --out-implib -Xlinker .libs/libsigc-2.0.dll.a
Creating library file: .libs/libsigc-2.0.dll.a
copying selected object files to avoid basename conflicts...
rm -fr .libs/libsigc-2.0.lax
mkdir .libs/libsigc-2.0.lax
ar cru .libs/libsigc-2.0.a signal.o signal_base.o trackable.o connection.o slot.o slot_base.o lambda.o
ranlib .libs/libsigc-2.0.a
rm -fr .libs/libsigc-2.0.lax
creating libsigc-2.0.la
(cd .libs && rm -f libsigc-2.0.la && cp -p ../libsigc-2.0.la libsigc-2.0.la)
make[3]: Leaving directory `/c/opt/libsigc++-2.2.3/sigc++'
make[2]: Leaving directory `/c/opt/libsigc++-2.2.3/sigc++'
Making all in tests
make[2]: Entering directory `/c/opt/libsigc++-2.2.3/tests'
g++  -I. -I.. -I.. -I..    -g -O2 -MT test_trackable.o -MD -MP -MF .deps/test_trackable.Tpo -c -o test_trackable.o test_trackable.cc
mv -f .deps/test_trackable.Tpo .deps/test_trackable.Po
/bin/sh ../libtool --tag=CXX   --mode=link g++  -g -O2   -o test_trackable.exe test_trackable.o ../sigc++/libsigc-2.0.la
mkdir .libs
g++ -g -O2 -o .libs/test_trackable.exe test_trackable.o  ../sigc++/.libs/libsigc-2.0.dll.a  -L/usr/local/lib
c:/mingw/bin/../lib/gcc/mingw32/4.4.0/libgcc_eh.a(unwind-sjlj.o): In function `Unwind_SjLj_Unregister':
d:\crossdev\b4.4.0-tdm-1\mingw32\libgcc/../../../gcc-4.4.0/libgcc/../gcc/unwind-sjlj.c:189: multiple definition of `_Unwind_SjLj_Unregister'
../sigc++/.libs/libsigc-2.0.dll.a(d000019.o):(.text+0x0): first defined here
c:/mingw/bin/../lib/gcc/mingw32/4.4.0/libgcc_eh.a(unwind-sjlj.o): In function `Unwind_SjLj_Register':
d:\crossdev\b4.4.0-tdm-1\mingw32\libgcc/../../../gcc-4.4.0/libgcc/../gcc/unwind-sjlj.c:142: multiple definition of `_Unwind_SjLj_Register'
../sigc++/.libs/libsigc-2.0.dll.a(d000016.o):(.text+0x0): first defined here
c:/mingw/bin/../lib/gcc/mingw32/4.4.0/libgcc_eh.a(unwind-sjlj.o): In function `Unwind_SjLj_Resume':
d:\crossdev\b4.4.0-tdm-1\mingw32\libgcc/../../../gcc-4.4.0/libgcc/../gcc/unwind.inc:220: multiple definition of `_Unwind_SjLj_Resume'
../sigc++/.libs/libsigc-2.0.dll.a(d000017.o):(.text+0x0): first defined here
collect2: ld returned 1 exit status
make[2]: *** [test_trackable.exe] Error 1

Offline TDragon

  • Lives here!
  • ****
  • Posts: 936
    • Twilight Dragon Media
Re: GCC 4.4.0-tdm-1 for MinGW (with installer)
« Reply #31 on: June 13, 2009, 09:29:54 pm »
Post the output after adding "-v" to the link command for libsigc-2.0.dll.
http://tdm-gcc.tdragon.net/ - TDM-GCC compiler suite for Windows (GCC 5.1.0 2015-06-28, 32/64-bit, no extra DLLs)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: GCC 4.4.0-tdm-1 for MinGW (with installer)
« Reply #32 on: June 24, 2009, 04:51:37 pm »
Hi, I found a problem that I can't set breakpoint in a inline function.

For example: I have three files:

main.cpp

Code: [Select]
#include <iostream>
using namespace std;
#include "a.h"
int main()
{
   f1();
    return 0;
}

a.cpp
Code: [Select]
#include "a.h"
void f2(){
    f1();
}

a.h
Code: [Select]
inline void f1(){
    int a=7;
    a=a+1;
    a=5;
};
Note, I can't set breakpoint in a.h in function f1().

When start debugging, I will receive this error from debugger(debug)
Quote
> break "C:/test/test_for_xiaowei/a.h:3"
Breakpoint 2 at 0x6: file C:/test/test_for_xiaowei/a.h, line 3. (2 locations)
>>>>>>cb_gdb:
> break "C:/test/test_for_xiaowei/main.cpp:11"
Breakpoint 3 at 0x401343: file C:\test\test_for_xiaowei\main.cpp, line 11.
>>>>>>cb_gdb:
> run
Warning:
Cannot insert breakpoint 2.
Error accessing memory address 0x6: Input/output error.
gdb: win32_init_thread_list

Any comments?
Thanks.

By the way ,I have tried many mingw package. Only TDM-MinGW can set breakpoints in a header file in CB :D

@John
Since the offical MinGW package abandon the SJLJ and use Dwarf-2 Unwinding by default.
Can TDM GCC do like this?

Thanks. :D


If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: GCC 4.4.0-tdm-1 for MinGW (with installer)
« Reply #33 on: June 25, 2009, 04:42:16 am »
I have fond this gdb return a bad address
Quote
> break "C:/test/test_for_xiaowei/a.h:3"
Breakpoint 2 at 0x6: file C:/test/test_for_xiaowei/a.h, line 3. (2 locations)

Why the address is 0x6??
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1442
    • CenizaSOFT
Re: GCC 4.4.0-tdm-1 for MinGW (with installer)
« Reply #34 on: June 25, 2009, 07:35:02 am »
I wouldn't be surprised you cannot set a breakpoint in an inline function, unless you tell the compiler not to inline it. Think about it. How can you break in a function that is no longer a function? I mean, once it is inlined, its code becomes part of the calling function.

I have no idea why it considers address 0x6, though.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: GCC 4.4.0-tdm-1 for MinGW (with installer)
« Reply #35 on: June 25, 2009, 07:51:54 am »
Thanks!

I have Googled a lot. But too confusing

1.Someone said when "-g" is enabled, a inline function will treated as a normal function.

2,I use "nm" tool to exam the symbol table in the exe file, there is a 0x4XXXXX address of an inline function :D


Edit
Here is another test:

If the inline function be referenced in two CPP file, like (main.cpp and a.cpp), then, this will reproduce the bug.

But if the inline function was only called in single cpp file, ( for example, only main.cpp call this inline function), then, I can successfully set breakpoint in the header :D
« Last Edit: June 25, 2009, 03:21:37 pm by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1442
    • CenizaSOFT
Re: GCC 4.4.0-tdm-1 for MinGW (with installer)
« Reply #36 on: June 25, 2009, 08:03:46 am »
A personal God (actually a guy who works for nvidia (I guess he still works there)) once told me a way to guarantee the compiler generates the function code for that case (inline) is to query the address of the function (and use it, I think... (it was a long time ago)). However, since the code is still... inlined... everywhere else it is called, setting a breakpoint there is not likely to work, unless you call it through a function pointer (I haven't tried it myself, though).

Why don't you try with "-fno-inline"?

<edit>
Every "translation unit" (roughly each cpp file with all the included headers) that uses an inline function should get a copy of it in case it is not inlined. It would be something similar to static functions.
</edit>
« Last Edit: June 25, 2009, 08:06:36 am by Ceniza »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: GCC 4.4.0-tdm-1 for MinGW (with installer)
« Reply #37 on: June 25, 2009, 08:13:11 am »
Why don't you try with "-fno-inline"?

Thanks for your help. I tested it, but this options has no effect :(.

Edit
function f1() has address

Quote
> p f1
$1 = {void (void)} 0x41894c <f1()>

So, the 0xd value is quite strange :shock:

Edit2
nm -s
result:
Quote
00418818 t .text
0040d7a8 t .text
004141b8 t .text
0041894c t .text$_Z2f1v
00418968 t .text$_ZN9__gnu_cxx13__scoped_lockD1Ev
00418a1c t .text$_ZN9__gnu_cxx13stdio_filebufIcSt11char_traitsIcEE2fdEv
00418a2c t .text$_ZN9__gnu_cxx13stdio_filebufIcSt11char_traitsIcEE4fileEv
« Last Edit: June 25, 2009, 08:54:11 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: GCC 4.4.0-tdm-1 for MinGW (with installer)
« Reply #38 on: June 25, 2009, 03:08:57 pm »
__attribute__ ((used)) is the canonical way of forcing gcc to emit a function body whether all calls are inlined or not. However, this is mostly useful for libraries or for cases where the compiler cannot possibly know that you call a function (out of inline assembly, for example). It's of little use for your debugging problem, as the function is never called, like in Ceniza's proposal.

Try __attribute__ ((noinline)), which prevents the compiler from inlining a particular function. This, however, only disables inlining, you may still face problems due to CSE and other optimisations which dead-strip function calls that have no effect.
If you want to prevent those too, use said attribute and add asm(""); in the function body. Due to the asm statement, the compiler cannot prove that no side effects take place, so it can't eleminate the function call.

EDIT:
Would have been good if I had looked at your code snippet too before answering. Class member declar-finitions as in your example are problematic. Why? Because the standard says (7.1.2.3) that these are inline, so it may be that the compiler still inlines those even if you tell it not to, as it's required by the language. Not sure what it does exactly, have to try.
« Last Edit: June 25, 2009, 03:21:34 pm by thomas »
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: GCC 4.4.0-tdm-1 for MinGW (with installer)
« Reply #39 on: June 25, 2009, 04:00:16 pm »
__attribute__ ((used)) is the canonical way of forcing gcc to emit a function body whether all calls are inlined or not. However, this is mostly useful for libraries or for cases where the compiler cannot possibly know that you call a function (out of inline assembly, for example). It's of little use for your debugging problem, as the function is never called, like in Ceniza's proposal.

Try __attribute__ ((noinline)), which prevents the compiler from inlining a particular function. This, however, only disables inlining, you may still face problems due to CSE and other optimisations which dead-strip function calls that have no effect.
If you want to prevent those too, use said attribute and add asm(""); in the function body. Due to the asm statement, the compiler cannot prove that no side effects take place, so it can't eleminate the function call.

EDIT:
Would have been good if I had looked at your code snippet too before answering. Class member declar-finitions as in your example are problematic. Why? Because the standard says (7.1.2.3) that these are inline, so it may be that the compiler still inlines those even if you tell it not to, as it's required by the language. Not sure what it does exactly, have to try.

Thank you for your help. I have tried these code below, but still has the same debug problem :(

a.h
Code: [Select]

__attribute__ ((noinline)) inline void f1(){
    int a=7;
    a=a+1;
    a=5;
    asm("");
};


By the way, I have tried another "Class member declar-finitions" examples.

main.cpp
Code: [Select]
#include <iostream>

using namespace std;

#include "a.h"

int main()
{
   TestClass a;
   a.func_inline();
    return 0;
}


a.cpp
Code: [Select]
#include "a.h"
void f2(){
    TestClass b;
    b.func_inline();
}


a.h
Code: [Select]
class TestClass{

public:
    void func_inline(){
        int a;
        a = 0;
        a++;
    }
};


And still I can't set breakpoint in "func_inline" function body. see below:
Code: [Select]
> break "C:/test/inline_2/main.cpp:12"
Breakpoint 2 at 0x401346: file C:\test\inline_2\main.cpp, line 12.
>>>>>>cb_gdb:
> break "C:/test/inline_2/a.h:7"
Breakpoint 3 at 0x6: file C:/test/inline_2/a.h, line 7. (2 locations)
>>>>>>cb_gdb:
> break "C:/test/inline_2/main.cpp:19"
No line 19 in file "C:\test\inline_2\main.cpp".
>>>>>>cb_gdb:
> run
Warning:
Cannot insert breakpoint 3.
Error accessing memory address 0x6: Input/output error.

Seems I can't find any way to solve this. :(


By the way , If I totally comment the code in
Code: [Select]
void f2(){
    //TestClass b;
    //b.func_inline();
}

then, breakpoint can  be set successfully in header file. This is the same as my previous example, if an inline function be called only once, we can set breakpoints in function body. :D

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: GCC 4.4.0-tdm-1 for MinGW (with installer)
« Reply #40 on: June 25, 2009, 04:52:13 pm »
Hi.
I searched on Google, but finally return to CB forum again. I find one solution that in this post by Jens.

http://forums.codeblocks.org/index.php/topic,9295.msg66259.html#msg66259

Code: [Select]
Using "-gstabs" in "Compiler settings -> Other options" instead works for me.
This can solve my problem!  :shock:

Edit
I can set breakpoints in a header file, but the program will hit that breakpoint with no line information output :(. this method still can't work.

Quote
Breakpoint 3, 0x00418952 in f1 ()
>>>>>>cb_gdb:
> cont
Breakpoint 4, 0x0041895c in f1 ()
>>>>>>cb_gdb:
> cont
Breakpoint 2, main () at C:/test/inline_test/main.cpp:12

Edit2
If I use both -gstabs -gstabs+ , then the problem can totally be solved :D
« Last Edit: June 25, 2009, 05:22:31 pm by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline yipinx

  • Single posting newcomer
  • *
  • Posts: 6
Re: GCC 4.4.0-tdm-1 for MinGW (with installer)
« Reply #41 on: July 02, 2009, 09:47:46 pm »
Hi guys,

does this release support elf32 object, sharedlib and exec files? the last distro didn't... not sure why though... i was forced do use this objdump tool, but that wasn't really compatible either....

why did the mingw guys turned this feature off in the first place.... i know plenty of projects that incorporate there own elf32 object loader into their programs.

cheers,
yipinx

btw.... since you took over the job to make a great install of the mingw distro *THANK YOU*... would you be so kind to repeat that with the latest nightlybuild of codeblocks, since these fellows don't like to make installers either.  :? (or a updatebutton to latest nightlybuild button in codeblocks)

Offline TDragon

  • Lives here!
  • ****
  • Posts: 936
    • Twilight Dragon Media
Re: GCC 4.4.0-tdm-1 for MinGW (with installer)
« Reply #42 on: July 04, 2009, 06:04:31 pm »
Why should a compiler that targets desktop Windows support ELF in the first place?

And it's not that difficult to download and unpack a Code::Blocks nightly by hand.
http://tdm-gcc.tdragon.net/ - TDM-GCC compiler suite for Windows (GCC 5.1.0 2015-06-28, 32/64-bit, no extra DLLs)

Offline nenin

  • Multiple posting newcomer
  • *
  • Posts: 95
Re: GCC 4.4.0-tdm-1 for MinGW (with installer)
« Reply #43 on: July 14, 2009, 06:05:14 pm »
Hello!
I got odd message with GCC 4.4.0-tdm-1-dw2 after "Compile current file" in C::B
Code: [Select]
Compiling: op\op.cpp
Linking console executable: op\op.exe
C:\mingw\lib/libmingw32.a(main.o):main.c:(.text+0x104): undefined reference to `[email protected]'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 0 warnings
op\op.exe should not be linked at all...  :shock:

Offline TDragon

  • Lives here!
  • ****
  • Posts: 936
    • Twilight Dragon Media
Re: GCC 4.4.0-tdm-1 for MinGW (with installer)
« Reply #44 on: July 15, 2009, 01:32:23 am »
The line "Linking console executable" shows that the link process is being executed by C::B, so this certainly is no fault of TDM-GCC. Since I never use the "Compile current file" command, I'm not sure whether this behavior is expected of Code::Blocks or not.
http://tdm-gcc.tdragon.net/ - TDM-GCC compiler suite for Windows (GCC 5.1.0 2015-06-28, 32/64-bit, no extra DLLs)