Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 19 Nov 2017 15:52:43 +0000
From:      bugzilla-noreply@freebsd.org
To:        freebsd-bugs@FreeBSD.org
Subject:   [Bug 223752] clang __attribute__((constructor)) gets wrong input parameters
Message-ID:  <bug-223752-8-w7krcM0EyP@https.bugs.freebsd.org/bugzilla/>
In-Reply-To: <bug-223752-8@https.bugs.freebsd.org/bugzilla/>
References:  <bug-223752-8@https.bugs.freebsd.org/bugzilla/>

next in thread | previous in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D223752

dstaesse <dimitri.staessens@ugent.be> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dimitri.staessens@ugent.be

--- Comment #1 from dstaesse <dimitri.staessens@ugent.be> ---
Created attachment 188120
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D188120&action=
=3Dedit
main program code

Sorry, pushed submit too early.

I find that the argc and argv values that are passed to a shared library
constructor for a library that is compiled using clang fails. I get the same
result using FreeBSD 11.0-RELEASE, 11.1-RELEASE and 12-CURRENT

When compiling the attached code using

$clang -c -fPIC attrconst.c=20
$clang -shared -o libattrconst.so attrconst.o
$clang -L . main.c -lattrconst -o test

and executing (bash)=20
$LD_LIBRARY_PATH=3D. ./test

I get:
Initializing library.=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
Got 3 params.
argv[0] is (null).
Running the test.
Finalizing library.

Which is not what I was expecting.

Compiling the library using gcc, gives the correct result:

$gcc -c -fPIC attrconst.c=20
$gcc -shared -o libattrconst.so attrconst.o
$gcc -L . main.c -lattrconst -o test
$LD_LIBRARY_PATH=3D. ./test
Initializing library.=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20
Got 1 params.
argv[0] is ./test.
Running the test.
Finalizing library.

Could this be a bug in clang?

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-223752-8-w7krcM0EyP>