Bug 24721

Summary: libgcc_r problem - library precedence with libstdc++
Product: Base System Reporter: dor <dor>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

Description dor 2001-01-29 17:00:01 UTC
The attached program creates cores using normal compilation & linking .
The compilation command is:
g++ -g3 try.cpp -pthread -o try

// file try.cpp

#include <sys/types.h>
#include <strstream.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <pthread.h>


class a {
public:
    a() {
        a1 = 0;
    }
    ~a() {
        int i;
        int a2[100];
        for (i = 0; i < 100 ; i++) {
            a2[i] = i;
        }
        a1 = a2[0];
    }
    int a1;
};

class b : a {
    int b1;
};

void func(void* arg) {
    int i;
    for (i=0;i<100000;i++) {
        b obj;
        b* p;
        p = &obj;
    }
    printf("thread done\n");
}

void thread_creation(int i) {
    int rtn = 0;

    pthread_t id;
    if (rtn = pthread_create(&id, 0, (void * (*)(void *))func,NULL)) {
        printf(" could create thread\n");
    }
}


int main() {

    for (int i=0; i< 100; i++) {
        thread_creation(i);
    }


    sleep(10);

    return 0;
}

Fix: 

Link libgcc_r implictly with the executable- use command

g++ -g3 try.cpp -pthread -lgcc_r -o try


Note that if you put libstdc++ before gcc_r the problem remains
How-To-Repeat: Just run the program several times.
Comment 1 ashp freebsd_committer freebsd_triage 2002-01-16 22:58:13 UTC
State Changed
From-To: open->closed

Following the instructions in the PR, I had no problems running 
the program in question.  It gives 'thread done' numerous times.