Elf64_Dyn* dyns = (Elf64_Dyn*)x64->dynamic->data;
+ size_t prefix = strlen("../lib/x64/");
+
for (i = 0; i < x64->dyn_needs->size; i++) {
scf_string_t* needed = x64->dyn_needs->data[i];
dyns[i].d_tag = DT_NEEDED;
dyns[i].d_un.d_val = str->len;
- scf_string_cat_cstr_len(str, needed->data, needed->len + 1);
+ scf_logw("i: %d, %s, %s\n", i, needed->data, needed->data + prefix);
+
+ scf_string_cat_cstr_len(str, needed->data + prefix, needed->len - prefix + 1);
}
dyns[i].d_tag = DT_STRTAB;
static char* __sofiles[] =
{
- "/lib64/ld-linux-x86-64.so.2",
- "/lib/x86_64-linux-gnu/libc.so.6",
+ "../lib/x64//lib64/ld-linux-x86-64.so.2",
+ "../lib/x64/libc.so.6",
};
static char* __arm64_objs[] =
static char* __arm64_sofiles[] =
{
- "../lib/arm64/lib/ld-linux-aarch64.so.1",
- "../lib/arm64/lib/aarch64-linux-gnu/libc.so.6",
+ "../lib/arm64//lib/ld-linux-aarch64.so.1",
+ "../lib/arm64/libc.so.6",
};
void usage(char* path)
{
- fprintf(stderr, "Usage: %s [-c] [-a arch] src0 [src1] [-o out]\n\n", path);
+ fprintf(stderr, "Usage: %s [-c] [-a arch] [-o out] src0 [src1]\n\n", path);
fprintf(stderr, "-c: only compile, not link\n");
fprintf(stderr, "-a: select cpu arch (x64 or arm64), default is x64\n");
}
int main(int argc, char* argv[])
{
- int opt;
- int link = 1;
+ scf_vector_t* afiles = scf_vector_alloc();
+ scf_vector_t* sofiles = scf_vector_alloc();
+ scf_vector_t* srcs = scf_vector_alloc();
+ scf_vector_t* objs = scf_vector_alloc();
+
char* out = NULL;
char* arch = "x64";
+ int link = 1;
- while ((opt = getopt(argc, argv, "coa:")) != -1) {
- switch (opt) {
- case 'c':
+ int i;
+
+ for (i = 1; i < argc; i++) {
+
+ if ('-' == argv[i][0]) {
+
+ if ('c' == argv[i][1]) {
link = 0;
- break;
- case 'o':
- out = optarg;
- break;
- case 'a':
- arch = optarg;
- break;
- default:
- usage(argv[0]);
- break;
- }
- }
+ continue;
+ }
- if (optind >= argc) {
- usage(argv[0]);
- return -1;
- }
+ if ('a' == argv[i][1]) {
- scf_vector_t* afiles = scf_vector_alloc();
- scf_vector_t* sofiles = scf_vector_alloc();
- scf_vector_t* srcs = scf_vector_alloc();
- scf_vector_t* objs = scf_vector_alloc();
+ if (++i >= argc) {
+ usage(argv[0]);
+ return -EINVAL;
+ }
+
+ arch = argv[i];
+ continue;
+ }
+
+ if ('o' == argv[i][1]) {
- while (optind < argc) {
- char* fname = argv[optind];
+ if (++i >= argc) {
+ usage(argv[0]);
+ return -EINVAL;
+ }
+
+ out = argv[i];
+ continue;
+ }
+
+ usage(argv[0]);
+ return -EINVAL;
+ }
+
+ char* fname = argv[i];
size_t len = strlen(fname);
if (len < 3) {
return -1;
}
+ scf_loge("fname: %s\n", fname);
+
scf_vector_t* vec;
if (!strcmp(fname + len - 2, ".a"))
if (scf_vector_add(vec, fname) < 0)
return -ENOMEM;
-
- optind++;
}
scf_parse_t* parse = NULL;
return -1;
}
- int i;
for (i = 0; i < srcs->size; i++) {
char* file = srcs->data[i];
static const char* somaps[][3] =
{
- {"x64", "/lib/ld-linux-aarch64.so.1", "/lib64/ld-linux-x86-64.so.2"},
- {"x64", "/lib/aarch64-linux-gnu/libc.so.6", "/lib/x86_64-linux-gnu/libc.so.6"},
+ {"x64", "/lib/ld-linux-aarch64.so.1", "/lib64/ld-linux-x86-64.so.2"},
+ {"x64", "libc.so.6", "/lib/x86_64-linux-gnu/libc.so.6"},
};
typedef int (*dyn_func_pt)(uint64_t r0,