NetBSD Problem Report #59564

From kardel@kardel.name  Tue Jul 29 19:40:20 2025
Return-Path: <kardel@kardel.name>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits)
	 client-signature RSA-PSS (2048 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 73C061A923C
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 29 Jul 2025 19:40:20 +0000 (UTC)
Message-Id: <20250729194015.4EA13AAAC2F7@pip.kardel.name>
Date: Tue, 29 Jul 2025 21:40:15 +0200 (CEST)
From: kardel@netbsd.org
Reply-To: kardel@netbsd.org
To: gnats-bugs@NetBSD.org
Subject: ELF source code compatibility regression
X-Send-Pr-Version: 3.95

>Number:         59564
>Notify-List:    kim
>Category:       lib
>Synopsis:       ELF source code compatibility regression
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    jkoshy
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jul 29 19:45:00 +0000 2025
>Last-Modified:  Tue Oct 14 16:15:23 +0000 2025
>Originator:     Frank Kardel
>Release:        NetBSD 10.99.15
>Organization:

>Environment:


System: NetBSD Build-0 10.99.15 NetBSD 10.99.15 (GENERIC) #1: Tue Jul 29 12:42:32 CEST 2025 kardel@gaia:/src/NetBSD/current/src/obj.amd64/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
	In 10.99.15 following ELF include sequence fails
#include <elf.h>
#include <libelf.h>
#include <gelf.h>

int main() { return 0; }

errors are:
n file included from /usr/include/elfdefinitions.h:34,
                 from /usr/include/libelf.h:40,
                 from test.c:2:
/usr/include/sys/elfdefinitions.h:2586:3: error: conflicting types for 'Elf32_Cap'; have 'struct <anonymous>'
 2586 | } Elf32_Cap;
      |   ^~~~~~~~~
In file included from test.c:1:
/usr/include/elf.h:743:3: note: previous declaration of 'Elf32_Cap' with type 'Elf32_Cap'
  743 | } Elf32_Cap;
      |   ^~~~~~~~~
/usr/include/sys/elfdefinitions.h:2595:3: error: conflicting types for 'Elf64_Cap'; have 'struct <anonymous>'
 2595 | } Elf64_Cap;
      |   ^~~~~~~~~
/usr/include/elf.h:751:3: note: previous declaration of 'Elf64_Cap' with type 'Elf64_Cap'
  751 | } Elf64_Cap;
      |   ^~~~~~~~~
/usr/include/sys/elfdefinitions.h:2622:3: error: conflicting types for 'Elf32_Dyn'; have 'struct <anonymous>'
 2622 | } Elf32_Dyn;
      |   ^~~~~~~~~
/usr/include/elf.h:762:3: note: previous declaration of 'Elf32_Dyn' with type 'Elf32_Dyn'
  762 | } Elf32_Dyn;
      |   ^~~~~~~~~
... many more

when removing #include <elf.h> the compilation succeeds.

On NetBSD 10.1_STABLE and versions before that including elf.h is not leading to errors.
This looks like a source code compatibility regression. The include sequence also works on other operating Sytems (Linux, Solaris, ...)

>How-To-Repeat:
	attempt to compile in 10.99.15:
#include <elf.h>
#include <libelf.h>
#include <gelf.h>

int main() { return 0; }

>Fix:
	revisit and fix elf includes

>Release-Note:

>Audit-Trail:

From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59564 CVS commit: src/external/bsd/elftoolchain/dist/common/sys
Date: Wed, 30 Jul 2025 18:26:04 -0400

 Module Name:	src
 Committed By:	christos
 Date:		Wed Jul 30 22:26:03 UTC 2025

 Modified Files:
 	src/external/bsd/elftoolchain/dist/common/sys: elfdefinitions.m4

 Log Message:
 PR/59564: Frank Kardel: Allow elfdefinitions.h and elf.h to co-exist.
 Unfortunately c does not allow structure redefinitions, even if the structures
 are identical. So include <sys/exec_elf.h> from <sys/elfdefinitions.h> and
 protect all the typedefs that exec_elf.h already provides with the guard
 of the sys/exec_elf.h file.
 Also fix the order of the cap union fields so that the sys/sys_exec.h and
 sys/elfdefinitions.h are identical.


 To generate a diff of this commit:
 cvs rdiff -u -r1.7 -r1.8 \
     src/external/bsd/elftoolchain/dist/common/sys/elfdefinitions.m4

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: Kimmo Suominen <kim@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: PR/59564 CVS commit: src/external/bsd/elftoolchain/dist/common/sys
Date: Thu, 31 Jul 2025 09:40:19 +0300

 ----- Forwarded message from Robert Elz <kre@netbsd.org> -----

 From: Robert Elz <kre@netbsd.org>
 To: source-changes@NetBSD.org
 Date: Thu, 31 Jul 2025 02:21:13 +0000
 Message-Id: <20250731022113.EF159FA40@cvs.NetBSD.org>
 Subject: CVS commit: src/external/bsd/elftoolchain/dist/common/sys
 Approved: for-source-only
 Reply-To: kre@netbsd.org

 Module Name:	src
 Committed By:	kre
 Date:		Thu Jul 31 02:21:13 UTC 2025

 Modified Files:
 	src/external/bsd/elftoolchain/dist/common/sys: elfdefinitions.m4

 Log Message:
 Revert this to rev 1.7 (reverse the previous 3 commits).

 This is a total mess - it simply cannot be done that way.


 To generate a diff of this commit:
 cvs rdiff -u -r1.10 -r1.11 \
     src/external/bsd/elftoolchain/dist/common/sys/elfdefinitions.m4

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.


 ----- End forwarded message -----

Responsible-Changed-From-To: lib-bug-people->jkoshy
Responsible-Changed-By: jkoshy@NetBSD.org
Responsible-Changed-When: Tue, 14 Oct 2025 16:15:23 +0000
Responsible-Changed-Why:


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2025 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.