hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/tools/perf/util/genelf.c
....@@ -1,41 +1,40 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * genelf.c
34 * Copyright (C) 2014, Google, Inc
45 *
56 * Contributed by:
67 * Stephane Eranian <eranian@gmail.com>
7
- *
8
- * Released under the GPL v2. (and only v2, not any later version)
98 */
109
1110 #include <sys/types.h>
12
-#include <stdio.h>
13
-#include <getopt.h>
1411 #include <stddef.h>
1512 #include <libelf.h>
1613 #include <string.h>
1714 #include <stdlib.h>
15
+#include <unistd.h>
1816 #include <inttypes.h>
19
-#include <limits.h>
2017 #include <fcntl.h>
2118 #include <err.h>
2219 #ifdef HAVE_DWARF_SUPPORT
2320 #include <dwarf.h>
2421 #endif
2522
26
-#include "perf.h"
2723 #include "genelf.h"
2824 #include "../util/jitdump.h"
25
+#include <linux/compiler.h>
2926
3027 #ifndef NT_GNU_BUILD_ID
3128 #define NT_GNU_BUILD_ID 3
3229 #endif
3330
34
-#define JVMTI
35
-
3631 #define BUILD_ID_URANDOM /* different uuid for each run */
3732
38
-#ifdef HAVE_LIBCRYPTO
33
+// FIXME, remove this and fix the deprecation warnings before its removed and
34
+// We'll break for good here...
35
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
36
+
37
+#ifdef HAVE_LIBCRYPTO_SUPPORT
3938
4039 #define BUILD_ID_MD5
4140 #undef BUILD_ID_SHA /* does not seem to work well when linked with Java */
....@@ -252,6 +251,7 @@
252251 Elf_Data *d;
253252 Elf_Scn *scn;
254253 Elf_Ehdr *ehdr;
254
+ Elf_Phdr *phdr;
255255 Elf_Shdr *shdr;
256256 uint64_t eh_frame_base_offset;
257257 char *strsym = NULL;
....@@ -285,6 +285,19 @@
285285 ehdr->e_entry = GEN_ELF_TEXT_OFFSET;
286286 ehdr->e_version = EV_CURRENT;
287287 ehdr->e_shstrndx= unwinding ? 4 : 2; /* shdr index for section name */
288
+
289
+ /*
290
+ * setup program header
291
+ */
292
+ phdr = elf_newphdr(e, 1);
293
+ phdr[0].p_type = PT_LOAD;
294
+ phdr[0].p_offset = 0;
295
+ phdr[0].p_vaddr = 0;
296
+ phdr[0].p_paddr = 0;
297
+ phdr[0].p_filesz = csize;
298
+ phdr[0].p_memsz = csize;
299
+ phdr[0].p_flags = PF_X | PF_R;
300
+ phdr[0].p_align = 8;
288301
289302 /*
290303 * setup text section
....@@ -511,44 +524,3 @@
511524
512525 return retval;
513526 }
514
-
515
-#ifndef JVMTI
516
-
517
-static unsigned char x86_code[] = {
518
- 0xBB, 0x2A, 0x00, 0x00, 0x00, /* movl $42, %ebx */
519
- 0xB8, 0x01, 0x00, 0x00, 0x00, /* movl $1, %eax */
520
- 0xCD, 0x80 /* int $0x80 */
521
-};
522
-
523
-static struct options options;
524
-
525
-int main(int argc, char **argv)
526
-{
527
- int c, fd, ret;
528
-
529
- while ((c = getopt(argc, argv, "o:h")) != -1) {
530
- switch (c) {
531
- case 'o':
532
- options.output = optarg;
533
- break;
534
- case 'h':
535
- printf("Usage: genelf -o output_file [-h]\n");
536
- return 0;
537
- default:
538
- errx(1, "unknown option");
539
- }
540
- }
541
-
542
- fd = open(options.output, O_CREAT|O_TRUNC|O_RDWR, 0666);
543
- if (fd == -1)
544
- err(1, "cannot create file %s", options.output);
545
-
546
- ret = jit_write_elf(fd, "main", x86_code, sizeof(x86_code));
547
- close(fd);
548
-
549
- if (ret != 0)
550
- unlink(options.output);
551
-
552
- return ret;
553
-}
554
-#endif