problem about version-script

罗翼 luoyi.ly@gmail.com
Tue Jan 23 03:36:00 GMT 2007


Hi, first my ld version:

luoyi@wslab$ ld --version
GNU ld version 2.15.92.0.2 20040927
Copyright 2002 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License.  This program has absolutely no warranty.

and I've found if I want to use version-script to export both C&C++
symbols from the so, I must put the C++'s name *before* the C name.
does this expected or have been documented somewhere ?

for example:
/*********************************** header file
**************************************/
luoyi@wslab$ cat foo.h
#if _MSC_VER > 1000 || __GNUC__ > 2
#pragma once
#endif

#ifndef _FOO_H
#define _FOO_H

#ifdef __cplusplus
extern "C" {
#endif

struct foo_module_t{
        int key;
        int value;
};

extern struct foo_module_t foo_module;

#ifdef __cplusplus
}
#endif

extern int foo_func(void);

#endif

/*********************************** cpp file
**************************************/
luoyi@wslab$ cat foo.cpp
#include "foo.h"

struct foo_module_t foo_module = {
        1, 100
};

int foo_func(void)
{
        return 100;
}

/*********************************** version-script 1
**************************************/
luoyi@wslab$ cat foo1.vermap
{
  global:
        foo_module;
        extern "C++" {
                foo_func*;
        };

  local:
    *;
};
/*********************************** version-script 2
**************************************/
luoyi@wslab$ cat foo2.vermap
{
  global:
        extern "C++" {
                foo_func*;
        };
        foo_module;
  local:
    *;
};
/*********************************** Makefile
**************************************/
luoyi@wslab$ cat Makefile
.PHONY : all list
all : foo1.so foo2.so list

LDFLAGS = -O2 -shared -fPIC -DPIC -o $@ -Wl,--no-undefined -Wl,-s
-Wl,-soname=$@ -Wl,--as-needed

foo1.so : foo.cpp foo.h
        g++ $(LDFLAGS) -Wl,--version-script,foo1.vermap $< -Wl,-lc

foo2.so : foo.cpp foo.h
        g++ $(LDFLAGS) -Wl,--version-script,foo2.vermap $< -Wl,-lc

list :
        strings foo1.so | egrep 'func|module'
        strings foo2.so | egrep 'func|module'
        ls -lh *.so

/***********************************
output**************************************/
luoyi@wslab$ make -B
g++ -O2 -shared -fPIC -DPIC -o foo1.so -Wl,--no-undefined -Wl,-s
-Wl,-soname=foo1.so -Wl,--as-needed -Wl,--version-script,foo1.vermap
foo.cpp -Wl,-lc
g++ -O2 -shared -fPIC -DPIC -o foo2.so -Wl,--no-undefined -Wl,-s
-Wl,-soname=foo2.so -Wl,--as-needed -Wl,--version-script,foo2.vermap
foo.cpp -Wl,-lc
strings foo1.so | egrep 'func|module'
_Z8foo_funcv
strings foo2.so | egrep 'func|module'
foo_module
_Z8foo_funcv
ls -lh *.so
-rwxr-xr-x 1 luoyi users 2.6K 2007-01-23 11:32 foo1.so
-rwxr-xr-x 1 luoyi users 2.6K 2007-01-23 11:32 foo2.so

as you can see, there is no symbol named "foo_module" in foo1.so, but
it exist in foo2.so.



More information about the Binutils mailing list