DPDK usage discussions
 help / color / mirror / Atom feed
* when link librte_net_mlx5.so and use gdb, my program can't get environment variable
@ 2023-12-04  9:45 jiangheng (G)
  2024-01-08  9:16 ` Thomas Monjalon
  0 siblings, 1 reply; 2+ messages in thread
From: jiangheng (G) @ 2023-12-04  9:45 UTC (permalink / raw)
  To: Matan Azrad, Slava Ovsiienko, orika, suanmingm, users

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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-08  9:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-04  9:45 when link librte_net_mlx5.so and use gdb, my program can't get environment variable jiangheng (G)
2024-01-08  9:16 ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).