This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch] Document __secure_getenv


On 7/12/2012 1:55 PM, Rich Felker wrote:
> On Thu, Jul 12, 2012 at 10:38:24AM -0700, Roland McGrath wrote:
>> The public symbol needs a proper public declaration, not one in include/.
>> We should also deprecate public use of __secure_getenv and make it
>> unlinkable-to, as Carlos mentioned.
> 
> How can a symbol be made unlinkable, i.e. usable by already-linked
> apps, but failing if ld tries to link a new app to it? This is
> slightly off-topic but it's a problem I've been trying to solve for a
> while and it looks like you might know the answer.

Version it but provide no default version. The lack
of a default terminates the progression of compatible 
functions that the static linker can use to resolve 
the symbol reference.

I'm not sure this is 100% kosher, but it's what
I would cook up if somebody put me to the task.

Rich, Would you mind cleaning up this example and 
sticking it somewhere in the wiki? :-)

cat >> foo.c <<EOF
/* Function in a shared library.  */
int foo (void)
{
  return 42;
}
EOF
cat >> main.c <<EOF
/* Application.  */
#include <stdlib.h>
#include <stdio.h>
extern int foo (void);
int main (void)
{
  printf ("foo returned %d.\n", foo());
  return 0;
}
EOF
cat >> foo2.c <<EOF
/* Function in a shared library. No default version. */
__asm__(".symver foo, foo@FOO_1.0");
int foo (void)
{
  return 42;
}
EOF
cat >> foo.map <<EOF
FOO_1.0 {
};
EOF
cat >> run.sh <<EOF
echo "Build old library without symbol versioning."
gcc -Wall -pedantic -fPIC -shared -o libfoo.so foo.c
echo "Build old application..."
gcc -Wall -pedantic -L. -lfoo -o main main.c
echo "Run old application."
./main
echo "Build new library with no default symbol version for foo."
gcc -Wall -pedantic -fPIC -shared -o libfoo.so -Wl,--version-script,foo.map foo2.c
echo "Run old application successfully..."
./main
echo "Fail to rebuild new application because symbol foo has no default version."
gcc -Wall -pedantic -L. -lfoo -o main main.c
echo "Fail to run anything because main failed to build."
./main
EOF
/bin/sh ./run.sh

Result is:
~~~
Build old library without symbol versioning.
Build old application.
Run old application...
foo returned 42.
Build new library with no default symbol version for foo.
Run old application successfully...
foo returned 42.
Fail to rebuild new application because symbol foo has no default version.
/tmp/ccQPSiau.o: In function `main':
main.c:(.text+0x5): undefined reference to `foo'
collect2: ld returned 1 exit status
Fail to run anything because main failed to build.
./run.sh: line 14: ./main: No such file or directory
~~~


Cheers,
Carlos.
-- 
Carlos O'Donell
Mentor Graphics / CodeSourcery
carlos_odonell@mentor.com
carlos@codesourcery.com
+1 (613) 963 1026


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]