head	1.1;
access;
symbols
	netbsd-11-0-RC4:1.1
	netbsd-11-0-RC3:1.1
	netbsd-11-0-RC2:1.1
	netbsd-11-0-RC1:1.1
	perseant-exfatfs-base-20250801:1.1
	netbsd-11:1.1.0.10
	netbsd-11-base:1.1
	netbsd-10-1-RELEASE:1.1.2.2
	perseant-exfatfs-base-20240630:1.1
	perseant-exfatfs:1.1.0.8
	perseant-exfatfs-base:1.1
	netbsd-8-3-RELEASE:1.1.4.2
	netbsd-9-4-RELEASE:1.1.6.2
	netbsd-10-0-RELEASE:1.1.2.2
	netbsd-10-0-RC6:1.1.2.2
	netbsd-10-0-RC5:1.1.2.2
	netbsd-10-0-RC4:1.1.2.2
	netbsd-10-0-RC3:1.1.2.2
	netbsd-10-0-RC2:1.1.2.2
	netbsd-10-0-RC1:1.1.2.2
	netbsd-9:1.1.0.6
	netbsd-8:1.1.0.4
	netbsd-10:1.1.0.2;
locks; strict;
comment	@ * @;


1.1
date	2023.07.30.09.20.14;	author riastradh;	state Exp;
branches
	1.1.2.1
	1.1.4.1
	1.1.6.1;
next	;
commitid	2Ng83oFWa8e77OyE;

1.1.2.1
date	2023.07.30.09.20.14;	author martin;	state dead;
branches;
next	1.1.2.2;
commitid	rwHyGdWtbuvcC6zE;

1.1.2.2
date	2023.08.01.17.03.53;	author martin;	state Exp;
branches;
next	;
commitid	rwHyGdWtbuvcC6zE;

1.1.4.1
date	2023.07.30.09.20.14;	author martin;	state dead;
branches;
next	1.1.4.2;
commitid	PvF0kz2XVLX368AE;

1.1.4.2
date	2023.08.09.16.16.40;	author martin;	state Exp;
branches;
next	;
commitid	PvF0kz2XVLX368AE;

1.1.6.1
date	2023.07.30.09.20.14;	author sborrill;	state dead;
branches;
next	1.1.6.2;
commitid	UbitZ6emjrlgGmAE;

1.1.6.2
date	2023.08.11.12.13.10;	author sborrill;	state Exp;
branches;
next	;
commitid	UbitZ6emjrlgGmAE;


desc
@@


1.1
log
@ld.elf_so: Split hash functions into a separate file.

This way we can test them in isolation.

No functional change intended.
@
text
@/*	$NetBSD: rtld.h,v 1.146 2023/06/04 01:24:56 joerg Exp $	 */

/*
 * Copyright 1996 John D. Polstra.
 * Copyright 1996 Matt Thomas <matt@@3am-software.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by John Polstra.
 * 4. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef	RTLD_HASH_H
#define	RTLD_HASH_H

#include <sys/exec_elf.h>

Elf32_Word _rtld_sysv_hash(const char *);
Elf32_Word _rtld_gnu_hash(const char *);

#endif	/* RTLD_HASH_H */
@


1.1.6.1
log
@file hash.h was added on branch netbsd-9 on 2023-08-11 12:13:10 +0000
@
text
@d1 42
@


