Skip to content

Commit 83e5de0

Browse files
committed
working aarch64
1 parent 3977253 commit 83e5de0

File tree

3 files changed

+95
-11
lines changed

3 files changed

+95
-11
lines changed

packages/std/packages/std/manifest.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,17 @@ impl Manifest {
305305
.as_ref()
306306
.ok_or_else(|| tg::error!("expected a wrap binary"))?;
307307

308-
tg::cache::cache(tg, tg::cache::Arg {
309-
artifacts: vec![file.id().into(), stub_bin.id().into(), stub_elf.id().into(), wrap.id().into()]
310-
})
308+
tg::cache::cache(
309+
tg,
310+
tg::cache::Arg {
311+
artifacts: vec![
312+
file.id().into(),
313+
stub_bin.id().into(),
314+
stub_elf.id().into(),
315+
wrap.id().into(),
316+
],
317+
},
318+
)
311319
.await
312320
.map_err(|source| tg::error!(!source, "failed to cache artifacts"))?;
313321

@@ -317,9 +325,10 @@ impl Manifest {
317325
let stub_bin = path.join(stub_bin.id().to_string());
318326
let stub_elf = path.join(stub_elf.id().to_string());
319327
let wrap = path.join(wrap.id().to_string());
320-
328+
321329
// Create a temp file for the manifest.
322-
let mut manifest = tempfile::NamedTempFile::new().map_err(|source| tg::error!(!source, "failed to get temp file"))?;
330+
let mut manifest = tempfile::NamedTempFile::new()
331+
.map_err(|source| tg::error!(!source, "failed to get temp file"))?;
323332

324333
// Create a random output name.
325334
let tempfile = tempfile::NamedTempFile::new()
@@ -329,7 +338,10 @@ impl Manifest {
329338
// Create the manifest file. TODO: asyncify.
330339
let contents = serde_json::to_vec(self)
331340
.map_err(|source| tg::error!(!source, "failed to serialize manifest"))?;
332-
manifest.as_file_mut().write_all(&contents).map_err(|source| tg::error!(!source, "failed to write manifest"))?;
341+
manifest
342+
.as_file_mut()
343+
.write_all(&contents)
344+
.map_err(|source| tg::error!(!source, "failed to write manifest"))?;
333345

334346
// Run the command.
335347
let success = std::process::Command::new(wrap)
@@ -348,10 +360,14 @@ impl Manifest {
348360
return Err(tg::error!("failed to run the command"));
349361
}
350362

351-
let bytes = std::fs::read(output).map_err(|source| tg::error!(!source, "failed to read the output"))?;
352-
std::fs::remove_file(output).map_err(|source| tg::error!(!source, "failed to remove output file"))?;
363+
let bytes = std::fs::read(output)
364+
.map_err(|source| tg::error!(!source, "failed to read the output"))?;
365+
std::fs::remove_file(output)
366+
.map_err(|source| tg::error!(!source, "failed to remove output file"))?;
353367
let cursor = std::io::Cursor::new(bytes);
354-
let blob = tg::Blob::with_reader(tg, cursor).await.map_err(|source| tg::error!(!source, "failed to create blob"))?;
368+
let blob = tg::Blob::with_reader(tg, cursor)
369+
.await
370+
.map_err(|source| tg::error!(!source, "failed to create blob"))?;
355371

356372
// Obtain the dependencies from the manifest to add to the file.
357373
// NOTE: We know the wrapper file has no dependencies, so there is no need to merge.
@@ -637,7 +653,6 @@ static TANGRAM_WRAPPER: LazyLock<tg::File> = LazyLock::new(|| {
637653
tg::File::with_id(id)
638654
});
639655

640-
641656
static TANGRAM_STUB_BIN: LazyLock<Option<tg::File>> = LazyLock::new(|| {
642657
std::env::var("TANGRAM_STUB_BIN_ID").ok().map(|id| {
643658
let id = id.parse().expect("TANGRAM_STUB_BIN_ID is not a valid ID");
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
gcc appears to have an issue with some functions (memset and memcpy) on some architectures (aarch64) which forbids overriding them in a static function declaration within a single header file. In addition, conversion
3+
of long doubles to doubles is a built-in provided by lib-gcc on aarch64.
4+
5+
We don't care about any of that, so this source file works around it.
6+
*/
7+
#include <stddef.h>
8+
#include <stdint.h>
9+
10+
#ifdef __x86_64__
11+
__attribute__((naked))
12+
static void* memcpy (
13+
void* dst,
14+
const void* src,
15+
size_t len
16+
) {
17+
asm volatile (
18+
"rep rex.w movsb;"
19+
"ret;"
20+
: "+D"(dst), "+S"(src), "+c"(len)
21+
:
22+
: "memory", "cc"
23+
);
24+
}
25+
26+
__attribute__((naked))
27+
void* memset (
28+
void* dst,
29+
int c,
30+
size_t n
31+
) {
32+
asm volatile (
33+
"rep rex.w stosb;"
34+
"ret;"
35+
: "+D"(dst), "+c"(n)
36+
: "a"(c)
37+
: "memory", "cc"
38+
);
39+
}
40+
#endif
41+
42+
#ifdef __aarch64__
43+
#include "syscall.h"
44+
double __trunctfdf2 (long double ld) {
45+
exit(111);
46+
return 0.0;
47+
}
48+
49+
void* memcpy (
50+
void* dst,
51+
const void* src,
52+
size_t len
53+
) {
54+
for (size_t i = 0; i < len; i++) {
55+
((uint8_t*)dst)[i] = ((const uint8_t*)src)[i];
56+
}
57+
}
58+
59+
void* memset (
60+
void* dst,
61+
int c,
62+
size_t n
63+
) {
64+
for (size_t i = 0; i < n; i++) {
65+
((uint8_t*)dst)[i] = (uint8_t)(c);
66+
}
67+
return dst;
68+
}
69+
#endif

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void file_concat (File* dst, File src) {
112112
bytes_read += n;
113113
ssize_t offset = 0;
114114
while (offset < n) {
115-
ssize_t m = write(dst->fd, buf + offset, sizeof(buf) - offset);
115+
ssize_t m = write(dst->fd, buf + offset, n - offset);
116116
ABORT_IF(m < 0, "failed to write to %s", dst->path);
117117
offset += m;
118118
}

0 commit comments

Comments
 (0)