Skip to contentSkip to conversation

tools: ynl: two patches to ease building with rpmbuild

PATCH Applied Jan Stancek 3 participants 6 messages Nov 12, 2024 – Nov 14, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover tools: ynl: two patches to ease building with rpmbuild

I'm looking to build and package ynl for Fedora and Centos Stream users. Default rpmbuild has couple hardening options enabled by default [1][2], which currently prevent ynl from building.

This series contains 2 small patches to address it.

[1] https://fedoraproject.org/wiki/Changes/Harden_All_Packages
[2] https://fedoraproject.org/wiki/Changes/PythonSafePath

Changes in v2:
- rebased on top of https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/

Jan Stancek (2):
tools: ynl: add script dir to sys.path
tools: ynl: extend CFLAGS to keep options from environment

 tools/net/ynl/cli.py             | 3 +++
 tools/net/ynl/ethtool.py         | 2 ++
 tools/net/ynl/generated/Makefile | 2 +-
 tools/net/ynl/lib/Makefile       | 2 +-
 tools/net/ynl/samples/Makefile   | 2 +-
 tools/net/ynl/ynl-gen-c.py       | 3 +++
 6 files changed, 11 insertions(+), 3 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/2 tools: ynl: add script dir to sys.path

Python options like PYTHONSAFEPATH or -P [1] do not add script directory to PYTHONPATH. ynl depends on this path to build and run.

[1] This option is default for Fedora rpmbuild since introduction of
https://fedoraproject.org/wiki/Changes/PythonSafePath

---
 tools/net/ynl/cli.py       | 3 +++
 tools/net/ynl/ethtool.py   | 2 ++
 tools/net/ynl/ynl-gen-c.py | 3 +++
 3 files changed, 8 insertions(+)
tools/net/ynl/cli.py +3 -0
index 9e95016b85b3..5e2913a7f3e4 100755
@@ -3,10 +3,13 @@
 
 import argparse
 import json
+import pathlib
 import pprint
+import sys
 import time
 import signal
 
+sys.path.append(pathlib.Path(__file__).resolve().parent.as_posix())
 from lib import YnlFamily, Netlink, NlError
 
 
tools/net/ynl/ethtool.py +2 -0
index 63c471f075ab..ebb0a11f67bf 100755
@@ -3,11 +3,13 @@
 
 import argparse
 import json
+import pathlib
 import pprint
 import sys
 import re
 import os
 
+sys.path.append(pathlib.Path(__file__).resolve().parent.as_posix())
 from lib import YnlFamily
 
 def args_to_req(ynl, op_name, args, req):
tools/net/ynl/ynl-gen-c.py +3 -0
index c48b69071111..394b0023b9a3 100755
@@ -4,12 +4,15 @@
 import argparse
 import collections
 import filecmp
+import pathlib
 import os
 import re
 import shutil
+import sys
 import tempfile
 import yaml
 
+sys.path.append(pathlib.Path(__file__).resolve().parent.as_posix())
 from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, SpecEnumEntry
 
 
Signature · 1 line
2.43.0
#3 lore raw

PATCH v2 2/2 tools: ynl: extend CFLAGS to keep options from environment

In reply to Jan Stancek

Package build environments like Fedora rpmbuild introduced hardening options (e.g. -pie -Wl,-z,now) by passing a -spec option to CFLAGS and LDFLAGS.