1.1.6.2
log
@Pull up the following revisions(s) (requested by riastradh in ticket #1712):
	distrib/sets/lists/debug/mi:	revision 1.409 via patch
	distrib/sets/lists/tests/mi:	revision 1.1280 via patch
	libexec/ld.elf_so/Makefile:	revision 1.145-1.147 via patch
	libexec/ld.elf_so/hash.c:	revision 1.1 via patch
	libexec/ld.elf_so/hash.h:	revision 1.1 via patch
	libexec/ld.elf_so/symbol.c:	revision 1.74-1.76 via patch
	tests/libexec/ld.elf_so/Makefile:	revision 1.21 via patch
	tests/libexec/ld.elf_so/t_hash.c:	revision 1.1 via patch

ld.elf_so: Fix sysv elf hash on edge cases like `ZZZZZW9p' on LP64
platforms where long is 64-bit.
@
text
@a0 41
/*	$NetBSD$	 */

/*
 * Copyright 1996 John D. Polstra.
 * Copyright 1996 Matt Thomas <matt@@3am-software.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by John Polstra.
 * 4. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef	RTLD_HASH_H
#define	RTLD_HASH_H

#include <sys/exec_elf.h>

Elf32_Word _rtld_elf_hash(const char *);

#endif	/* RTLD_HASH_H */
@


1.1.4.1
log
@file hash.h was added on branch netbsd-8 on 2023-08-09 16:16:40 +0000
@
text
@d1 42
@


1.1.4.2
log
@Pull up following revision(s) (requested by riastradh in ticket #1886):

	distrib/sets/lists/debug/mi			1.409 (patch)
	distrib/sets/lists/tests/mi			1.1280 (patch)
	libexec/ld.elf_so/Makefile			1.145-1.147 (patch)
	libexec/ld.elf_so/hash.c			1.1
	libexec/ld.elf_so/hash.h			1.1
	libexec/ld.elf_so/reloc.c			1.118 (patch)
	libexec/ld.elf_so/rtld.c			1.215 (patch)
	libexec/ld.elf_so/rtld.h			1.145,1.147 (patch)
	libexec/ld.elf_so/symbol.c			1.74-1.76 (patch)
	tests/libexec/ld.elf_so/Makefile		1.21 (patch)
	tests/libexec/ld.elf_so/t_hash.c		1.1

The SysV ABI specifies that the symbol hash function should return only 32
bits of hash. Unfortunately due to an implementation bu and the fact that
the return type is unsigned long which is 64 bits in LP64, this can fail
in some cases: "\xff\x0f\x0f\x0f\x0f\x0f\x12". See:
	https://maskray.me/blog/2023-04-12-elf-hash-function

From Ed Maste @@ FreeBSD:
	https://cgit.freebsd.org/src/commit/?id=29e3a06510823edbb91667d21f530d3ec778116d

Need to write Unit Tests for this.

Oops wrong mask.

ld.elf_so: Split SRCS onto multiple lines.
Makes updates easier.
No functional change intended.

ld.elf_so: Sort SRCS.
No functional change intended.

ld.elf_so: Split hash functions into a separate file.
This way we can test them in isolation.
No functional change intended.

ld.elf_so: Add some known-answer tests for hash functions.

Make sure the testing mechanism detects the traditional overflow bug.
@
text
@a0 41
/*	$NetBSD$	 */

/*
 * Copyright 1996 John D. Polstra.
 * Copyright 1996 Matt Thomas <matt@@3am-software.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by John Polstra.
 * 4. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef	RTLD_HASH_H
#define	RTLD_HASH_H

#include <sys/exec_elf.h>

Elf32_Word _rtld_elf_hash(const char *);

#endif	/* RTLD_HASH_H */
@


1.1.2.1
log
@file hash.h was added on branch netbsd-10 on 2023-08-01 17:03:53 +0000
@
text
@d1 42
@


1.1.2.2
log
@Pull up following revision(s) (requested by riastradh in ticket #300):

	libexec/ld.elf_so/rtld.h: revision 1.145
	libexec/ld.elf_so/symbol.c: revision 1.74
	libexec/ld.elf_so/rtld.h: revision 1.147
	libexec/ld.elf_so/symbol.c: revision 1.75
	libexec/ld.elf_so/symbol.c: revision 1.76
	tests/libexec/ld.elf_so/t_hash.c: revision 1.1
	libexec/ld.elf_so/Makefile: revision 1.145
	libexec/ld.elf_so/Makefile: revision 1.146
	libexec/ld.elf_so/Makefile: revision 1.147
	libexec/ld.elf_so/reloc.c: revision 1.118
	distrib/sets/lists/tests/mi: revision 1.1280
	libexec/ld.elf_so/rtld.c: revision 1.215
	tests/libexec/ld.elf_so/Makefile: revision 1.21
	libexec/ld.elf_so/hash.c: revision 1.1
	libexec/ld.elf_so/hash.h: revision 1.1
	distrib/sets/lists/debug/mi: revision 1.409

The SysV ABI specifies that the symbol hash function should return only 32
bits of hash. Unfortunately due to an implementation bug and the fact that
the return type is unsigned long which is 64 bits in LP64, this can fail
in some cases: "\xff\x0f\x0f\x0f\x0f\x0f\x12". See:
    "https://maskray.me/blog/2023-04-12-elf-hash-function
From Ed Maste @@ FreeBSD:
    https://cgit.freebsd.org/src/commit/?id=29e3a06510823edbb91667d21f530d3ec778116d

Need to write Unit Tests for this.

Oops wrong mask.

ld.elf_so: Split SRCS onto multiple lines.
Makes updates easier.
No functional change intended.

ld.elf_so: Sort SRCS.
No functional change intended.

ld.elf_so: Split hash functions into a separate file.
This way we can test them in isolation.
No functional change intended.

ld.elf_so: Add some known-answer tests for hash functions.

Make sure the testing mechanism detects the traditional overflow bug.
@
text
@a0 42
/*	$NetBSD: hash.h,v 1.1 2023/07/30 09:20:14 riastradh Exp $	 */

/*
 * Copyright 1996 John D. Polstra.
 * Copyright 1996 Matt Thomas <matt@@3am-software.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by John Polstra.
 * 4. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef	RTLD_HASH_H
#define	RTLD_HASH_H

#include <sys/exec_elf.h>

Elf32_Word _rtld_sysv_hash(const char *);
Elf32_Word _rtld_gnu_hash(const char *);

#endif	/* RTLD_HASH_H */
@


