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/amd64/amd64/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: releng/7.4/sys/amd64/amd64/elf_machdep.c 196924 2009-09-07 13:37:04Z bz $");
   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/sysent.h>
   39 #include <sys/signalvar.h>
   40 #include <sys/vnode.h>
   41 
   42 #include <vm/vm.h>
   43 #include <vm/pmap.h>
   44 #include <vm/vm_param.h>
   45 
   46 #include <machine/elf.h>
   47 #include <machine/md_var.h>
   48 
   49 struct sysentvec elf64_freebsd_sysvec = {
   50         .sv_size        = SYS_MAXSYSCALL,
   51         .sv_table       = sysent,
   52         .sv_mask        = 0,
   53         .sv_sigsize     = 0,
   54         .sv_sigtbl      = NULL,
   55         .sv_errsize     = 0,
   56         .sv_errtbl      = NULL,
   57         .sv_transtrap   = NULL,
   58         .sv_fixup       = __elfN(freebsd_fixup),
   59         .sv_sendsig     = sendsig,
   60         .sv_sigcode     = sigcode,
   61         .sv_szsigcode   = &szsigcode,
   62         .sv_prepsyscall = NULL,
   63         .sv_name        = "FreeBSD ELF64",
   64         .sv_coredump    = __elfN(coredump),
   65         .sv_imgact_try  = NULL,
   66         .sv_minsigstksz = MINSIGSTKSZ,
   67         .sv_pagesize    = PAGE_SIZE,
   68         .sv_minuser     = VM_MIN_ADDRESS,
   69         .sv_maxuser     = VM_MAXUSER_ADDRESS,
   70         .sv_usrstack    = USRSTACK,
   71         .sv_psstrings   = PS_STRINGS,
   72         .sv_stackprot   = VM_PROT_ALL,
   73         .sv_copyout_strings     = exec_copyout_strings,
   74         .sv_setregs     = exec_setregs,
   75         .sv_fixlimit    = NULL,
   76         .sv_maxssiz     = NULL
   77 };
   78 
   79 static Elf64_Brandinfo freebsd_brand_info = {
   80         .brand          = ELFOSABI_FREEBSD,
   81         .machine        = EM_X86_64,
   82         .compat_3_brand = "FreeBSD",
   83         .emul_path      = NULL,
   84         .interp_path    = "/libexec/ld-elf.so.1",
   85         .sysvec         = &elf64_freebsd_sysvec,
   86         .interp_newpath = NULL,
   87         .brand_note     = &elf64_freebsd_brandnote,
   88         .flags          = BI_CAN_EXEC_DYN | BI_BRAND_NOTE
   89 };
   90 
   91 SYSINIT(elf64, SI_SUB_EXEC, SI_ORDER_ANY,
   92         (sysinit_cfunc_t) elf64_insert_brand_entry,
   93         &freebsd_brand_info);
   94 
   95 static Elf64_Brandinfo freebsd_brand_oinfo = {
   96         .brand          = ELFOSABI_FREEBSD,
   97         .machine        = EM_X86_64,
   98         .compat_3_brand = "FreeBSD",
   99         .emul_path      = NULL,
  100         .interp_path    = "/usr/libexec/ld-elf.so.1",
  101         .sysvec         = &elf64_freebsd_sysvec,
  102         .interp_newpath = NULL,
  103         .brand_note     = &elf64_freebsd_brandnote,
  104         .flags          = BI_CAN_EXEC_DYN | BI_BRAND_NOTE
  105 };
  106 
  107 SYSINIT(oelf64, SI_SUB_EXEC, SI_ORDER_ANY,
  108         (sysinit_cfunc_t) elf64_insert_brand_entry,
  109         &freebsd_brand_oinfo);
  110 
  111 static Elf64_Brandinfo kfreebsd_brand_info = {
  112         .brand          = ELFOSABI_FREEBSD,
  113         .machine        = EM_X86_64,
  114         .compat_3_brand = "FreeBSD",
  115         .emul_path      = NULL,
  116         .interp_path    = "/lib/ld-kfreebsd-x86-64.so.1",
  117         .sysvec         = &elf64_freebsd_sysvec,
  118         .interp_newpath = NULL,
  119         .brand_note     = &elf64_kfreebsd_brandnote,
  120         .flags          = BI_CAN_EXEC_DYN | BI_BRAND_NOTE_MANDATORY
  121 };
  122 
  123 SYSINIT(kelf64, SI_SUB_EXEC, SI_ORDER_ANY,
  124         (sysinit_cfunc_t) elf64_insert_brand_entry,
  125         &kfreebsd_brand_info);
  126 
  127 
  128 void
  129 elf64_dump_thread(struct thread *td __unused, void *dst __unused,
  130     size_t *off __unused)
  131 {
  132 }
  133 
  134 
  135 /* Process one elf relocation with addend. */
  136 static int
  137 elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
  138     int type, int local, elf_lookup_fn lookup)
  139 {
  140         Elf64_Addr *where, val;
  141         Elf32_Addr *where32, val32;
  142         Elf_Addr addr;
  143         Elf_Addr addend;
  144         Elf_Size rtype, symidx;
  145         const Elf_Rel *rel;
  146         const Elf_Rela *rela;
  147 
  148         switch (type) {
  149         case ELF_RELOC_REL:
  150                 rel = (const Elf_Rel *)data;
  151                 where = (Elf_Addr *) (relocbase + rel->r_offset);
  152                 rtype = ELF_R_TYPE(rel->r_info);
  153                 symidx = ELF_R_SYM(rel->r_info);
  154                 /* Addend is 32 bit on 32 bit relocs */
  155                 switch (rtype) {
  156                 case R_X86_64_PC32:
  157                 case R_X86_64_32S:
  158                         addend = *(Elf32_Addr *)where;
  159                         break;
  160                 default:
  161                         addend = *where;
  162                         break;
  163                 }
  164                 break;
  165         case ELF_RELOC_RELA:
  166                 rela = (const Elf_Rela *)data;
  167                 where = (Elf_Addr *) (relocbase + rela->r_offset);
  168                 addend = rela->r_addend;
  169                 rtype = ELF_R_TYPE(rela->r_info);
  170                 symidx = ELF_R_SYM(rela->r_info);
  171                 break;
  172         default:
  173                 panic("unknown reloc type %d\n", type);
  174         }
  175 
  176         switch (rtype) {
  177 
  178                 case R_X86_64_NONE:     /* none */
  179                         break;
  180 
  181                 case R_X86_64_64:               /* S + A */
  182                         addr = lookup(lf, symidx, 1);
  183                         val = addr + addend;
  184                         if (addr == 0)
  185                                 return -1;
  186                         if (*where != val)
  187                                 *where = val;
  188                         break;
  189 
  190                 case R_X86_64_PC32:     /* S + A - P */
  191                         addr = lookup(lf, symidx, 1);
  192                         where32 = (Elf32_Addr *)where;
  193                         val32 = (Elf32_Addr)(addr + addend - (Elf_Addr)where);
  194                         if (addr == 0)
  195                                 return -1;
  196                         if (*where32 != val32)
  197                                 *where32 = val32;
  198                         break;
  199 
  200                 case R_X86_64_32S:      /* S + A sign extend */
  201                         addr = lookup(lf, symidx, 1);
  202                         val32 = (Elf32_Addr)(addr + addend);
  203                         where32 = (Elf32_Addr *)where;
  204                         if (addr == 0)
  205                                 return -1;
  206                         if (*where32 != val32)
  207                                 *where32 = val32;
  208                         break;
  209 
  210                 case R_X86_64_COPY:     /* none */
  211                         /*
  212                          * There shouldn't be copy relocations in kernel
  213                          * objects.
  214                          */
  215                         printf("kldload: unexpected R_COPY relocation\n");
  216                         return -1;
  217                         break;
  218 
  219                 case R_X86_64_GLOB_DAT: /* S */
  220                 case R_X86_64_JMP_SLOT: /* XXX need addend + offset */
  221                         addr = lookup(lf, symidx, 1);
  222                         if (addr == 0)
  223                                 return -1;
  224                         if (*where != addr)
  225                                 *where = addr;
  226                         break;
  227 
  228                 case R_X86_64_RELATIVE: /* B + A */
  229                         addr = relocbase + addend;
  230                         val = addr;
  231                         if (*where != val)
  232                                 *where = val;
  233                         break;
  234 
  235                 default:
  236                         printf("kldload: unexpected relocation type %ld\n",
  237                                rtype);
  238                         return -1;
  239         }
  240         return(0);
  241 }
  242 
  243 int
  244 elf_reloc(linker_file_t lf, Elf_Addr relocbase, const void *data, int type,
  245     elf_lookup_fn lookup)
  246 {
  247 
  248         return (elf_reloc_internal(lf, relocbase, data, type, 0, lookup));
  249 }
  250 
  251 int
  252 elf_reloc_local(linker_file_t lf, Elf_Addr relocbase, const void *data,
  253     int type, elf_lookup_fn lookup)
  254 {
  255 
  256         return (elf_reloc_internal(lf, relocbase, data, type, 1, lookup));
  257 }
  258 
  259 int
  260 elf_cpu_load_file(linker_file_t lf __unused)
  261 {
  262 
  263         return (0);
  264 }
  265 
  266 int
  267 elf_cpu_unload_file(linker_file_t lf __unused)
  268 {
  269 
  270         return (0);
  271 }

Cache object: 728dfcd90dc7721653338afe8c93351e


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