diff mbox

gdb/testsuite/gdb.threads: Make sure TLS tests link against pthreads.

Message ID 51B22910.7010208@linaro.org
State Superseded
Headers show

Commit Message

Will Newton June 7, 2013, 6:40 p.m. UTC
On Ubuntu the compiler passes --as-needed to the linker which means
no DT_NEEDED entry is added for libpthread when building the TLS
tests. This causes the test to fail as a libpthread is required to
look up TLS variables. Add some calls to pthread functions to make
sure libpthread is linked.

gdb/testsuite/ChangeLog:

2013-06-07  Will Newton  <will.newton@linaro.org>

	* gdb.threads/tls-nodebug.c: Call pthread_self to ensure
	the test is linked against pthreads.
	* gdb.threads/tls-var-main.c: Likewise.
	* gdb.threads/tls-shared.c: Call pthread_testcancel to
	ensure the test is linked against pthreads.
---
 gdb/testsuite/gdb.threads/tls-nodebug.c  | 2 +-
 gdb/testsuite/gdb.threads/tls-shared.c   | 4 ++++
 gdb/testsuite/gdb.threads/tls-var-main.c | 4 +++-
 3 files changed, 8 insertions(+), 2 deletions(-)

Comments

Andrew Pinski June 11, 2013, 11:02 p.m. UTC | #1
On Fri, Jun 7, 2013 at 11:40 AM, Will Newton <will.newton@linaro.org> wrote:
>
> On Ubuntu the compiler passes --as-needed to the linker which means
> no DT_NEEDED entry is added for libpthread when building the TLS
> tests. This causes the test to fail as a libpthread is required to
> look up TLS variables. Add some calls to pthread functions to make
> sure libpthread is linked.


I think this should be an debian/Ubuntu local only patch as the
default for FSF GCC/binutils is not to pass --as-needed.

Thanks,
Andrew

>
> gdb/testsuite/ChangeLog:
>
> 2013-06-07  Will Newton  <will.newton@linaro.org>
>
>         * gdb.threads/tls-nodebug.c: Call pthread_self to ensure
>         the test is linked against pthreads.
>         * gdb.threads/tls-var-main.c: Likewise.
>         * gdb.threads/tls-shared.c: Call pthread_testcancel to
>         ensure the test is linked against pthreads.
> ---
>  gdb/testsuite/gdb.threads/tls-nodebug.c  | 2 +-
>  gdb/testsuite/gdb.threads/tls-shared.c   | 4 ++++
>  gdb/testsuite/gdb.threads/tls-var-main.c | 4 +++-
>  3 files changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/gdb/testsuite/gdb.threads/tls-nodebug.c b/gdb/testsuite/gdb.threads/tls-nodebug.c
> index 73d96f0..10aa8c8 100644
> --- a/gdb/testsuite/gdb.threads/tls-nodebug.c
> +++ b/gdb/testsuite/gdb.threads/tls-nodebug.c
> @@ -6,5 +6,5 @@ __thread int thread_local = 42;
>
>  int main(void)
>  {
> -  return 0;
> +  return pthread_self();
>  }
> diff --git a/gdb/testsuite/gdb.threads/tls-shared.c b/gdb/testsuite/gdb.threads/tls-shared.c
> index d4f8e5c..1ef7949 100644
> --- a/gdb/testsuite/gdb.threads/tls-shared.c
> +++ b/gdb/testsuite/gdb.threads/tls-shared.c
> @@ -1,6 +1,10 @@
> +
> +#include <pthread.h>
> +
>  __thread int i_tls = 1;
>  int foo ()
>  {
> +  pthread_testcancel();
>    return i_tls;
>  }
>
> diff --git a/gdb/testsuite/gdb.threads/tls-var-main.c b/gdb/testsuite/gdb.threads/tls-var-main.c
> index 34a2522..4728ea3 100644
> --- a/gdb/testsuite/gdb.threads/tls-var-main.c
> +++ b/gdb/testsuite/gdb.threads/tls-var-main.c
> @@ -15,8 +15,10 @@
>     You should have received a copy of the GNU General Public License
>     along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
>
> +#include <pthread.h>
> +
>  int
>  main (void)
>  {
> -  return 0;
> +  return pthread_self();
>  }
> --
> 1.8.1.4
>
Will Newton June 12, 2013, 9:54 a.m. UTC | #2
On 12 June 2013 00:02, Andrew Pinski <pinskia@gmail.com> wrote:
> On Fri, Jun 7, 2013 at 11:40 AM, Will Newton <will.newton@linaro.org> wrote:
>>
>> On Ubuntu the compiler passes --as-needed to the linker which means
>> no DT_NEEDED entry is added for libpthread when building the TLS
>> tests. This causes the test to fail as a libpthread is required to
>> look up TLS variables. Add some calls to pthread functions to make
>> sure libpthread is linked.
>
>
> I think this should be an debian/Ubuntu local only patch as the
> default for FSF GCC/binutils is not to pass --as-needed.

