Opened 10 years ago

Closed 10 years ago

#6322 closed bug (fixed)

[gcc] Static class field in shared object links to two addresses

Reported by: Adek336 Owned by: nobody
Priority: normal Milestone: R1
Component: - General Version: R1/alpha2
Keywords: Cc:
Blocked By: Blocking:
Platform: All


/* A.h */
#ifndef A_H
#define A_H

#include <iostream>

class A
        static int i = 0;
        std::cerr << (void*)&i << std::endl;

/* */
#include "A.h"

A x;

int main()
/* */
#include "A.h"

A y;
g++ -shared -o
LIBRARY_PATH=. ./a.out

results in


whereas the addresses should be equal.

hrev37527, gcc4+2 hybrid, VBox 3.1

Change History (3)

comment:1 by bonefish, 10 years ago

This problem already existed under BeOS R5 with gcc 2.9. I don't know whether there are any provisions in gcc 4 that allow to make this work without weak symbol support by the OS. I guess we really should implement it, anyway.

comment:2 by diver, 10 years ago

As weak symbol support was implemented is this still an issue?

comment:3 by bonefish, 10 years ago

Resolution: fixed
Status: newclosed

I don't recall whether I have tested the given code example, but at least with gcc 4 it should now work as expected. With gcc 2 it probably still doesn't, but that's due to the symbolic linking which we probably won't change.

Note: See TracTickets for help on using tickets.