Skip to content

Commit 8874a37

Browse files
committed
Add <link.h> for absl
1 parent a11016e commit 8874a37

File tree

5 files changed

+99
-0
lines changed

5 files changed

+99
-0
lines changed

ape/ape.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,8 @@ ape_loader_end:
752752
#if SupportsSystemv() || SupportsMetal()
753753
.section .elf.phdrs,"a",@progbits
754754

755+
.globl ape_phdrs
756+
ape_phdrs:
755757
.long PT_LOAD
756758
.long PF_R|PF_X
757759
.stub ape_cod_offset,quad

ape/sections.internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ extern uint8_t __data_start[] __attribute__((__weak__));
2222
extern uint8_t __data_end[] __attribute__((__weak__));
2323
extern uint8_t __bss_start[] __attribute__((__weak__));
2424
extern uint8_t __bss_end[] __attribute__((__weak__));
25+
extern unsigned char ape_phdrs[] __attribute__((__weak__));
2526

2627
COSMOPOLITAN_C_END_
2728
#endif /* COSMOPOLITAN_APE_SECTIONS_INTERNAL_H_ */

libc/calls/dl_iterate_phdr.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
2+
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
3+
╞══════════════════════════════════════════════════════════════════════════════╡
4+
│ Copyright 2023 Justine Alexandra Roberts Tunney │
5+
│ │
6+
│ Permission to use, copy, modify, and/or distribute this software for │
7+
│ any purpose with or without fee is hereby granted, provided that the │
8+
│ above copyright notice and this permission notice appear in all copies. │
9+
│ │
10+
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
11+
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
12+
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
13+
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
14+
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
15+
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
16+
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
17+
│ PERFORMANCE OF THIS SOFTWARE. │
18+
╚─────────────────────────────────────────────────────────────────────────────*/
19+
#include "ape/sections.internal.h"
20+
#include "libc/elf/link.h"
21+
#include "libc/runtime/runtime.h"
22+
23+
int dl_iterate_phdr(int callback(struct dl_phdr_info *info, size_t size,
24+
void *data),
25+
void *data) {
26+
struct dl_phdr_info info = {
27+
.dlpi_addr = (uintptr_t)__executable_start,
28+
.dlpi_name = GetProgramExecutableName(),
29+
.dlpi_phdr = (const Elf64_Phdr *)ape_phdrs,
30+
.dlpi_phnum = 3,
31+
};
32+
return callback(&info, sizeof(info), data);
33+
}

libc/elf/link.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef COSMOPOLITAN_ELF_LINK_H_
2+
#define COSMOPOLITAN_ELF_LINK_H_
3+
#include "libc/elf/scalar.h"
4+
#include "libc/elf/struct/dyn.h"
5+
#include "libc/elf/struct/phdr.h"
6+
COSMOPOLITAN_C_START_
7+
8+
#define ElfW(type) Elf64_##type
9+
10+
struct dl_phdr_info {
11+
Elf64_Addr dlpi_addr;
12+
const char *dlpi_name;
13+
const Elf64_Phdr *dlpi_phdr;
14+
Elf64_Half dlpi_phnum;
15+
unsigned long long int dlpi_adds;
16+
unsigned long long int dlpi_subs;
17+
size_t dlpi_tls_modid;
18+
void *dlpi_tls_data;
19+
};
20+
21+
struct link_map {
22+
Elf64_Addr l_addr;
23+
char *l_name;
24+
Elf64_Dyn *l_ld;
25+
struct link_map *l_next;
26+
struct link_map *l_prev;
27+
};
28+
29+
struct r_debug {
30+
int r_version;
31+
struct link_map *r_map;
32+
Elf64_Addr r_brk;
33+
enum { RT_CONSISTENT, RT_ADD, RT_DELETE } r_state;
34+
Elf64_Addr r_ldbase;
35+
};
36+
37+
int dl_iterate_phdr(int (*)(struct dl_phdr_info *, size_t, void *), void *);
38+
39+
COSMOPOLITAN_C_END_
40+
#endif /* COSMOPOLITAN_ELF_LINK_H_ */

libc/isystem/link.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef _LINK_H
2+
#define _LINK_H
3+
#include "libc/elf/def.h"
4+
#include "libc/elf/link.h"
5+
#include "libc/elf/scalar.h"
6+
#include "libc/elf/struct/auxv.h"
7+
#include "libc/elf/struct/chdr.h"
8+
#include "libc/elf/struct/dyn.h"
9+
#include "libc/elf/struct/ehdr.h"
10+
#include "libc/elf/struct/lib.h"
11+
#include "libc/elf/struct/move.h"
12+
#include "libc/elf/struct/nhdr.h"
13+
#include "libc/elf/struct/phdr.h"
14+
#include "libc/elf/struct/rel.h"
15+
#include "libc/elf/struct/rela.h"
16+
#include "libc/elf/struct/shdr.h"
17+
#include "libc/elf/struct/sym.h"
18+
#include "libc/elf/struct/syminfo.h"
19+
#include "libc/elf/struct/verdaux.h"
20+
#include "libc/elf/struct/verdef.h"
21+
#include "libc/elf/struct/vernaux.h"
22+
#include "libc/elf/struct/verneed.h"
23+
#endif /* _LINK_H */

0 commit comments

Comments
 (0)