This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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: Behavior change, PLT entries for R_X86_64_PLT32 relocations with undefined symbol


Hi,

On Tue, 19 Mar 2019, H.J. Lu wrote:

> > library.c
> >
> > int answer() {
> >      return 42;
> > }
> >
> > ----
> >
> > executable.c
> >
> > #include <dlfcn.h>
> >
> > int answer();
> >
> > int main()
> > {
> >      void *lib = dlopen("./library.so", RTLD_LAZY | RTLD_GLOBAL);
> >      if (!lib) {
> >          printf("dlopen failed");
> >      }
> >      printf("The answer is %d\n", answer());
> >      return 0;
> > }
> 
> Since answer is undefined, its behavior is undefined.

You're making this sound more clear-cut than it is, and I disagree with 
it.  Clearly, at runtime, the symbol 'answer' is resolvable just fine, the 
loaded library contains a global definition.  So with lazy resolution it'd 
work.  Note that the user explicitely requested the acceptance of 
unresolved symbols with --unresolved-symbols=ignore-all (and did not 
request non-lazy loading), so I would fully expect that unresolved global 
symbols will be made dynamic symbols even for executables.

Martin: there is a work around for you for now: declare the functions in 
question as weak in the objects making use of them:

------
int answer() __attribute__((weak));
...
     printf("The answer is %d\n", answer());
...
------

You might or might not have to use the '-z dynamic-undefined-weak' link 
editor option for this to work.


Ciao,
Michael.


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