ynl Makefiles currently override CFLAGS but not LDFLAGS, which leads
to a mismatch and build failure:
CC sample devlink
/usr/bin/ld: devlink.o: relocation R_X86_64_32 against symbol `ynl_devlink_family' can not be used when making a PIE object; recompile with -fPIE /usr/bin/ld: failed to set dynamic section sizes: bad value
collect2: error: ld returned 1 exit status

Extend CFLAGS to support hardening options set by build environment.

---
 tools/net/ynl/generated/Makefile | 2 +-
 tools/net/ynl/lib/Makefile       | 2 +-
 tools/net/ynl/samples/Makefile   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
tools/net/ynl/generated/Makefile +1 -1
index 713f5fb9cc2d..7db5240de58a 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
 CC=gcc
-CFLAGS=-std=gnu11 -O2 -W -Wall -Wextra -Wno-unused-parameter -Wshadow \
+CFLAGS += -std=gnu11 -O2 -W -Wall -Wextra -Wno-unused-parameter -Wshadow \
 	-I../lib/ -idirafter $(UAPI_PATH)
 ifeq ("$(DEBUG)","1")
   CFLAGS += -g -fsanitize=address -fsanitize=leak -static-libasan
tools/net/ynl/lib/Makefile +1 -1
index 2887cc5de530..94c49cca3dca 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
 CC=gcc
-CFLAGS=-std=gnu11 -O2 -W -Wall -Wextra -Wno-unused-parameter -Wshadow
+CFLAGS += -std=gnu11 -O2 -W -Wall -Wextra -Wno-unused-parameter -Wshadow
 ifeq ("$(DEBUG)","1")
   CFLAGS += -g -fsanitize=address -fsanitize=leak -static-libasan
 endif
tools/net/ynl/samples/Makefile +1 -1
index e194a7565861..c9494a564da4 100644
@@ -3,7 +3,7 @@
 include ../Makefile.deps
 
 CC=gcc
-CFLAGS=-std=gnu11 -O2 -W -Wall -Wextra -Wno-unused-parameter -Wshadow \
+CFLAGS += -std=gnu11 -O2 -W -Wall -Wextra -Wno-unused-parameter -Wshadow \
 	-I../lib/ -I../generated/ -idirafter $(UAPI_PATH)
 ifeq ("$(DEBUG)","1")
   CFLAGS += -g -fsanitize=address -fsanitize=leak -static-libasan
Signature · 1 line
2.43.0
maintainer Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] tools: ynl: add script dir to sys.path

In reply to Jan Stancek
Quoted 8 lines · Jan Stancek

Python options like PYTHONSAFEPATH or -P [1] do not add script directory to PYTHONPATH. ynl depends on this path to build and run.

[1] This option is default for Fedora rpmbuild since introduction of
https://fedoraproject.org/wiki/Changes/PythonSafePath

maintainer Reviewed-by on v2 2/2
#4 lore raw

Re: [PATCH v2 2/2] tools: ynl: extend CFLAGS to keep options from environment

In reply to Jan Stancek
Quoted 11 lines · Jan Stancek

Package build environments like Fedora rpmbuild introduced hardening options (e.g. -pie -Wl,-z,now) by passing a -spec option to CFLAGS and LDFLAGS.

ynl Makefiles currently override CFLAGS but not LDFLAGS, which leads
to a mismatch and build failure:
CC sample devlink
/usr/bin/ld: devlink.o: relocation R_X86_64_32 against symbol `ynl_devlink_family' can not be used when making a PIE object; recompile with -fPIE /usr/bin/ld: failed to set dynamic section sizes: bad value
collect2: error: ld returned 1 exit status

Quoted 4 lines

Extend CFLAGS to support hardening options set by build environment.

#5 lore raw
In reply to Jan Stancek
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Tue, 12 Nov 2024 09:21:31 +0100 you wrote:

I'm looking to build and package ynl for Fedora and Centos Stream users. Default rpmbuild has couple hardening options enabled by default [1][2], which currently prevent ynl from building.

This series contains 2 small patches to address it.

[1] https://fedoraproject.org/wiki/Changes/Harden_All_Packages
[2] https://fedoraproject.org/wiki/Changes/PythonSafePath

[...]

Here is the summary with links:
- [v2,1/2] tools: ynl: add script dir to sys.path

    https://git.kernel.org/netdev/net-next/c/c3b3eb565bd7
  - [v2,2/2] tools: ynl: extend CFLAGS to keep options from environment
    https://git.kernel.org/netdev/net-next/c/05a318b4fc13

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html