The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/i386/i386/elf_machdep.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright 1996-1998 John D. Polstra.
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  *
   14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   24  *
   25  * $FreeBSD: releng/5.1/sys/i386/i386/elf_machdep.c 109605 2003-01-21 02:42:44Z jake $
   26  */
   27 
   28 #include <sys/param.h>
   29 #include <sys/kernel.h>
   30 #include <sys/systm.h>
   31 #include <sys/exec.h>
   32 #include <sys/imgact.h>
   33 #include <sys/linker.h>
   34 #include <sys/sysent.h>
   35 #include <sys/imgact_elf.h>
   36 #include <sys/syscall.h>
   37 #include <sys/signalvar.h>
   38 #include <sys/vnode.h>
   39 
   40 #include <vm/vm.h>
   41 #include <vm/pmap.h>
   42 #include <vm/vm_param.h>
   43 
   44 #include <machine/elf.h>
   45 #include <machine/md_var.h>
   46 
   47 struct sysentvec elf32_freebsd_sysvec = {
   48         SYS_MAXSYSCALL,
   49         sysent,
   50         0,
   51         0,
   52         NULL,
   53         0,
   54         NULL,
   55         NULL,
   56         __elfN(freebsd_fixup),
   57         sendsig,
   58         sigcode,
   59         &szsigcode,
   60         NULL,
   61         "FreeBSD ELF32",
   62         __elfN(coredump),
   63         NULL,
   64         MINSIGSTKSZ,
   65         PAGE_SIZE,
   66         VM_MIN_ADDRESS,
   67         VM_MAXUSER_ADDRESS,
   68         USRSTACK,
   69         PS_STRINGS,
   70         VM_PROT_ALL,
   71         exec_copyout_strings,
   72         exec_setregs
   73 };
   74 
   75 static Elf32_Brandinfo freebsd_brand_info = {
   76                                                 ELFOSABI_FREEBSD,
   77                                                 EM_386,
   78                                                 "FreeBSD",
   79                                                 "",
   80                                                 "/usr/libexec/ld-elf.so.1",
   81                                                 &elf32_freebsd_sysvec
   82                                           };
   83 
   84 SYSINIT(elf32, SI_SUB_EXEC, SI_ORDER_ANY,
   85         (sysinit_cfunc_t) elf32_insert_brand_entry,
   86         &freebsd_brand_info);
   87 
   88 /* Process one elf relocation with addend. */
   89 static int
   90 elf_reloc_internal(linker_file_t lf, const void *data, int type, int local)
   91 {
   92         Elf_Addr relocbase = (Elf_Addr) lf->address;
   93         Elf_Addr *where;
   94         Elf_Addr addr;
   95         Elf_Addr addend;
   96         Elf_Word rtype, symidx;
   97         const Elf_Rel *rel;
   98         const Elf_Rela *rela;
   99 
  100         switch (type) {
  101         case ELF_RELOC_REL:
  102                 rel = (const Elf_Rel *)data;
  103                 where = (Elf_Addr *) (relocbase + rel->r_offset);
  104                 addend = *where;
  105                 rtype = ELF_R_TYPE(rel->r_info);
  106                 symidx = ELF_R_SYM(rel->r_info);
  107                 break;
  108         case ELF_RELOC_RELA:
  109                 rela = (const Elf_Rela *)data;
  110                 where = (Elf_Addr *) (relocbase + rela->r_offset);
  111                 addend = rela->r_addend;
  112                 rtype = ELF_R_TYPE(rela->r_info);
  113                 symidx = ELF_R_SYM(rela->r_info);
  114                 break;
  115         default:
  116                 panic("unknown reloc type %d\n", type);
  117         }
  118 
  119         if (local) {
  120                 if (rtype == R_386_RELATIVE) {  /* A + B */
  121                         addr = relocbase + addend;
  122                         if (*where != addr)
  123                                 *where = addr;
  124                 }
  125                 return (0);
  126         }
  127 
  128         switch (rtype) {
  129 
  130                 case R_386_NONE:        /* none */
  131                         break;
  132 
  133                 case R_386_32:          /* S + A */
  134                         addr = elf_lookup(lf, symidx, 1);
  135                         if (addr == 0)
  136                                 return -1;
  137                         addr += addend;
  138                         if (*where != addr)
  139                                 *where = addr;
  140                         break;
  141 
  142                 case R_386_PC32:        /* S + A - P */
  143                         addr = elf_lookup(lf, symidx, 1);
  144                         if (addr == 0)
  145                                 return -1;
  146                         addr += addend - (Elf_Addr)where;
  147                         if (*where != addr)
  148                                 *where = addr;
  149                         break;
  150 
  151                 case R_386_COPY:        /* none */
  152                         /*
  153                          * There shouldn't be copy relocations in kernel
  154                          * objects.
  155                          */
  156                         printf("kldload: unexpected R_COPY relocation\n");
  157                         return -1;
  158                         break;
  159 
  160                 case R_386_GLOB_DAT:    /* S */
  161                         addr = elf_lookup(lf, symidx, 1);
  162                         if (addr == 0)
  163                                 return -1;
  164                         if (*where != addr)
  165                                 *where = addr;
  166                         break;
  167 
  168                 case R_386_RELATIVE:
  169                         break;
  170 
  171                 default:
  172                         printf("kldload: unexpected relocation type %d\n",
  173                                rtype);
  174                         return -1;
  175         }
  176         return(0);
  177 }
  178 
  179 int
  180 elf_reloc(linker_file_t lf, const void *data, int type)
  181 {
  182 
  183         return (elf_reloc_internal(lf, data, type, 0));
  184 }
  185 
  186 int
  187 elf_reloc_local(linker_file_t lf, const void *data, int type)
  188 {
  189 
  190         return (elf_reloc_internal(lf, data, type, 1));
  191 }
  192 
  193 int
  194 elf_cpu_load_file(linker_file_t lf __unused)
  195 {
  196 
  197         return (0);
  198 }
  199 
  200 int
  201 elf_cpu_unload_file(linker_file_t lf __unused)
  202 {
  203 
  204         return (0);
  205 }

Cache object: 004e54434c4df6cfc799d145f7b41ee6


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.