fix linker can't find libc.so.6 in fedora, and update the main()'s argv parser
authoryu.dongliang <18588496441@163.com>
Tue, 18 Apr 2023 07:33:41 +0000 (15:33 +0800)
committeryu.dongliang <18588496441@163.com>
Tue, 18 Apr 2023 07:33:41 +0000 (15:33 +0800)
elf/scf_elf_arm64_so.c
elf/scf_elf_naja_so.c
elf/scf_elf_x64_so.c
lib/arm64/libc.so.6 [moved from lib/arm64/lib/aarch64-linux-gnu/libc.so.6 with 100% similarity]
lib/x64/lib64/ld-linux-x86-64.so.2 [new file with mode: 0755]
lib/x64/libc.so.6 [new file with mode: 0755]
parse/main.c
vm/scf_vm_naja.c

index 6745089cb4602578b3c592153b06d97708e4b4be..59f687b607f5b62ab609137fc0ee7b10a2512037 100644 (file)
@@ -539,7 +539,7 @@ int __arm64_elf_add_dyn (elf_native_t* arm64)
 
        Elf64_Dyn* dyns = (Elf64_Dyn*)arm64->dynamic->data;
 
-       size_t prefix   = strlen("../lib/arm64");
+       size_t prefix   = strlen("../lib/arm64/");
 
        for (i = 0; i < arm64->dyn_needs->size; i++) {
                scf_string_t* needed = arm64->dyn_needs->data[i];
index 6e2fb8cbf944a50dca413e646bfed768d115d7a8..46471be6b9fd5877514401f1a55aae94ffab5314 100644 (file)
@@ -540,7 +540,7 @@ int __naja_elf_add_dyn (elf_native_t* naja)
 
        Elf64_Dyn* dyns = (Elf64_Dyn*)naja->dynamic->data;
 
-       size_t prefix   = strlen("../lib/arm64");
+       size_t prefix   = strlen("../lib/arm64/");
 
        for (i = 0; i < naja->dyn_needs->size; i++) {
                scf_string_t* needed = naja->dyn_needs->data[i];
index 2a92e9a85cb9790149ee73542bb4d5aff9b0f602..ab4f21df670da27ebd66bf45528a8d60417fcdf4 100644 (file)
@@ -543,13 +543,17 @@ int __x64_elf_add_dyn (elf_native_t* x64)
 
        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;
diff --git a/lib/x64/lib64/ld-linux-x86-64.so.2 b/lib/x64/lib64/ld-linux-x86-64.so.2
new file mode 100755 (executable)
index 0000000..a8cb029
Binary files /dev/null and b/lib/x64/lib64/ld-linux-x86-64.so.2 differ
diff --git a/lib/x64/libc.so.6 b/lib/x64/libc.so.6
new file mode 100755 (executable)
index 0000000..f5b26e3
Binary files /dev/null and b/lib/x64/libc.so.6 differ
index aae7583d7c79c421d82cab96693594431c75da65..2ee3400b2ecc9d8cda1adb5e6a12cdba001fdd3c 100644 (file)
@@ -12,8 +12,8 @@ static char* __objs[] =
 
 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[] =
@@ -23,53 +23,66 @@ 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) {
@@ -77,6 +90,8 @@ int main(int argc, char* argv[])
                        return -1;
                }
 
+               scf_loge("fname: %s\n", fname);
+
                scf_vector_t* vec;
 
                if (!strcmp(fname + len - 2, ".a"))
@@ -97,8 +112,6 @@ int main(int argc, char* argv[])
 
                if (scf_vector_add(vec, fname) < 0)
                        return -ENOMEM;
-
-               optind++;
        }
 
        scf_parse_t*  parse = NULL;
@@ -108,7 +121,6 @@ int main(int argc, char* argv[])
                return -1;
        }
 
-       int i;
        for (i = 0; i  < srcs->size; i++) {
                char* file = srcs->data[i];
 
index 1641d96ff99dcf36fb0e8da812987837e937e942..de0eb16da520f77e7813b4bc200b9fad0c3331dc 100644 (file)
@@ -2,8 +2,8 @@
 
 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,