| Summary: | FBSD4 gcc __attribute__(constructor) not work | ||
|---|---|---|---|
| Product: | Base System | Reporter: | xyf <xyf> |
| Component: | gnu | Assignee: | Gerald Pfeifer <gerald> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | ||
| Priority: | Normal | ||
| Version: | Unspecified | ||
| Hardware: | Any | ||
| OS: | Any | ||
Responsible Changed From-To: freebsd-bugs->obrien David's baby. Responsible Changed From-To: obrien->freebsd-bugs State Changed From-To: open->feedback Would you mind reporting this problem to the GCC folks following <http://gcc.gnu.org/bugs.html>? Please let us know when you have done so, or in case it is not feasible for you. (I verified that this is not a FreeBSD-specific issue.) Responsible Changed From-To: freebsd-bugs->gerald I'm tracking this now. Would you mind reporting this problem to the GCC folks following <http://gcc.gnu.org/bugs.html>? Please let us know when you have done so, or in case it is not feasible for you. (I verified that this is not a FreeBSD-specific issue.) State Changed From-To: feedback->closed I have forwarded this bug report to the GCC folks, and it got fixed on the main GCC development branch within less than two days, which means it will be imported to FreeBSD in the future. As a workaround for your problem you could use a current snapshot of GCC, but given the fact that this is not FreeBSD-specific, this bug does not constitute a portability problem, so I don't think it's worth diverging from official GCC sources by importing this in the system compiler -- though I'll inform our compiler maintainers so they can decide. |
the GNU C++ compiler in FreeBSD doesn't correctly handles "__attribute__((constructor))", but it works if I use C compiler instead. Fix: I think some utilities in FreeBSD are inconsistent, it has different version of utilities for C and C++, need update these utilities. How-To-Repeat: this is the demo program: #include <stdio.h> int g_int = 0; void init() __attribute__((constructor)); void init() { g_int = 1; } int main(int argc, char** argv) { if (g_int == 1) printf("__attribute__((constructor)) work!\n"); else printf("__attribute__((constructor)) not work!\n"); return 0; } if the source program name is test.cpp and use command "c++ test.cpp" to compile it, "__attribute__((constructor))" hasn't effect, but if the source program name is test.c, then use command "cc test.c" the compile it, it works!