[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#489357: undefined reference to __open_2 on hurd/kfreebsd with -D_FORTIFY_SOURCE=2



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Package: g++-4.3
Version: 4.3.1-4
Severity: important

Good morning,

it seems as there's an older bug in (maybe) g++.
The package znc won't build on the following architectures:

	hurd-i386
	kfreebsd-i386
	kfreebsd-amd64

It FTBFS with the following error message:

> i486-gnu-g++ -Wl,--export-dynamic -o znc String.o Csocket.o main.o
znc.o User.o IRCSock.o Client.o DCCBounce.o DCCSock.o Chan.o Nick.o
Server.o Modules.o MD5.o Buffer.o Utils.o FileUtils.o HTTPSock.o
Template.o -ldl -lssl -lcrypto
> znc.o: In function `CLockFile::TryExLock(CString const&, bool)':
>
znc.cpp:(.text._ZN9CLockFile9TryExLockERK7CStringb[CLockFile::TryExLock(CString
const&, bool)]+0x6a): undefined reference to `__open_2'

How you can see at [1] it just happens with -D_FORTIFY_SOURCE=2 -
without fortify_source it's compiling, linking and working well.
So on FORTIFY_SOURCE=2 is optimizing something in a quite bad way? :)

This is at znc the evil line which causes the FTBFS:
m_fd = open(sFile.c_str(), bRw ? O_RDWR : O_RDONLY);

You can find it in Utils.h arround line 112.


The author of the software znc Uli Schlachter has written the
"testcase.cpp" where you could also test it (with some notes).

As the build logs on [1] say, this bug also exists in stable and lenny,
but I haven't got a hurd/kfreebsd stable/testing buildd.


[1]: http://buildd.debian-ports.org/status/package.php?p=znc

- --
/*
Mit freundlichem Gruß / With kind regards,
Patrick Matthäi

E-Mail: patrick.matthaei@web.de
*/

// Comment:
// Always if we think we are right,
// we were maybe wrong.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkhvOp8ACgkQ2XA5inpabMfnggCfSKSjPEHs6C5utZTC4SHRrzIe
OXoAoJPiIMa4lWzQOuGBCF/fAxgLOolR
=yrdE
-----END PGP SIGNATURE-----
/* Uli Schlachter (C) 2008 GPLv2 (who would fork a testcase anyway? :P) */
/* Compile this with -DFORTIFY_SOURCE=2 and at least -O1.
 * E.g. so:
 *   g++ -D_FORTIFY_SOURCE=2 -O2 -o test test.cpp
 * You will get a linker error about an undefined reference to __open_2
 * (and an undefined reference to i, ignore that one).
 *
 * __open_2() is defined in /usr/include/bits/fcntl2.h which is included by
 * fcntl.h only if _FORTIFY_SOURCE is turned on and which seems to only have an
 * effect with optimization enabled (-O1 or higher).
 *
 * I have no clue why we only get an undefined reference to __open_2() if
 * the __builtin_constant_p() in fcntl2.h / open() returns false (happens
 * here because the value of 'extern int i' is unknown).
 */

#include <fcntl.h>

extern int i;

int main()
{
	int fd = open("test", i ? O_RDWR : O_RDONLY);
	return 0;
}

Attachment: testcase.cpp.sig
Description: Binary data


Reply to: