Hello,

We could dig in details what happens in constructors,
but first I don't understand why you want to LD_PRELOAD some drivers.
The DPDK drivers are already loaded dynamically with dlopen() from EAL.


04/12/2023 10:45, jiangheng (G):
> Environment:
> [root@localhost jh]# cat /etc/centos-release
> CentOS Linux release 8.5.2111
> root@localhost jh]# uname -r
> 4.18.0-348.el8.x86_64
> [root@localhost jh]# rpm -qa gcc
> gcc-8.5.0-3.el8.x86_64
> [root@localhost jh]# rpm -qa dpdk
> dpdk-21.11-3.el8.x86_64
> 
> Reproduction Procedure:
> 1. We need create test.c and init.c
> 
> [root@localhost jh]# cat init.c
> #include <string.h>
> #include <stdio.h>
> #include <stdlib.h>
> 
> __attribute__ ((constructor)) void init(void)
> {
>         char *enval = NULL;
>         enval = getenv("LD_PRELOAD");
>         printf("enval LD_PRELOAD : %s\n", enval);
>         return;
> }
> 
> [root@localhost jh]# cat test.c
> #include <stdio.h>
> 
> int main(int argc, char **argv)
> {
>         printf("Hello World\n");
>         return 0;
> }
> 
> 2. Build test.c
> gcc test.c -o test
> 
> 3. Build init.c as so in three cases:
> 3.1 only link librte_eal.so
> gcc --shared -fPIC -lrte_eal   init.c -o libinit.so
> 3.2 link librte_eal.so and librte_net_i40e.so
> gcc --shared -fPIC -lrte_eal -lrte_net_i40e  init.c -o libinit_i40e.so
> 3.3 link librte_eal.so and librte_net_mlx5.so
> gcc --shared -fPIC -lrte_eal -lrte_net_mlx5  init.c -o libinit_mlx5.so
> 
> 4. run test using gdb and LD_PRELOAD 
> 4.1 : libinit.so links only librte_eal.so 
> LD_PRELOAD=./libinit.so   gdb  ./test    
> (gdb) r
> enval LD_PRELOAD : ./libinit.so
> enval LD_PRELOAD : ./libinit.so   (I don't know why the constrctor function 
> is executed twice.)
> Hello World
> 
> 4.2 libinit.so links librte_eal.so and librte_net_i40e.so
> LD_PRELOAD=./libinit_i40e.so    gdb  ./test
> enval LD_PRELOAD : ./libinit_i40e.so
> enval LD_PRELOAD : ./libinit_i40e.so    (I don't know why the constrctor 
> function is executed twice.)
> Hello World
> 
> 4.3 4.3 libinit.so links librte_eal.so and librte_net_mlx5.so
> LD_PRELOAD=./libinit_mlx5.so     gdb  ./test
> enval LD_PRELOAD : (null)              // ? ? ? ?
> enval LD_PRELOAD : ./libinit_mlx5.so
> Hello World
> 
> 
> After libinit.so is linked to librte_net_mlx5.so, the symptom when the gdb is 
> used to execute the program is different from the preceding two cases. The 
> value of LD_PRELOAD obtained is NULL for the first time.
> Have you ever had the same problem?
> Looking forward to your favourable reply.
> 
> Thanks
> 
> 
> 





Reply via email to