From 287dc7837edbd1be9ec02275c5c0dd0d035749d2 Mon Sep 17 00:00:00 2001 From: Nick Hainke Date: Wed, 18 Dec 2024 00:16:20 +0100 Subject: [PATCH] bird2: replace gcc flag workaround with patch fixing alignment issues Previously, we used the -mno-unaligned-access flag to instruct GCC to forbid unaligned memory access on arm processors. This was a workaround for alignment issues that caused crashes. This commit imports a patch from the BIRD mailing list discussion [0] that resolves the alignment issue by modifying the net_addr structure, removing the need for the GCC flag. The patch addresses the alignment problem more efficiently and avoids the performance, code size, and hardware optimization drawbacks of the flag. [0] - http://trubka.network.cz/pipermail/bird-users/2024-December/017957.html Signed-off-by: Nick Hainke --- bird2/Makefile | 4 -- ...001-fix-net_addr-alignment-for-armv7.patch | 44 +++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 bird2/patches/001-fix-net_addr-alignment-for-armv7.patch diff --git a/bird2/Makefile b/bird2/Makefile index 7fbd56752..fd4bc57b3 100644 --- a/bird2/Makefile +++ b/bird2/Makefile @@ -97,10 +97,6 @@ protocols, telling BIRD to show various information, telling it to show a routing table filtered by a filter, or asking BIRD to reconfigure. endef -ifeq ($(ARCH),arm) -TARGET_CFLAGS+=-mno-unaligned-access -endif - CONFIGURE_ARGS += --disable-libssh define Package/bird2/conffiles diff --git a/bird2/patches/001-fix-net_addr-alignment-for-armv7.patch b/bird2/patches/001-fix-net_addr-alignment-for-armv7.patch new file mode 100644 index 000000000..2fff0f418 --- /dev/null +++ b/bird2/patches/001-fix-net_addr-alignment-for-armv7.patch @@ -0,0 +1,44 @@ +From b4e8108cb2995f45d63105f6b179d8e4a155eab5 Mon Sep 17 00:00:00 2001 +From: Nick Hainke +Date: Tue, 17 Dec 2024 23:38:45 +0100 +Subject: [PATCH] Fix net_addr alignment for armv7 + +The patch originates from the mailing list discussion [0]. + +On armv7 platforms, the `net_addr` structure caused alignment issues due +to the use of `u64 align[0]`, which requires 8-byte alignment. This led +to crashes on systems with stricter alignment rules. + +This patch changes the alignment to `u32 align[0]`, which resolves the +crashes. However, this change may still cause issues with VPN network types +that rely on stricter alignment. + +Previously, we used a workaround with `-mno-unaligned-access` [1,2], +which prevents unaligned memory crashes but comes at the cost of reduced +performance, larger code size, and missed hardware optimizations. Applying +this patch is a better solution, even if VPN network types may still face +problems. Alignment issues are expected to be properly resolved in the +upcoming BIRD 3 release, so this patch will not be merged into upstream BIRD +since it also originates from the BIRD mailing list discussion. + +[0] - http://trubka.network.cz/pipermail/bird-users/2024-December/017957.html +[1] - https://github.com/freifunk-berlin/falter-packages/commit/fcce390fc57b44593fe969f1063c6ba711fc7f9b +[2] - https://github.com/openwrt/routing/commit/0209a1f3be5d0d227c34c7e73ff779ef7dcc533e + +Signed-off-by: Nick Hainke +--- +--- + lib/net.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/lib/net.h ++++ b/lib/net.h +@@ -51,7 +51,7 @@ typedef struct net_addr { + u8 pxlen; + u16 length; + u8 data[20]; +- u64 align[0]; ++ u32 align[0]; + } net_addr; + + typedef struct net_addr_ip4 {