I admit the change is a little, erm, weird, but my hope was to avoid
causing pain to people who build gdb on Ubuntu. This isn't just Ubunto
or Debian developers but Ubuntu or Debian users that happen to have
downloaded a gdb tarball from gnu.org. Similar test failures in
binutils have been worked around by adding -Wl,--no-as-needed which we
could also do here, but I was concerned that this may break non-gcc
compilers.

--
Will Newton
Toolchain Working Group, Linaro
Joel Brobecker June 12, 2013, 10:26 a.m. UTC | #3
> > I think this should be an debian/Ubuntu local only patch as the
> > default for FSF GCC/binutils is not to pass --as-needed.
> 
> I admit the change is a little, erm, weird, but my hope was to avoid
> causing pain to people who build gdb on Ubuntu. This isn't just Ubunto
> or Debian developers but Ubuntu or Debian users that happen to have
> downloaded a gdb tarball from gnu.org. Similar test failures in
> binutils have been worked around by adding -Wl,--no-as-needed which we
> could also do here, but I was concerned that this may break non-gcc
> compilers.

I tend to agree that it can be potentially useful, and since it does
not appear to be very disruptive, I find it acceptable in principle.
I just haven't had time to look into it in more details...
Tom Tromey July 17, 2013, 6:15 p.m. UTC | #4
Andrew> I think this should be an debian/Ubuntu local only patch as the
Andrew> default for FSF GCC/binutils is not to pass --as-needed.

If that is the only reason, then I think it is still ok in principle to
use the patch.  It won't hurt the FSF default case.

Tom
Tom Tromey July 17, 2013, 6:18 p.m. UTC | #5
>>>>> "Will" == Will Newton <will.newton@linaro.org> writes:

Will>  int main(void)
Will>  {
Will> -  return 0;
Will> +  return pthread_self();

I think it is possible according to POSIX for pthread_t to be a pointer
type.  It seems like it would be safer to just use a call to
pthread_testcancel in all these tests.

Tom
Mark Kettenis July 17, 2013, 7:04 p.m. UTC | #6
> From: Tom Tromey <tromey@redhat.com>
> Date: Wed, 17 Jul 2013 12:18:25 -0600
> 
> >>>>> "Will" == Will Newton <will.newton@linaro.org> writes:
> 
> Will>  int main(void)
> Will>  {
> Will> -  return 0;
> Will> +  return pthread_self();
> 
> I think it is possible according to POSIX for pthread_t to be a pointer
> type.

It is on OpenBSD.
Will Newton July 17, 2013, 8:17 p.m. UTC | #7
On 17 July 2013 19:18, Tom Tromey <tromey@redhat.com> wrote:
>
> >>>>> "Will" == Will Newton <will.newton@linaro.org> writes:
>
> Will>  int main(void)
> Will>  {
> Will> -  return 0;
> Will> +  return pthread_self();
>
> I think it is possible according to POSIX for pthread_t to be a pointer
> type.  It seems like it would be safer to just use a call to
> pthread_testcancel in all these tests.

Yes, that's true. I'll respin the patch, thanks for the review!


--
Will Newton
Toolchain Working Group, Linaro
diff mbox

Patch

diff --git a/gdb/testsuite/gdb.threads/tls-nodebug.c b/gdb/testsuite/gdb.threads/tls-nodebug.c
index 73d96f0..10aa8c8 100644
--- a/gdb/testsuite/gdb.threads/tls-nodebug.c
+++ b/gdb/testsuite/gdb.threads/tls-nodebug.c
@@ -6,5 +6,5 @@  __thread int thread_local = 42;

 int main(void)
 {
-  return 0;
+  return pthread_self();
 }
diff --git a/gdb/testsuite/gdb.threads/tls-shared.c b/gdb/testsuite/gdb.threads/tls-shared.c
index d4f8e5c..1ef7949 100644
--- a/gdb/testsuite/gdb.threads/tls-shared.c
+++ b/gdb/testsuite/gdb.threads/tls-shared.c
@@ -1,6 +1,10 @@ 
+
+#include <pthread.h>
+
 __thread int i_tls = 1;
 int foo ()
 {
+  pthread_testcancel();
   return i_tls;
 }

diff --git a/gdb/testsuite/gdb.threads/tls-var-main.c b/gdb/testsuite/gdb.threads/tls-var-main.c
index 34a2522..4728ea3 100644
--- a/gdb/testsuite/gdb.threads/tls-var-main.c
+++ b/gdb/testsuite/gdb.threads/tls-var-main.c
@@ -15,8 +15,10 @@ 
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

+#include <pthread.h>
+
 int
 main (void)
 {
-  return 0;
+  return pthread_self();
 }