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: Define __start/__stop symbols when there is only a dynamic def


Hi,

On Mon, 29 Jan 2018, H.J. Lu wrote:

> I asked specially if the testcase is correct:
> 
> https://sourceware.org/ml/binutils/2018-01/msg00421.html

Gah!  Sorry, I didn't recognize that you also adjusted the link line to 
remove the reference to liborphan.  Okay, with that testcase and that link 
command and no dynamic definitions of __start___verbose, then no, that's 
not a testcase that has to work (it also didn't before 2.29).  It's 
specifically the case that:
  a) a dynamic library X exports such symbol for section S
  b) another library or app Y linked against X also has a section S
  c) Y doesn't contain any regular references to symbol __start_S
then it still needs to be the case that Y exports its own variant of 
__start_S as well.  If Y doesn't contain ref_regular refs and isn't linked 
against any such X lib, then nothing needs to happen.

(That's how far the old behaviour was and what is relied upon by the 
pacemaker logging mechanism.  We of course can declare that invalid, 
though it'd change IMHO useful behaviour)

I now realize that the references to older mails from me might have 
confused things, so to be absolutely certain we're talking about the right 
thing.  The following it is, a two-file, two-DSO testcase:

% cat lib.c
extern int __start___verbose[];
extern int __stop___verbose[];
extern int foo2(void);
int foo (void)
{
  static int my_var __attribute__((section("__verbose"))) = 5;
  if (__start___verbose == __stop___verbose  // ref_regular
      || __start___verbose[0] != 5)
    return -1;
  else
    return 0;
}
% cat app.c
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>

extern int __start___verbose[];
extern int __stop___verbose[];
int bar (void)
{
  static int my_var __attribute__((section("__verbose"))) = 6;
  int *ptr;
  ptr = (int*) dlsym(RTLD_DEFAULT, "__start___verbose");
  if (!ptr || *ptr != 6)
    return -1;
  return 0;
}

int main()
{
  if (bar () != 0)
    {
      printf("main: wrong __start___verbose\n");
      exit(2);
    }
  return 0;
}
% cc -g   -c -o app.o app.c
% cc -g -fPIC   -c -o lib.o lib.c
% cc -B./ -shared -o liborphan.so lib.o -Wl,-R,.
% cc -B./ -o app app.o liborphan.so -ldl -Wl,-R,.
% ./app
<nothing>

If we want to go back to pre-2.29 behaviour the above program must work.  
If you don't link liborphan.so to app then app doesn't need to work.

> https://sourceware.org/ml/binutils/2018-01/msg00416.html
> 
> may make .startof symbols dynamic.

Yes, that's why I said:

 "Or something along the lines (perhaps doing this only in the 
  C-representable case, and then only if not made hidden or so)."


Ciao,
Michael.


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