<commit_before>/*
    Title:     Write out a database as an ELF object file
    Author:    <NAME>.

    Copyright (c) 2006-7, 2011, 2016 <NAME>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License version 2.1 as published by the Free Software Foundation.
    
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR H PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.
    
    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "config.h"

#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif

#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif

#ifdef HAVE_STDDEF_H
#include <stddef.h>
#endif

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif

#ifdef HAVE_TIME_H
#include <time.h>
#endif

#ifdef HAVE_ASSERT_H
#include <assert.h>
#define ASSERT(x) assert(x)
#else
#define ASSERT(x)
#endif

#ifdef HAVE_ELF_H
#include <elf.h>
#elif defined(HAVE_ELF_ABI_H)
#include <elf_abi.h>
#include <machine/reloc.h>

#ifndef EM_X86_64
#define EM_X86_64 EM_AMD64
#endif

#if defined(HOSTARCHITECTURE_X86_64)

#ifndef R_386_PC32
#define R_386_PC32 R_X86_64_PC32
#endif

#ifndef R_386_32
#define R_386_32 R_X86_64_32
#endif

#ifndef R_X86_64_64
#define R_X86_64_64 R_X86_64_64
#endif

#endif /* HOSTARCHITECTURE_X86_64 */

#endif

// Solaris seems to put processor-specific constants in separate files
#ifdef HAVE_SYS_ELF_SPARC_H
#include <sys/elf_SPARC.h>
#endif
#ifdef HAVE_SYS_ELF_386_H
#include <sys/elf_386.h>
#endif
#ifdef HAVE_SYS_ELF_AMD64_H
#include <sys/elf_amd64.h>
#endif

// Android has the ARM relocation symbol here
#ifdef HAVE_ASM_ELF_H
#include <asm/elf.h>
#endif

#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_SYS_UTSNAME_H
#include <sys/utsname.h>
#endif

#include "globals.h"

#include "diagnostics.h"
#include "sys.h"
#include "machine_dep.h"
#include "gc.h"
#include "mpoly.h"
#include "scanaddrs.h"
#include "elfexport.h"
#include "run_time.h"
#include "version.h"
#include "polystring.h"
#include "timing.h"

#define sym_last_local_sym sym_data_section

#if defined(HOSTARCHITECTURE_X86)
# define HOST_E_MACHINE EM_386
# define HOST_DIRECT_RELOC R_386_32
# define USE_RELA 0
#elif defined(HOSTARCHITECTURE_PPC)
# define HOST_E_MACHINE EM_PPC
# define HOST_DIRECT_RELOC R_PPC_ADDR32
# define USE_RELA 1
#elif defined(HOSTARCHITECTURE_PPC64)
# define HOST_E_MACHINE EM_PPC64
# define HOST_DIRECT_RELOC R_PPC64_ADDR64
# define USE_RELA 1
#elif defined(HOSTARCHITECTURE_S390)
# define HOST_E_MACHINE EM_S390
# define HOST_DIRECT_RELOC R_390_32
# define USE_RELA 1
#elif defined(HOSTARCHITECTURE_S390X)
# define HOST_E_MACHINE EM_S390
# define HOST_DIRECT_RELOC R_390_64
# define USE_RELA 1
#elif defined(HOSTARCHITECTURE_SH)
# define HOST_E_MACHINE EM_SH
# define HOST_DIRECT_RELOC R_SH_DIR32
# define USE_RELA 1
#elif defined(HOSTARCHITECTURE_SPARC)
# define HOST_E_MACHINE EM_SPARC
# define HOST_DIRECT_RELOC R_SPARC_32
# define USE_RELA 1
/* Sparc/Solaris, at least 2.8, requires ELF32_Rela relocations.  For some reason,
   though, it adds the value in the location being relocated (as with ELF32_Rel
   relocations) as well as the addend. To be safe, whenever we use an ELF32_Rela
   relocation we always zero the location to be relocated. */
#elif defined(HOSTARCHITECTURE_SPARC64)
# define HOST_E_MACHINE EM_SPARCV9
# define HOST_DIRECT_RELOC R_SPARC_64
/* Use the most relaxed memory model. At link time, the most restrictive one is
   chosen, so it does no harm to be as permissive as possible here. */
# define HOST_E_FLAGS EF_SPARCV9_RMO
# define USE_RELA 1
#elif defined(HOSTARCHITECTURE_X86_64)
/* It seems Solaris/X86-64 only supports ELF64_Rela relocations.  It appears that
   Linux will support either so we now use Rela on X86-64. */
# define HOST_E_MACHINE EM_X86_64
# define HOST_DIRECT_RELOC R_X86_64_64
# define USE_RELA 1
#elif defined(HOSTARCHITECTURE_X32)
# define HOST_E_MACHINE EM_X86_64
# define HOST_DIRECT_RELOC R_X86_64_32
# define USE_RELA 1
#elif defined(HOSTARCHITECTURE_ARM)
# ifndef EF_ARM_EABI_VER4
#  define EF_ARM_EABI_VER4     0x04000000
# endif
// When linking ARM binaries the linker checks the ABI version.  We
// need to set the version to the same as the libraries.
// GCC currently uses version 4.
# define HOST_E_MACHINE EM_ARM
# define HOST_DIRECT_RELOC R_ARM_ABS32
# define USE_RELA 0
# define HOST_E_FLAGS EF_ARM_EABI_VER4
#elif defined(HOSTARCHITECTURE_HPPA)
# define HOST_OSABI ELFOSABI_HPUX
# define HOST_E_MACHINE EM_PARISC
# define HOST_DIRECT_RELOC R_PARISC_DIR32
# define HOST_E_FLAGS EFA_PARISC_1_0
# define USE_RELA 1
#elif defined(HOSTARCHITECTURE_IA64)
# define HOST_E_MACHINE EM_IA_64
# define HOST_DIRECT_RELOC R_IA64_DIR64LSB
# define HOST_E_FLAGS EF_IA_64_ABI64
# define USE_RELA 1
#elif defined(HOSTARCHITECTURE_AARCH64)
# define HOST_E_MACHINE EM_AARCH64
# define HOST_DIRECT_RELOC R_AARCH64_ABS64
# define USE_RELA 1
#elif defined(HOSTARCHITECTURE_M68K)
# define HOST_E_MACHINE EM_68K
# define HOST_DIRECT_RELOC R_68K_32<commit_msg>Use correct ELF ABIs on HPPA<commit_after>/*
    Title:     Write out a database as an ELF object file
    Author:    <NAME>.

    Copyright (c) 2006-7, 2011, 2016 <NAME>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License version 2.1 as published by the Free Software Foundation.
    
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR H PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.
    
    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "config.h"

#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif

#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif

#ifdef HAVE_STDDEF_H
#include <stddef.h>
#endif

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif

#ifdef HAVE_TIME_H
#include <time.h>
#endif

#ifdef HAVE_ASSERT_H
#include <assert.h>
#define ASSERT(x) assert(x)
#else
#define ASSERT(x)
#endif

#ifdef HAVE_ELF_H
#include <elf.h>
#elif defined(HAVE_ELF_ABI_H)
#include <elf_abi.h>
#include <machine/reloc.h>

#ifndef EM_X86_64
#define EM_X86_64 EM_AMD64
#endif

#if defined(HOSTARCHITECTURE_X86_64)

#ifndef R_386_PC32
#define R_386_PC32 R_X86_64_PC32
#endif

#ifndef R_386_32
#define R_386_32 R_X86_64_32
#endif

#ifndef R_X86_64_64
#define R_X86_64_64 R_X86_64_64
#endif

#endif /* HOSTARCHITECTURE_X86_64 */

#endif

// Solaris seems to put processor-specific constants in separate files
#ifdef HAVE_SYS_ELF_SPARC_H
#include <sys/elf_SPARC.h>
#endif
#ifdef HAVE_SYS_ELF_386_H
#include <sys/elf_386.h>
#endif
#ifdef HAVE_SYS_ELF_AMD64_H
#include <sys/elf_amd64.h>
#endif

// Android has the ARM relocation symbol here
#ifdef HAVE_ASM_ELF_H
#include <asm/elf.h>
#endif

#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_SYS_UTSNAME_H
#include <sys/utsname.h>
#endif

#include "globals.h"

#include "diagnostics.h"
#include "sys.h"
#include "machine_dep.h"
#include "gc.h"
#include "mpoly.h"
#include "scanaddrs.h"
#include "elfexport.h"
#include "run_time.h"
#include "version.h"
#include "polystring.h"
#include "timing.h"

#define sym_last_local_sym sym_data_section

#if defined(HOSTARCHITECTURE_X86)
# define HOST_E_MACHINE EM_386
# define HOST_DIRECT_RELOC R_386_32
# define USE_RELA 0
#elif defined(HOSTARCHITECTURE_PPC)
# define HOST_E_MACHINE EM_PPC
# define HOST_DIRECT_RELOC R_PPC_ADDR32
# define USE_RELA 1
#elif defined(HOSTARCHITECTURE_PPC64)
# define HOST_E_MACHINE EM_PPC64
# define HOST_DIRECT_RELOC R_PPC64_ADDR64
# define USE_RELA 1
#elif defined(HOSTARCHITECTURE_S390)
# define HOST_E_MACHINE EM_S390
# define HOST_DIRECT_RELOC R_390_32
# define USE_RELA 1
#elif defined(HOSTARCHITECTURE_S390X)
# define HOST_E_MACHINE EM_S390
# define HOST_DIRECT_RELOC R_390_64
# define USE_RELA 1
#elif defined(HOSTARCHITECTURE_SH)
# define HOST_E_MACHINE EM_SH
# define HOST_DIRECT_RELOC R_SH_DIR32
# define USE_RELA 1
#elif defined(HOSTARCHITECTURE_SPARC)
# define HOST_E_MACHINE EM_SPARC
# define HOST_DIRECT_RELOC R_SPARC_32
# define USE_RELA 1
/* Sparc/Solaris, at least 2.8, requires ELF32_Rela relocations.  For some reason,
   though, it adds the value in the location being relocated (as with ELF32_Rel
   relocations) as well as the addend. To be safe, whenever we use an ELF32_Rela
   relocation we always zero the location to be relocated. */
#elif defined(HOSTARCHITECTURE_SPARC64)
# define HOST_E_MACHINE EM_SPARCV9
# define HOST_DIRECT_RELOC R_SPARC_64
/* Use the most relaxed memory model. At link time, the most restrictive one is
   chosen, so it does no harm to be as permissive as possible here. */
# define HOST_E_FLAGS EF_SPARCV9_RMO
# define USE_RELA 1
#elif defined(HOSTARCHITECTURE_X86_64)
/* It seems Solaris/X86-64 only supports ELF64_Rela relocations.  It appears that
   Linux will support either so we now use Rela on X86-64. */
# define HOST_E_MACHINE EM_X86_64
# define HOST_DIRECT_RELOC R_X86_64_64
# define USE_RELA 1
#elif defined(HOSTARCHITECTURE_X32)
# define HOST_E_MACHINE EM_X86_64
# define HOST_DIRECT_RELOC R_X86_64_32
# define USE_RELA 1
#elif defined(HOSTARCHITECTURE_ARM)
# ifndef EF_ARM_EABI_VER4
#  define EF_ARM_EABI_VER4     0x04000000
# endif
// When linking ARM binaries the linker checks the ABI version.  We
// need to set the version to the same as the libraries.
// GCC currently uses version 4.
# define HOST_E_MACHINE EM_ARM
# define HOST_DIRECT_RELOC R_ARM_ABS32
# define USE_RELA 0
# define HOST_E_FLAGS EF_ARM_EABI_VER4
#elif defined(HOSTARCHITECTURE_HPPA)
# if defined(__hpux)
#  define HOST_OSABI ELFOSABI_HPUX
# elif defined(__NetBSD__)
#  define HOST_OSABI ELFOSABI_NETBSD
# elif defined(__linux__)
#  define HOST_OSABI ELFOSABI_GNU
# endif
# define HOST_E_MACHINE EM_PARISC
# define HOST_DIRECT_RELOC R_PARISC_DIR32
# define HOST_E_FLAGS EFA_PARISC_1_0
# define USE_RELA 1
#elif defined(HOSTARCHITECTURE_IA64)
# define HOST_E_MACHINE EM_IA_64
# define HOST_DIRECT_RELOC R_IA64_DIR64LSB
# define HOST_E_FLAGS EF_IA_64_ABI64
# define USE_RELA 1
#elif defined(HOSTARCHITECTURE_AARCH64)
# define HOST_E_MACHINE EM_AARCH64
# define HOST_DIRECT_RELOC R_AARCH64_ABS64
# define USE_RELA 1
#elif defined(HOSTARCHITECTURE_M68K)
# define HOST_E_MACHINE EM_68K
# define HOST_DIRECT_RELOC R_68K_32
{'fraction_non_alphanumeric': 0.06763816332141875, 'fraction_numerical': 0.04784162771514985, 'mean_word_length': 5.3294663573085845, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6238741', 'n_tokens_mistral': 4561, 'n_tokens_neox': 4183, 'n_words': 1183}