Skip to content

Commit 84f569f

Browse files
committed
wip
1 parent b8fb86a commit 84f569f

File tree

5 files changed

+51
-240
lines changed

5 files changed

+51
-240
lines changed

packages/std/packages/ld_proxy/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ async fn create_wrapper(options: &Options) -> tg::Result<()> {
264264
tracing::debug!(?is_executable, ?interpreter, ?initial_needed_libraries);
265265

266266
// If the file is executable but does not need an interpreter, it is static or static-PIE linked. Abort here.
267-
if is_executable && matches!(interpreter, InterpreterRequirement::None) {
267+
if !options.embed && is_executable && matches!(interpreter, InterpreterRequirement::None) {
268268
tracing::info!("No interpreter needed for static executable. Exiting without wrapping.");
269269
return Ok(());
270270
}

packages/std/packages/stub/src/stub.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static void parse_options(Stack* stack, Options* options) {
7373
String TANGRAM_SUPPRESS_ARGS = STRING_LITERAL("TANGRAM_SUPPRESS_ARGS");
7474
String TANGRAM_SUPPRESS_ENV = STRING_LITERAL("TANGRAM_SUPPRESS_ENV");
7575
String TANGRAM_TRACING = STRING_LITERAL("TANGRAM_TRACING");
76-
76+
7777
char **itr, **end;
7878

7979
// Parse args.
@@ -609,7 +609,7 @@ static int read_and_process_manifest (
609609
if (!options->suppress_env) {
610610
for (int i = 0; i < stack->envc; i++) {
611611
char* e = stack->envp[i];
612-
612+
613613
// Find the length and midpoint of the env var.
614614
size_t n = 0;
615615
size_t m = 0;
@@ -629,7 +629,7 @@ static int read_and_process_manifest (
629629
key.ptr = ALLOC_N(arena, m + 1, uint8_t);
630630
key.len = m;
631631
memcpy(key.ptr, e, m);
632-
632+
633633
String val = {0};
634634
val.ptr = ALLOC_N(arena, n - m, uint8_t);
635635
val.len = n - m - 1;
@@ -774,15 +774,15 @@ void exec (Arena* arena, Manifest* manifest, char* argv0, Options* options) {
774774
// Sanity check.
775775
ABORT_IF(!manifest->executable.ptr, "missing executable");
776776
ABORT_IF(!argv0, "missing argv0");
777-
777+
778778
// Get the executable path.
779779
char* pathname = manifest->interpreter.ptr
780780
? cstr(arena, manifest->interpreter)
781781
: cstr(arena, manifest->executable);
782782

783783
// Compute argc.
784-
size_t argc = manifest->argc
785-
+ manifest->interp_argc
784+
size_t argc = manifest->argc
785+
+ manifest->interp_argc
786786
+ 1 // pathname
787787
+ 1 // --argv0
788788
+ 1 // argv[0]
@@ -792,7 +792,7 @@ void exec (Arena* arena, Manifest* manifest, char* argv0, Options* options) {
792792
// Create argv, envp
793793
char** argv = ALLOC_N(arena, argc + 1, char*);
794794
char** envp = ALLOC_N(arena, manifest->env.size + 1, char*);
795-
795+
796796
// Fill argv.
797797
size_t n = 0;
798798
argv[n++] = pathname;
@@ -870,13 +870,13 @@ void _stub_start (void *sp) {
870870

871871
if (options.enable_tracing) {
872872
trace(
873-
"options: enable_tracing:%d, suppress_args:%d, suppress_env:%d, loader_cli:%d\n",
873+
"options: enable_tracing:%d, suppress_args:%d, suppress_env:%d, loader_cli:%d\n",
874874
options.enable_tracing, options.suppress_args, options.suppress_env, options.loader_cli
875875
);
876876
trace("original stack:\n");
877877
print_stack(&stack);
878878
}
879-
879+
880880
// Check for reentrancy.
881881
if (stack.envc) {
882882
String tangram_entrypoint = STRING_LITERAL("TANGRAM_REENTRY=");
@@ -892,12 +892,11 @@ void _stub_start (void *sp) {
892892
trace("TANGRAM_REENTRY: %lx\n", original_entrypoint);
893893
}
894894
stack.envp[stack.envc] = "TANGRAM_REENTRY=0";
895-
BREAK;
896895
transfer_control(sp, (void*)original_entrypoint);
897896
}
898897
}
899898
}
900-
899+
901900
// We need to search the aux vector for the program header table and index of the entry point.
902901
Elf64_Phdr* phdr = (Elf64_Phdr*)stack.auxv_glob[AT_PHDR];
903902
uint64_t ph_num = (uint64_t)stack.auxv_glob[AT_PHNUM];
@@ -908,7 +907,7 @@ void _stub_start (void *sp) {
908907
if (options.enable_tracing) {
909908
trace("initialized arena\n");
910909
}
911-
910+
912911
// Search for the positions of AT_ENTRY, AT_BASE, AT_PHDR, AT_PHNUM
913912
int nentry = -1;
914913
int nbase = -1;
@@ -1004,7 +1003,7 @@ void _stub_start (void *sp) {
10041003
if (nbase >= 0) {
10051004
stack.auxv[nbase].a_un.a_val = loaded.base_address;
10061005
}
1007-
1006+
10081007
// Set the entrypoint as the interpreter.
10091008
entrypoint = (void*)(loaded.base_address + loaded.entry);
10101009

@@ -1055,6 +1054,6 @@ void _stub_start (void *sp) {
10551054
trace("about to transfer control\n");
10561055
trace("entrypoint: 0x%lx\n", (uintptr_t)entrypoint);
10571056
}
1058-
// BREAK;
1057+
10591058
transfer_control(sp, entrypoint);
10601059
}

packages/std/sdk.tg.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -910,13 +910,14 @@ export namespace sdk {
910910
}
911911

912912
tg.assert(metadata.format === "elf");
913-
const expectedInterpreter = libc.interpreterName(expectedTarget);
914-
const actualInterpreter = metadata.interpreter;
915-
tg.assert(actualInterpreter, "File should have been dynamically linked.");
916-
tg.assert(
917-
actualInterpreter.includes(expectedInterpreter),
918-
`Expected interpreter named ${expectedInterpreter} but got ${actualInterpreter}.`,
919-
);
913+
// const expectedInterpreter = libc.interpreterName(expectedTarget);
914+
// const actualInterpreter = metadata.interpreter;
915+
916+
// tg.assert(actualInterpreter, "File should have been dynamically linked.");
917+
// tg.assert(
918+
// actualInterpreter.includes(expectedInterpreter),
919+
// `Expected interpreter named ${expectedInterpreter} but got ${actualInterpreter}.`,
920+
// );
920921
} else if (metadata.format === "mach-o") {
921922
tg.assert(metadata.arches.includes(expectedArch as string));
922923
} else {

packages/std/sdk/gnu/toolchain.tg.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ export const canadianCross = async (arg?: CanadianCrossArg) => {
135135
});
136136

137137
// Build a fully native GCC toolchain.
138-
const nativeGcc = gcc.build({
138+
const nativeGcc = tg.build(gcc.build, {
139139
bootstrap: true,
140140
build: host,
141141
bundledSources: true, // Build gmp/isl/mpfr/mpc inline
142142
crossNative: true, // Include workaround for configuring target libraries with an unproxied compiler.
143-
env: stage1HostSdk,
143+
env: std.env.arg (stage1HostSdk),
144144
host,
145145
sysroot,
146146
target,
@@ -229,7 +229,7 @@ export const crossToolchain = async (arg: tg.Unresolved<CrossToolchainArg>) => {
229229
});
230230

231231
// Produce a toolchain containing the sysroot and a cross-compiler.
232-
const crossGcc = await gcc.build({
232+
const crossGcc = await tg.build(gcc.build, {
233233
bootstrap: true,
234234
build: buildTriple,
235235
env: buildEnv,
@@ -300,7 +300,7 @@ export const buildSysroot = async (arg: tg.Unresolved<BuildSysrootArg>) => {
300300
});
301301

302302
// Produce the initial gcc required to build the standard C library.
303-
const initialGccDir = await gcc.build({
303+
const initialGccDir = await tg.build(gcc.build, {
304304
bootstrap: true,
305305
build: buildTriple,
306306
env: buildEnv,

0 commit comments

Comments
 (0)