]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/csu/amd64/reloc.c
Replace literal uses of /usr/local in C sources with _PATH_LOCALBASE
[FreeBSD/FreeBSD.git] / lib / csu / amd64 / reloc.c
1 /*-
2  * Copyright (c) 2018 The FreeBSD Foundation
3  *
4  * This software was developed by Konstantin Belousov <kib@FreeBSD.org>
5  * under sponsorship from the FreeBSD Foundation.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  */
25
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
28
29 #include <machine/specialreg.h>
30 #include <machine/cpufunc.h>
31
32 static void
33 crt1_handle_rela(const Elf_Rela *r)
34 {
35         Elf_Addr *ptr, *where, target;
36         u_int p[4];
37         uint32_t cpu_feature, cpu_feature2;
38         uint32_t cpu_stdext_feature, cpu_stdext_feature2;
39
40         do_cpuid(1, p);
41         cpu_feature = p[3];
42         cpu_feature2 = p[2];
43         do_cpuid(0, p);
44         if (p[0] >= 7) {
45                 cpuid_count(7, 0, p);
46                 cpu_stdext_feature = p[1];
47                 cpu_stdext_feature2 = p[2];
48         } else {
49                 cpu_stdext_feature = 0;
50                 cpu_stdext_feature2 = 0;
51         }
52
53         switch (ELF_R_TYPE(r->r_info)) {
54         case R_X86_64_IRELATIVE:
55                 ptr = (Elf_Addr *)r->r_addend;
56                 where = (Elf_Addr *)r->r_offset;
57                 target = ((Elf_Addr (*)(uint32_t, uint32_t, uint32_t,
58                     uint32_t))ptr)(cpu_feature, cpu_feature2,
59                     cpu_stdext_feature, cpu_stdext_feature2);
60                 *where = target;
61                 break;
62         }
63 }