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 
   26 #include <sys/cdefs.h>
   27 __FBSDID("$FreeBSD$");
   28 
   29 #include <sys/param.h>
   30 #include <sys/kernel.h>
   31 #include <sys/systm.h>
   32 #include <sys/exec.h>
   33 #include <sys/imgact.h>
   34 #include <sys/linker.h>
   35 #include <sys/sysent.h>
   36 #include <sys/imgact_elf.h>
   37 #include <sys/syscall.h>
   38 #include <sys/signalvar.h>
   39 #include <sys/vnode.h>
   40 
   41 #include <vm/vm.h>
   42 #include <vm/pmap.h>
   43 #include <vm/vm_param.h>
   44 
   45 #include <machine/elf.h>
   46 #include <machine/md_var.h>
   47 
   48 struct sysentvec elf32_freebsd_sysvec = {
   49         SYS_MAXSYSCALL,
   50         sysent,
   51         0,
   52         0,
   53         NULL,
   54         0,
   55         NULL,
   56         NULL,
   57         __elfN(freebsd_fixup),
   58         sendsig,
   59         sigcode,
   60         &szsigcode,
   61         NULL,
   62         "FreeBSD ELF32",
   63         __elfN(coredump),
   64         NULL,
   65         MINSIGSTKSZ,
   66         PAGE_SIZE,
   67         VM_MIN_ADDRESS,
   68         VM_MAXUSER_ADDRESS,
   69         USRSTACK,
   70         PS_STRINGS,
   71         VM_PROT_ALL,
   72         exec_copyout_strings,
   73         exec_setregs,
   74         NULL
   75 };
   76 
   77 static Elf32_Brandinfo freebsd_brand_info = {
   78                                                 ELFOSABI_FREEBSD,
   79                                                 EM_386,
   80                                                 "FreeBSD",
   81                                                 NULL,
   82                                                 "/libexec/ld-elf.so.1",
   83                                                 &elf32_freebsd_sysvec,
   84                                                 NULL,
   85                                           };
   86 
   87 SYSINIT(elf32, SI_SUB_EXEC, SI_ORDER_ANY,
   88         (sysinit_cfunc_t) elf32_insert_brand_entry,
   89         &freebsd_brand_info);
   90 
   91 static Elf32_Brandinfo freebsd_brand_oinfo = {
   92                                                 ELFOSABI_FREEBSD,
   93                                                 EM_386,
   94                                                 "FreeBSD",
   95                                                 NULL,
   96                                                 "/usr/libexec/ld-elf.so.1",
   97                                                 &elf32_freebsd_sysvec,
   98                                                 NULL,
   99                                           };
  100 
  101 SYSINIT(oelf32, SI_SUB_EXEC, SI_ORDER_ANY,
  102         (sysinit_cfunc_t) elf32_insert_brand_entry,
  103         &freebsd_brand_oinfo);
  104 
  105 
  106 void
  107 elf32_dump_thread(struct thread *td __unused, void *dst __unused,
  108     size_t *off __unused)
  109 {
  110 }
  111 
  112 
  113 /* Process one elf relocation with addend. */
  114 static int
  115 elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
  116     int type, int local, elf_lookup_fn lookup)
  117 {
  118         Elf_Addr *where;
  119         Elf_Addr addr;
  120         Elf_Addr addend;
  121         Elf_Word rtype, symidx;
  122         const Elf_Rel *rel;
  123         const Elf_Rela *rela;
  124 
  125         switch (type) {
  126         case ELF_RELOC_REL:
  127                 rel = (const Elf_Rel *)data;
  128                 where = (Elf_Addr *) (relocbase + rel->r_offset);
  129                 addend = *where;
  130                 rtype = ELF_R_TYPE(rel->r_info);
  131                 symidx = ELF_R_SYM(rel->r_info);
  132                 break;
  133         case ELF_RELOC_RELA:
  134                 rela = (const Elf_Rela *)data;
  135                 where = (Elf_Addr *) (relocbase + rela->r_offset);
  136                 addend = rela->r_addend;
  137                 rtype = ELF_R_TYPE(rela->r_info);
  138                 symidx = ELF_R_SYM(rela->r_info);
  139                 break;
  140         default:
  141                 panic("unknown reloc type %d\n", type);
  142         }
  143 
  144         if (local) {
  145                 if (rtype == R_386_RELATIVE) {  /* A + B */
  146                         addr = relocbase + addend;
  147                         if (*where != addr)
  148                                 *where = addr;
  149                 }
  150                 return (0);
  151         }
  152 
  153         switch (rtype) {
  154 
  155                 case R_386_NONE:        /* none */
  156                         break;
  157 
  158                 case R_386_32:          /* S + A */
  159                         addr = lookup(lf, symidx, 1);
  160                         if (addr == 0)
  161                                 return -1;
  162                         addr += addend;
  163                         if (*where != addr)
  164                                 *where = addr;
  165                         break;
  166 
  167                 case R_386_PC32:        /* S + A - P */
  168                         addr = lookup(lf, symidx, 1);
  169                         if (addr == 0)
  170                                 return -1;
  171                         addr += addend - (Elf_Addr)where;
  172                         if (*where != addr)
  173                                 *where = addr;
  174                         break;
  175 
  176                 case R_386_COPY:        /* none */
  177                         /*
  178                          * There shouldn't be copy relocations in kernel
  179                          * objects.
  180                          */
  181                         printf("kldload: unexpected R_COPY relocation\n");
  182                         return -1;
  183                         break;
  184 
  185                 case R_386_GLOB_DAT:    /* S */
  186                         addr = lookup(lf, symidx, 1);
  187                         if (addr == 0)
  188                                 return -1;
  189                         if (*where != addr)
  190                                 *where = addr;
  191                         break;
  192 
  193                 case R_386_RELATIVE:
  194                         break;
  195 
  196                 default:
  197                         printf("kldload: unexpected relocation type %d\n",
  198                                rtype);
  199                         return -1;
  200         }
  201         return(0);
  202 }
  203 
  204 int
  205 elf_reloc(linker_file_t lf, Elf_Addr relocbase, const void *data, int type,
  206     elf_lookup_fn lookup)
  207 {
  208 
  209         return (elf_reloc_internal(lf, relocbase, data, type, 0, lookup));
  210 }
  211 
  212 int
  213 elf_reloc_local(linker_file_t lf, Elf_Addr relocbase, const void *data,
  214     int type, elf_lookup_fn lookup)
  215 {
  216 
  217         return (elf_reloc_internal(lf, relocbase, data, type, 1, lookup));
  218 }
  219 
  220 int
  221 elf_cpu_load_file(linker_file_t lf __unused)
  222 {
  223 
  224         return (0);
  225 }
  226 
  227 int
  228 elf_cpu_unload_file(linker_file_t lf __unused)
  229 {
  230 
  231         return (0);
  232 }

Cache object: 0e739b2d320822100218d60a9ff0b8d5


[ 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.