Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/std/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pedantic = { level = "warn", priority = -1 }
result_large_err = "allow"

[workspace.dependencies]
bytes = { version = "1", features = ["serde"] }
clap = { version = "4", features = ["derive"] }
fnv = "1"
futures = "0.3"
Expand All @@ -35,6 +36,7 @@ libc = "0.2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tangram_client = { default-features = false, git = "https://github.com/tangramdotdev/tangram", rev = "58527c57de3217c82d0c54e3dacaba6394245fec" }
tangram_serialize = { default-features = false, git = "https://github.com/tangramdotdev/tangram", rev = "58527c57de3217c82d0c54e3dacaba6394245fec" }
tempfile = "3"
tokio = { version = "1", default-features = false, features = [
"rt",
Expand Down Expand Up @@ -77,12 +79,16 @@ path = "packages/std/lib.rs"
workspace = true

[dependencies]
bytes = { workspace = true }
futures = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
tangram_client = { workspace = true }
tangram_serialize = { workspace = true }
tempfile = { workspace = true }
tracing = { workspace = true, optional = true }
tracing-subscriber = { workspace = true, optional = true }

[features]
tracing = ["dep:tracing", "dep:tracing-subscriber"]
default = ["tracing"]
Binary file added packages/std/a.out
Binary file not shown.
11 changes: 10 additions & 1 deletion packages/std/bootstrap/make.tg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ export const source = () => {

export type Arg = {
host?: string;
embedWrapper?: boolean | undefined;
};

export const build = async (arg?: Arg) => {
const host = arg?.host ?? (await std.triple.host());
const embedWrapper = arg?.embedWrapper ?? true;

const configure = {
args: ["--disable-dependency-tracking"],
Expand All @@ -48,7 +50,14 @@ export const build = async (arg?: Arg) => {
install,
};

const env = std.env.arg(sdk(host), { utils: false });
let envArgs: Array<tg.Unresolved<std.env.Arg>> = [
sdk(host),
{ utils: false },
];
if (embedWrapper) {
envArgs.push({ TANGRAM_LINKER_EMBED_WRAPPER: true });
}
const env = std.env.arg(...envArgs);

const output = await autotoolsInternal({
bootstrap: true,
Expand Down
Binary file added packages/std/cctest/a.out
Binary file not shown.
58 changes: 58 additions & 0 deletions packages/std/cctest/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <elf.h>
#include <stdio.h>
#include <stdbool.h>
#include <sys/mman.h>

#define eprintf(...) fprintf(stderr, __VA_ARGS__)

int main(int argc, const char** argv) {
if (argc != 3) {
return 111;
}
const char* input = argv[0];
const char* output = argv[1];
int status = 0;

int in = open(input, O_RDONLY);
int out = open(output, O_RDWR | O_CREAT, 0o755);
if (in < 0 || out < 0) {
perror("failed to open in/out/files");
return 1;
}
off_t size = lseek(in, 0, SEEK_END);
if (size < 0) {
perror("failed to seek to the end of the input");
status = 1;
goto cleanup;
}

uint8_t* elf = (uint8_t*)mmap(
NULL,
(size_t)size,
PROT_READ,
MAP_ANONYMOUS | MAP_PRIVATE,
in,
0
);

Elf64_Ehdr* ehdr = (Elf64_Ehdr*)elf;
Elf64_Phdr* phdr = (Elf64_Phr*)(elf + ehdr->e_phoff);

bool copied = false
for (int i = 0; i < ehdr->e_phnum) {
if (phdr[i].p_type != PT_LOAD) {
continue;
}
if (copied) {
status = 1;
eprintf("expected a single loadable segment");
goto cleanup;
}

}
cleanup:
munmap(elf, size);
close(in);
close(out);
return status;
}
Binary file added packages/std/cctest/output.o
Binary file not shown.
7 changes: 7 additions & 0 deletions packages/std/cctest/script.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SECTIONS
{
. = 0x0;
.text : {
*(.text.start)
}
}
Binary file added packages/std/cctest/start.bin
Binary file not shown.
Binary file added packages/std/cctest/start.elf
Binary file not shown.
Binary file added packages/std/cctest/start.o
Binary file not shown.
8 changes: 8 additions & 0 deletions packages/std/cctest/start.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.section .text.start,"ax",@progbits
.global _start
.type _start, @function
_start:
mov x8, 93
mov x0, 42
svc #0
ret
13 changes: 13 additions & 0 deletions packages/std/file.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <stdio.h>
extern char** environ;
int main(int argc, const char** argv) {
for (int i = 0; i < 2; i++) {
const char* var = i ? "envp" : "argv";
const char** s = i ? (const char**)environ : argv;
int j = 0;
for (; *s; s++, j++) {
printf("%s[%d] = %s\n", var, j, *s);
}
}
return 0;
}
Binary file added packages/std/main
Binary file not shown.
20 changes: 20 additions & 0 deletions packages/std/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <sys/syscall.h>
#include <stdio.h>

int main() {
printf("__NR_write: %d\n", SYS_write);
// printf("__NR_open: %d\n", SYS_open);
printf("#define __NR_close =\t%d\n", SYS_close);
// printf("#define __NR_stat =\t%d\n", SYS_stat);
printf("#define __NR_lseek =\t%d\n", SYS_lseek);
printf("#define __NR_mmap =\t%d\n", SYS_mmap);
printf("#define __NR_munmap =\t%d\n", SYS_munmap);
printf("#define __NR_pread64 =\t%d\n", SYS_pread64);
printf("#define __NR_execve =\t%d\n", SYS_execve);
printf("#define __NR_exit =\t%d\n", SYS_exit);
printf("#define __NR_getcwd =\t%d\n", SYS_getcwd);
// print#define f("__NR_readlink =\t%d\n", SYS_readlink);
printf("#define __NR_getrlimit =\t%d\n", SYS_getrlimit);
printf("#define __NR_getrandom =\t%d\n", SYS_getrandom);
return 0;
}
Loading