<commit_before>/* Run an ELF binary on a linux system.

   Copyright (C) 1993, <NAME>.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */


#ifndef VERBOSE_DLINKER
#define VERBOSE_DLINKER
#endif
#ifdef VERBOSE_DLINKER
static char *_dl_reltypes[] =
	{ "R_386_NONE", "R_386_32", "R_386_PC32", "R_386_GOT32",
	"R_386_PLT32", "R_386_COPY", "R_386_GLOB_DAT",
	"R_386_JMP_SLOT", "R_386_RELATIVE", "R_386_GOTOFF",
	"R_386_GOTPC", "R_386_NUM"
};
#endif

/* Program to load an ELF binary on a linux system, and run it.
   References to symbols in sharable libraries can be resolved by either
   an ELF sharable library or a linux style of shared library. */

/* Disclaimer:  I have never seen any AT&T source code for SVr4, nor have
   I ever taken any courses on internals.  This program was developed using
   information available through the book "UNIX SYSTEM V RELEASE 4,
   Programmers guide: Ansi C and Programming Support Tools", which did
   a more than adequate job of explaining everything required to get this
   working. */

#include <sys/types.h>
#include <errno.h>
#include "elf.h"
#include "hash.h"
#include "syscall.h"
#include "string.h"
#include "sysdep.h"

extern char *_dl_progname;

extern int _dl_linux_resolve(void);

unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry)
{
	int reloc_type;
	Elf32_Rel *this_reloc;
	char *strtab;
	Elf32_Sym *symtab;
	Elf32_Rel *rel_addr;
	int symtab_index;
	char *new_addr;
	char **got_addr;
	unsigned long instr_addr;

	rel_addr = (Elf32_Rel *) (tpnt->dynamic_info[DT_JMPREL] + tpnt->loadaddr);

	this_reloc = rel_addr + (reloc_entry >> 3);
	reloc_type = ELF32_R_TYPE(this_reloc->r_info);
	symtab_index = ELF32_R_SYM(this_reloc->r_info);

	symtab = (Elf32_Sym *) (tpnt->dynamic_info[DT_SYMTAB] + tpnt->loadaddr);
	strtab = (char *) (tpnt->dynamic_info[DT_STRTAB] + tpnt->loadaddr);


	if (reloc_type != R_386_JMP_SLOT) {
		_dl_fdprintf(2, "%s: Incorrect relocation type in jump relocations\n", 
			_dl_progname);
		_dl_exit(1);
	};

	/* Address of jump instruction to fix up */
	instr_addr = ((int) this_reloc->r_offset + (int) tpnt->loadaddr);
	got_addr = (char **) instr_addr;

#ifdef DEBUG
	_dl_fdprintf(2, "Resolving symbol %s\n", 
		strtab + symtab[symtab_index].st_name);
#endif

	/* Get the address of the GOT entry */
	new_addr = _dl_find_hash(strtab + symtab[symtab_index].st_name, 
		tpnt->symbol_scope, (int) got_addr, tpnt, 0);
	if (!new_addr) {
		_dl_fdprintf(2, "%s: can't resolve symbol '%s'\n", 
			_dl_progname, strtab + symtab[symtab_index].st_name);
		_dl_exit(1);
	};
/* #define DEBUG_LIBRARY */<commit_msg>Scrub a couple of ints<commit_after>/* Run an ELF binary on a linux system.

   Copyright (C) 1993, <NAME>.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */


#ifndef VERBOSE_DLINKER
#define VERBOSE_DLINKER
#endif
#ifdef VERBOSE_DLINKER
static char *_dl_reltypes[] =
	{ "R_386_NONE", "R_386_32", "R_386_PC32", "R_386_GOT32",
	"R_386_PLT32", "R_386_COPY", "R_386_GLOB_DAT",
	"R_386_JMP_SLOT", "R_386_RELATIVE", "R_386_GOTOFF",
	"R_386_GOTPC", "R_386_NUM"
};
#endif

/* Program to load an ELF binary on a linux system, and run it.
   References to symbols in sharable libraries can be resolved by either
   an ELF sharable library or a linux style of shared library. */

/* Disclaimer:  I have never seen any AT&T source code for SVr4, nor have
   I ever taken any courses on internals.  This program was developed using
   information available through the book "UNIX SYSTEM V RELEASE 4,
   Programmers guide: Ansi C and Programming Support Tools", which did
   a more than adequate job of explaining everything required to get this
   working. */

#include <sys/types.h>
#include <errno.h>
#include "elf.h"
#include "hash.h"
#include "syscall.h"
#include "string.h"
#include "sysdep.h"

extern char *_dl_progname;

extern int _dl_linux_resolve(void);

unsigned long _dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry)
{
	int reloc_type;
	Elf32_Rel *this_reloc;
	char *strtab;
	Elf32_Sym *symtab;
	Elf32_Rel *rel_addr;
	int symtab_index;
	char *new_addr;
	char **got_addr;
	unsigned long instr_addr;

	rel_addr = (Elf32_Rel *) (tpnt->dynamic_info[DT_JMPREL] + tpnt->loadaddr);

	this_reloc = rel_addr + (reloc_entry >> 3);
	reloc_type = ELF32_R_TYPE(this_reloc->r_info);
	symtab_index = ELF32_R_SYM(this_reloc->r_info);

	symtab = (Elf32_Sym *) (tpnt->dynamic_info[DT_SYMTAB] + tpnt->loadaddr);
	strtab = (char *) (tpnt->dynamic_info[DT_STRTAB] + tpnt->loadaddr);


	if (reloc_type != R_386_JMP_SLOT) {
		_dl_fdprintf(2, "%s: Incorrect relocation type in jump relocations\n", 
			_dl_progname);
		_dl_exit(1);
	};

	/* Address of jump instruction to fix up */
	instr_addr = ((unsigned long) this_reloc->r_offset + 
		(unsigned long) tpnt->loadaddr);
	got_addr = (char **) instr_addr;

#ifdef DEBUG
	_dl_fdprintf(2, "Resolving symbol %s\n", 
		strtab + symtab[symtab_index].st_name);
#endif

	/* Get the address of the GOT entry */
	new_addr = _dl_find_hash(strtab + symtab[symtab_index].st_name, 
		tpnt->symbol_scope, (unsigned long) got_addr, tpnt, 0);
	if (!new_addr) {
		_dl_fdprintf(2, "%s: can't resolve symbol '%s'\n", 
			_dl_progname, strtab + symtab[symtab_index].st_name);
		_dl_exit(1);
	};
/* #define DEBUG_LIBRARY */
{'fraction_non_alphanumeric': 0.10116851168511685, 'fraction_numerical': 0.025522755227552277, 'mean_word_length': 4.452640402347025, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 35, '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': '5654077', 'n_tokens_mistral': 2490, 'n_tokens_neox': 2303, 'n_words': 745}