Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Segfault when execution for tls test #19

Closed
kito-cheng opened this issue Nov 3, 2016 · 4 comments
Closed

Segfault when execution for tls test #19

kito-cheng opened this issue Nov 3, 2016 · 4 comments
Assignees

Comments

@kito-cheng
Copy link
Collaborator

Arch: RV32I, RV32G
Option: -pthread -O1

How to reproduce:

$ riscv32-unknown-linux-gnu-gcc tls-test.c  -pthread -O1
$ qemu-riscv32 -L `riscv32-unknown-linux-gnu-gcc --print-sysroot` a.out
Segmentation fault (core dumped)

Code for tls-test.c:

#include <pthread.h>
extern int printf (char *,...);
__thread int a = 5; 
int *volatile a_in_other_thread = (int *) 12345;

static void *
thread_func (void *arg)
{
  a_in_other_thread = &a;
  a+=5;
  *((int *) arg) = a;
  return (void *)0;
}

int
main ()
{
  pthread_t thread;
  void *thread_retval;

  int *volatile a_in_main_thread;
  int *volatile again ;
  int thr_a;

  a_in_main_thread = &a;

  if (pthread_create (&thread, (pthread_attr_t *)0, thread_func, &thr_a))
    return 0;

  if (pthread_join (thread, &thread_retval))
    return 0;

  again = &a;
  if (again != a_in_main_thread)
    {
      printf ("FAIL: main thread addy changed from 0x%0x to 0x%0x\n", 
                a_in_other_thread, again);
      return 1;
    }

  if (a != 5 || thr_a != 10 || (a_in_other_thread == a_in_main_thread))
    {
      printf ("FAIL: a= %d, thr_a = %d Addr = 0x%0x\n", 
                a, thr_a, a_in_other_thread);
      return 1;
    }
  return 0;
}

@aswaterman aswaterman self-assigned this Nov 3, 2016
@aswaterman
Copy link
Contributor

Looks like qemu is segfaulting, not the TLS test.

@sagark can you look into this? I put the stuff you need to replicate the failure in /scratch/waterman/toolchain32/ on a5: Just hop in that directory and run

qemu-riscv32 -L /scratch/waterman/toolchain32/sysroot ./a.out

@kito-cheng
Copy link
Collaborator Author

I guess those test case is same as this case:

g++.dg/tls/thread_local3.C
g++.dg/tls/thread_local3g.C
g++.dg/tls/thread_local4.C
g++.dg/tls/thread_local4g.C
g++.dg/tls/thread_local5.C
g++.dg/tls/thread_local5g.C

@aswaterman
Copy link
Contributor

It looks like the -pthread option alone is enough to trigger this (the code in main() doesn't matter).

@aswaterman
Copy link
Contributor

I think this is a duplicate of riscv-collab/riscv-gnu-toolchain#192 but I am working on it.

palmer-dabbelt pushed a commit to riscvarchive/riscv-binutils-gdb that referenced this issue Nov 20, 2016
palmer-dabbelt pushed a commit to riscvarchive/riscv-binutils-gdb that referenced this issue Dec 14, 2016
fanghuaqi pushed a commit to riscv-mcu/riscv-gcc that referenced this issue Feb 10, 2022
…mental-v@fix-z-letter

fix %z letter in output template
yulong18 pushed a commit to yulong18/riscv-gcc that referenced this issue Apr 12, 2022
name_lookup::search_unqualified uses a statically allocated vector
in order to avoid repeated reallocation, under the assumption that
the function can't be called recursively.  With modules however,
this assumption turns out to be false, and search_unqualified can
be called recursively as demonstrated by the testcase in comment riscvarchive#19
of PR99479[1] where the recursive call causes the vector to get
reallocated which invalidates the reference to queue[ix] held by the
parent call.

This patch makes search_unqualified instead use an auto_vec with 16
elements of internal storage.  In turn we can simplify the API of some
member functions to take the vector by reference and return void.

[1]: https://gcc.gnu.org/PR99479#c19

	PR c++/99479

gcc/cp/ChangeLog:

	* name-lookup.cc (name_lookup::using_queue): Change to an
	auto_vec (with 16 elements of internal storage).
	(name_lookup::queue_namespace): Change return type to void,
	take queue parameter by reference and adjust function body
	accordingly.
	(name_lookup::do_queue_usings): Inline into ...
	(name_lookup::queue_usings): ... here.  As in queue_namespace.
	(name_lookup::search_unqualified): Don't make queue static,
	remove length variable, and adjust function body accordingly.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants