Bug 1851629

Summary: dpdk Hello World example from dpdk-examples package fails to compile
Product: [Fedora] Fedora Reporter: Georg Sauthoff <fedora>
Component: dpdkAssignee: Neil Horman <nhorman>
Status: CLOSED INSUFFICIENT_DATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 31CC: aconole, linville, nhorman, tredaelli
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-07-29 18:11:51 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
patch to pass -fpie and -pie to the compiler and linker for applications none

Description Georg Sauthoff 2020-06-27 17:30:54 UTC
Description of problem:
The helloworld example from the dpdk-examples package doesn't compile.

Version-Release number of selected component (if applicable):
dpdk-examples-18.11.2-3.fc31.x86_64

How reproducible:
always

Steps to Reproduce:
1. export RTE_TARGET=x86_64-default-linuxapp-gcc
2. cp -r /usr/share/dpdk/examples/helloworld . && cd helloworld
3. make V=1

Actual results:
mkdir -p /home/juser/dpdk/helloworld/build
make -C /home/juser/dpdk/helloworld/build -f /home/juser/dpdk/helloworld/Makefile \
        S=/home/juser/dpdk/helloworld O=/home/juser/dpdk/helloworld/build SRCDIR=/home/juser/dpdk/helloworld
gcc -Wp,-MD,./.main.o.d.tmp  -m64 -pthread -fPIC  -march=corei7 -DRTE_MACHINE_CPUFLAG_SSE -DRTE_MACHINE_CPUFLAG_SSE2 -DRTE_MACHINE_CPUFLAG_SSE3 -DRTE_MACHINE_CPUFLAG_SSSE3 -DRTE_MACHINE_CPUFLAG_SSE4_1 -DRTE_MACHINE_CPUFLAG_SSE4_2  -I/home/juser/dpdk/helloworld/build/include -I/usr/share/dpdk/x86_64-default-linuxapp-gcc/include -include /usr/share/dpdk/x86_64-default-linuxapp-gcc/include/rte_config.h -D_GNU_SOURCE -O3 -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wold-style-definition -Wpointer-arith -Wcast-align -Wnested-externs -Wcast-qual -Wformat-nonliteral -Wformat-security -Wundef -Wwrite-strings -Wdeprecated -Wimplicit-fallthrough=2 -Wno-format-truncation -Wno-address-of-packed-member    -o main.o -c /home/juser/dpdk/helloworld/main.c
gcc -o helloworld -m64 -pthread -fPIC  -march=corei7 -DRTE_MACHINE_CPUFLAG_SSE -DRTE_MACHINE_CPUFLAG_SSE2 -DRTE_MACHINE_CPUFLAG_SSE3 -DRTE_MACHINE_CPUFLAG_SSSE3 -DRTE_MACHINE_CPUFLAG_SSE4_1 -DRTE_MACHINE_CPUFLAG_SSE4_2  -I/home/juser/dpdk/helloworld/build/include -I/usr/share/dpdk/x86_64-default-linuxapp-gcc/include -include /usr/share/dpdk/x86_64-default-linuxapp-gcc/include/rte_config.h -D_GNU_SOURCE -O3 -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wold-style-definition -Wpointer-arith -Wcast-align -Wnested-externs -Wcast-qual -Wformat-nonliteral -Wformat-security -Wundef -Wwrite-strings -Wdeprecated -Wimplicit-fallthrough=2 -Wno-format-truncation -Wno-address-of-packed-member  main.o -L/usr/share/dpdk/x86_64-default-linuxapp-gcc/lib -Wl,-lrte_flow_classify -Wl,--whole-archive -Wl,-lrte_pipeline -Wl,--no-whole-archive -Wl,--whole-archive -Wl,-lrte_table -Wl,--no-whole-archive -Wl,--whole-archive -Wl,-lrte_port -Wl,--no-whole-archive -Wl,-lrte_pdump -Wl,-lrte_distributor -Wl,-lrte_ip_frag -Wl,-lrte_meter -Wl,-lrte_lpm -Wl,--whole-archive -Wl,-lrte_acl -Wl,--no-whole-archive -Wl,-lrte_jobstats -Wl,-lrte_metrics -Wl,-lrte_bitratestats -Wl,-lrte_latencystats -Wl,-lrte_efd -Wl,-lrte_bpf -Wl,--whole-archive -Wl,-lrte_cfgfile -Wl,-lrte_gro -Wl,-lrte_gso -Wl,-lrte_hash -Wl,-lrte_member -Wl,-lrte_vhost -Wl,-lrte_kvargs -Wl,-lrte_mbuf -Wl,-lrte_net -Wl,-lrte_ethdev -Wl,-lrte_bbdev -Wl,-lrte_cryptodev -Wl,-lrte_security -Wl,-lrte_compressdev -Wl,-lrte_eventdev -Wl,-lrte_rawdev -Wl,-lrte_timer -Wl,-lrte_mempool -Wl,-lrte_mempool_ring -Wl,-lrte_ring -Wl,-lrte_pci -Wl,-lrte_eal -Wl,-lrte_cmdline -Wl,-lrte_reorder -Wl,-lrte_sched -Wl,-lrte_common_cpt -Wl,-lrte_common_octeontx -Wl,-lrte_common_dpaax -Wl,-lrte_bus_pci -Wl,-lrte_bus_vdev -Wl,-lrte_bus_dpaa -Wl,-lrte_bus_fslmc -Wl,--no-whole-archive -Wl,-lgcc_s -Wl,-ldl -Wl,-export-dynamic -Wl,-export-dynamic -L/home/juser/dpdk/helloworld/build/lib -L/usr/share/dpdk/x86_64-default-linuxapp-gcc/lib -Wl,--as-needed -Wl,-pie -Wl,-Map=helloworld.map -Wl,--cref
/usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/9/crtbegin.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a PIE object
/usr/bin/ld: final link failed: nonrepresentable section on output
collect2: error: ld returned 1 exit status
make[1]: *** [/usr/share/dpdk/mk/rte.app.mk:393: helloworld] Error 1
make: *** [/usr/share/dpdk/mk/rte.extapp.mk:15: all] Error 2


Expected results:
no compile errors and a working helloworld binary

Additional info:
It would also be nice if the RTE_TARGET makefile variable would default to something useful. If not explicitly set in the environment it defaults to x86_64-native-linuxapp-gcc although /usr/share/dpdk/ only has the x86_64-default-linuxapp-gcc target.

Thus the expectation here is to have RTE_TARGET default to an existing target.

Comment 1 Georg Sauthoff 2020-06-28 07:41:17 UTC
A workaround is to remove the -pie flag:

sed -i 's/-pie//' /usr/share/dpdk/mk/rte.app.mk

I guess then the -fPIC flag doesn't make sense as well:

sed 's/-fPIC//' -i /usr/share/dpdk/mk/exec-env/linuxapp/rte.vars.mk


Without -pie the helloworld example compiles and runs successfully.

I don't know if -pie was added by upstream or the Fedora package itself - and why.

Comment 2 Neil Horman 2020-06-29 00:06:11 UTC
yeah, but we need to build everything in fedora with -pie if we can, for security.  I think I can fix this.  Please install the dpdk, dpdk-devel, and dpdk-examples rpms from this scratch build:
https://koji.fedoraproject.org/koji/taskinfo?taskID=46301726

and confirm that you are able to build the examples properly please.

Comment 3 Georg Sauthoff 2020-06-29 19:54:35 UTC
Does this Fedora PIE policy also extend to the defaults of the installed compiler/build system?

I mean, if I compile my own software with Fedora's gcc then it **doesn't** implicitly enable PIE options.

For example, for an executable created by - say - `gcc -o mytool mytool.c` the `file` output reads

mytool: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, ...

and NOT

ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, ...

in contrast to most system executables.

Comment 4 Georg Sauthoff 2020-06-29 20:01:50 UTC
PS: Another thing to consider is DPDK's performance objective which likely conflicts with PIE (because of the added indirections).

In that sense adding -fPIC/-pie violates the principle of least surprise for dpdk users.

Comment 5 Neil Horman 2020-06-29 20:03:03 UTC
No, it has no bearing on the code you compile yourself, its just policy for fedora packages, which is why I need to fix it here.

Did the above build work for you?

Comment 6 Neil Horman 2020-06-29 20:03:54 UTC
dpdks upstream objective is performance, when packaging that performance is constrained by our other quality and security requirements

Comment 7 Georg Sauthoff 2020-06-29 20:50:05 UTC
(In reply to Neil Horman from comment #5)
> No, it has no bearing on the code you compile yourself, its just policy for
> fedora packages, which is why I need to fix it here.

And the DPDK examples are exactly code I compile myself.

The same goes for other code one wants to compile with the DPDK build system and thus ends up using the defaults present in:

/usr/share/dpdk/mk/rte.app.mk
/usr/share/dpdk/mk/exec-env/linuxapp/rte.vars.mk


> Did the above build work for you?

Haven't tested it yet.

Did you remove the -fPIC/-pie flags from the above files?

And did you adjust the default RTE_TARGET value?

Comment 8 Neil Horman 2020-06-30 10:56:55 UTC
Created attachment 1699282 [details]
patch to pass -fpie and -pie to the compiler and linker for applications

yes, and you're welcome to do whatever you like with the code that you build, but you opened this bz because the examples were failing to build with the Makefiles as shipped, so whatever corrections I make need to be in line with fedora policy.  

The build I gave you modified rte.app.mk and rte.vars.mk so that -fpie and -pie were passed to the compiler and to the linker respectively.

I'm attaching the patch so you can see what I did.  As you can see the rte.app.mk file was initially passing -fPIC to the compilation line, which is expected for DSO files during the sdk build itself, but breaks when building executables (as executables build with -pie need to have their objects compiled with -fpie, rather than -fpic)

Comment 9 Neil Horman 2020-07-08 10:45:12 UTC
ping, any test results?

Comment 10 Neil Horman 2020-07-13 17:12:32 UTC
ping again

Comment 11 Neil Horman 2020-07-29 18:11:51 UTC
closing due to inactivity

Comment 12 Georg Sauthoff 2021-07-04 19:44:50 UTC
I think that I already provided enough information, complete reproducing steps and some rationale behind this issue.