DPDK usage discussions
 help / color / mirror / Atom feed
From: Thomas Monjalon <thomas@monjalon.net>
To: "jiangheng (G)" <jiangheng14@huawei.com>
Cc: Matan Azrad <matan@nvidia.com>,
	Slava Ovsiienko <viacheslavo@nvidia.com>,
	 "orika@nvidia.com" <orika@nvidia.com>,
	"suanmingm@nvidia.com" <suanmingm@nvidia.com>,
	"users@dpdk.org" <users@dpdk.org>
Subject: Re: when link librte_net_mlx5.so and use gdb, my program can't get environment variable
Date: Mon, 08 Jan 2024 10:16:32 +0100	[thread overview]
Message-ID: <4274415.mogB4TqSGs@thomas> (raw)
In-Reply-To: <282c6e61a40f40ab81d8d14adce84f1e@huawei.com>

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	other threads:[~2024-01-08  9:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-04  9:45 jiangheng (G)
2024-01-08  9:16 ` Thomas Monjalon [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4274415.mogB4TqSGs@thomas \
    --to=thomas@monjalon.net \
    --cc=jiangheng14@huawei.com \
    --cc=matan@nvidia.com \
    --cc=orika@nvidia.com \
    --cc=suanmingm@nvidia.com \
    --cc=users@dpdk.org \
    --cc=viacheslavo@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).