Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 07 Sep 2020 09:53:51 +0000
From:      bugzilla-noreply@freebsd.org
To:        bugs@FreeBSD.org
Subject:   [Bug 249162] Consider passing argc/argv/env to the shared object init function (DT_INIT) for compatibility with glibc
Message-ID:  <bug-249162-227@https.bugs.freebsd.org/bugzilla/>

next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D249162

            Bug ID: 249162
           Summary: Consider passing argc/argv/env to the shared object
                    init function (DT_INIT) for compatibility with glibc
           Product: Base System
           Version: Unspecified
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: iwtcex@gmail.com

% cat so_init.c=20
#include <stdio.h>

void so_init(int argc, char** argv, char** env) {
  for (int i =3D 0; i < argc; i++) {
    printf("arg[%d]: %s\n", i, argv[i]);
  }
}
% cc -std=3Dc99 -fPIC -shared -Wl,-init=3Dso_init so_init.c -o test.so
% env LD_PRELOAD=3D$PWD/test.so true 1 2 3
Bus error
% /compat/linux/bin/cc -std=3Dc99 -fPIC -shared -Wl,-init=3Dso_init so_init=
.c -o
test.so
% env LD_PRELOAD=3D$PWD/test.so /compat/linux/bin/true 1 2 3=20
arg[0]: /compat/linux/bin/true
arg[1]: 1
arg[2]: 2
arg[3]: 3

Some notes there:
1. relevant glibc code:
https://sourceware.org/git/?p=3Dglibc.git;a=3Dblob;f=3Delf/dl-init.c;h=3D3e=
72fa3013a6aaeda05fe61a0ae7af5d46640826;hb=3DHEAD#l58
;
2. rtld already does this for functions referenced in DT_INIT_ARRAY, so it's
enough to replace a call_initfini_pointer call with call_init_pointer.

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-249162-227>