| ... | @@ -32,6 +32,7 @@ static CodeGen *create_child_codegen(CodeGen *parent_gen, Buf *root_src_path, Ou | ... | @@ -32,6 +32,7 @@ static CodeGen *create_child_codegen(CodeGen *parent_gen, Buf *root_src_path, Ou |
| 32 | child_gen->verbose_llvm_ir = parent_gen->verbose_llvm_ir; | 32 | child_gen->verbose_llvm_ir = parent_gen->verbose_llvm_ir; |
| 33 | child_gen->verbose_cimport = parent_gen->verbose_cimport; | 33 | child_gen->verbose_cimport = parent_gen->verbose_cimport; |
| 34 | child_gen->verbose_cc = parent_gen->verbose_cc; | 34 | child_gen->verbose_cc = parent_gen->verbose_cc; |
| | 35 | child_gen->llvm_argv = parent_gen->llvm_argv; |
| 35 | | 36 | |
| 36 | codegen_set_strip(child_gen, parent_gen->strip_debug_symbols); | 37 | codegen_set_strip(child_gen, parent_gen->strip_debug_symbols); |
| 37 | child_gen->disable_pic = parent_gen->disable_pic; | 38 | child_gen->disable_pic = parent_gen->disable_pic; |
| ... | @@ -161,6 +162,7 @@ static void glibc_add_include_dirs_arch(CFile *c_file, ZigLLVM_ArchType arch, co | ... | @@ -161,6 +162,7 @@ static void glibc_add_include_dirs_arch(CFile *c_file, ZigLLVM_ArchType arch, co |
| 161 | bool is_arm = arch == ZigLLVM_arm || arch == ZigLLVM_armeb; | 162 | bool is_arm = arch == ZigLLVM_arm || arch == ZigLLVM_armeb; |
| 162 | bool is_ppc = arch == ZigLLVM_ppc || arch == ZigLLVM_ppc64 || arch == ZigLLVM_ppc64le; | 163 | bool is_ppc = arch == ZigLLVM_ppc || arch == ZigLLVM_ppc64 || arch == ZigLLVM_ppc64le; |
| 163 | bool is_riscv = arch == ZigLLVM_riscv32 || arch == ZigLLVM_riscv64; | 164 | bool is_riscv = arch == ZigLLVM_riscv32 || arch == ZigLLVM_riscv64; |
| | 165 | bool is_sparc = arch == ZigLLVM_sparc || arch == ZigLLVM_sparcel || arch == ZigLLVM_sparcv9; |
| 164 | bool is_64 = target_arch_pointer_bit_width(arch) == 64; | 166 | bool is_64 = target_arch_pointer_bit_width(arch) == 64; |
| 165 | | 167 | |
| 166 | if (is_x86) { | 168 | if (is_x86) { |
| ... | @@ -195,14 +197,29 @@ static void glibc_add_include_dirs_arch(CFile *c_file, ZigLLVM_ArchType arch, co | ... | @@ -195,14 +197,29 @@ static void glibc_add_include_dirs_arch(CFile *c_file, ZigLLVM_ArchType arch, co |
| 195 | } else { | 197 | } else { |
| 196 | if (is_64) { | 198 | if (is_64) { |
| 197 | c_file->args.append("-I"); | 199 | c_file->args.append("-I"); |
| 198 | c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "mips64", dir))); | 200 | c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "mips" OS_SEP "mips64", dir))); |
| 199 | } else { | 201 | } else { |
| 200 | c_file->args.append("-I"); | 202 | c_file->args.append("-I"); |
| 201 | c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "mips32", dir))); | 203 | c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "mips" OS_SEP "mips32", dir))); |
| 202 | } | 204 | } |
| 203 | c_file->args.append("-I"); | 205 | c_file->args.append("-I"); |
| 204 | c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "mips", dir))); | 206 | c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "mips", dir))); |
| 205 | } | 207 | } |
| | 208 | } else if (is_sparc) { |
| | 209 | if (nptl != nullptr) { |
| | 210 | c_file->args.append("-I"); |
| | 211 | c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "sparc" OS_SEP "%s", dir, nptl))); |
| | 212 | } else { |
| | 213 | if (is_64) { |
| | 214 | c_file->args.append("-I"); |
| | 215 | c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "sparc" OS_SEP "sparc64", dir))); |
| | 216 | } else { |
| | 217 | c_file->args.append("-I"); |
| | 218 | c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "sparc" OS_SEP "sparc32", dir))); |
| | 219 | } |
| | 220 | c_file->args.append("-I"); |
| | 221 | c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "sparc", dir))); |
| | 222 | } |
| 206 | } else if (is_aarch64) { | 223 | } else if (is_aarch64) { |
| 207 | if (nptl != nullptr) { | 224 | if (nptl != nullptr) { |
| 208 | c_file->args.append("-I"); | 225 | c_file->args.append("-I"); |
| ... | @@ -218,10 +235,10 @@ static void glibc_add_include_dirs_arch(CFile *c_file, ZigLLVM_ArchType arch, co | ... | @@ -218,10 +235,10 @@ static void glibc_add_include_dirs_arch(CFile *c_file, ZigLLVM_ArchType arch, co |
| 218 | } else { | 235 | } else { |
| 219 | if (is_64) { | 236 | if (is_64) { |
| 220 | c_file->args.append("-I"); | 237 | c_file->args.append("-I"); |
| 221 | c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "powerpc64", dir))); | 238 | c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "powerpc" OS_SEP "powerpc64", dir))); |
| 222 | } else { | 239 | } else { |
| 223 | c_file->args.append("-I"); | 240 | c_file->args.append("-I"); |
| 224 | c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "powerpc32", dir))); | 241 | c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "powerpc" OS_SEP "powerpc32", dir))); |
| 225 | } | 242 | } |
| 226 | c_file->args.append("-I"); | 243 | c_file->args.append("-I"); |
| 227 | c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "powerpc", dir))); | 244 | c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "powerpc", dir))); |
| ... | @@ -288,11 +305,59 @@ static void glibc_add_include_dirs(CodeGen *parent, CFile *c_file) { | ... | @@ -288,11 +305,59 @@ static void glibc_add_include_dirs(CodeGen *parent, CFile *c_file) { |
| 288 | c_file->args.append(path_from_libc(parent, "glibc")); | 305 | c_file->args.append(path_from_libc(parent, "glibc")); |
| 289 | } | 306 | } |
| 290 | | 307 | |
| | 308 | static const char *glibc_start_asm_path(CodeGen *parent, const char *file) { |
| | 309 | ZigLLVM_ArchType arch = parent->zig_target->arch; |
| | 310 | bool is_aarch64 = arch == ZigLLVM_aarch64 || arch == ZigLLVM_aarch64_be; |
| | 311 | bool is_mips = arch == ZigLLVM_mips || arch == ZigLLVM_mipsel || |
| | 312 | arch == ZigLLVM_mips64el || arch == ZigLLVM_mips64; |
| | 313 | bool is_arm = arch == ZigLLVM_arm || arch == ZigLLVM_armeb; |
| | 314 | bool is_ppc = arch == ZigLLVM_ppc || arch == ZigLLVM_ppc64 || arch == ZigLLVM_ppc64le; |
| | 315 | bool is_riscv = arch == ZigLLVM_riscv32 || arch == ZigLLVM_riscv64; |
| | 316 | bool is_sparc = arch == ZigLLVM_sparc || arch == ZigLLVM_sparcel || arch == ZigLLVM_sparcv9; |
| | 317 | bool is_64 = target_arch_pointer_bit_width(arch) == 64; |
| | 318 | |
| | 319 | Buf result = BUF_INIT; |
| | 320 | buf_resize(&result, 0); |
| | 321 | buf_append_buf(&result, parent->zig_lib_dir); |
| | 322 | buf_append_str(&result, OS_SEP "libc" OS_SEP "glibc" OS_SEP "sysdeps" OS_SEP); |
| | 323 | if (arch == ZigLLVM_nios2) { |
| | 324 | buf_append_str(&result, "nios2"); |
| | 325 | } else if (is_sparc) { |
| | 326 | if (is_64) { |
| | 327 | buf_append_str(&result, "sparc" OS_SEP "sparc64"); |
| | 328 | } else { |
| | 329 | buf_append_str(&result, "sparc" OS_SEP "sparc32"); |
| | 330 | } |
| | 331 | } else if (is_arm) { |
| | 332 | buf_append_str(&result, "arm"); |
| | 333 | } else if (is_mips) { |
| | 334 | buf_append_str(&result, "mips"); |
| | 335 | } else if (arch == ZigLLVM_x86_64) { |
| | 336 | buf_append_str(&result, "x86_64"); |
| | 337 | } else if (arch == ZigLLVM_x86) { |
| | 338 | buf_append_str(&result, "i386"); |
| | 339 | } else if (is_aarch64) { |
| | 340 | buf_append_str(&result, "aarch64"); |
| | 341 | } else if (is_riscv) { |
| | 342 | buf_append_str(&result, "riscv"); |
| | 343 | } else if (is_ppc) { |
| | 344 | if (is_64) { |
| | 345 | buf_append_str(&result, "powerpc" OS_SEP "powerpc64"); |
| | 346 | } else { |
| | 347 | buf_append_str(&result, "powerpc" OS_SEP "powerpc32"); |
| | 348 | } |
| | 349 | } |
| | 350 | |
| | 351 | buf_append_str(&result, OS_SEP); |
| | 352 | buf_append_str(&result, file); |
| | 353 | return buf_ptr(&result); |
| | 354 | } |
| | 355 | |
| 291 | static const char *get_libc_crt_file(CodeGen *parent, const char *file) { | 356 | static const char *get_libc_crt_file(CodeGen *parent, const char *file) { |
| 292 | if (parent->libc == nullptr && target_is_glibc(parent)) { | 357 | if (parent->libc == nullptr && target_is_glibc(parent)) { |
| 293 | if (strcmp(file, "crti.o") == 0) { | 358 | if (strcmp(file, "crti.o") == 0) { |
| 294 | CFile *c_file = allocate<CFile>(1); | 359 | CFile *c_file = allocate<CFile>(1); |
| 295 | c_file->source_path = path_from_libc(parent, "glibc" OS_SEP "sysdeps" OS_SEP "x86_64" OS_SEP "crti.S"); | 360 | c_file->source_path = glibc_start_asm_path(parent, "crti.S"); |
| 296 | glibc_add_include_dirs(parent, c_file); | 361 | glibc_add_include_dirs(parent, c_file); |
| 297 | c_file->args.append("-D_LIBC_REENTRANT"); | 362 | c_file->args.append("-D_LIBC_REENTRANT"); |
| 298 | c_file->args.append("-include"); | 363 | c_file->args.append("-include"); |
| ... | @@ -314,7 +379,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) { | ... | @@ -314,7 +379,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) { |
| 314 | return build_libc_object(parent, "crti", c_file); | 379 | return build_libc_object(parent, "crti", c_file); |
| 315 | } else if (strcmp(file, "crtn.o") == 0) { | 380 | } else if (strcmp(file, "crtn.o") == 0) { |
| 316 | CFile *c_file = allocate<CFile>(1); | 381 | CFile *c_file = allocate<CFile>(1); |
| 317 | c_file->source_path = path_from_libc(parent, "glibc" OS_SEP "sysdeps" OS_SEP "x86_64" OS_SEP "crtn.S"); | 382 | c_file->source_path = glibc_start_asm_path(parent, "crtn.S"); |
| 318 | glibc_add_include_dirs(parent, c_file); | 383 | glibc_add_include_dirs(parent, c_file); |
| 319 | c_file->args.append("-D_LIBC_REENTRANT"); | 384 | c_file->args.append("-D_LIBC_REENTRANT"); |
| 320 | c_file->args.append("-DMODULE_NAME=libc"); | 385 | c_file->args.append("-DMODULE_NAME=libc"); |
| ... | @@ -325,7 +390,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) { | ... | @@ -325,7 +390,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) { |
| 325 | return build_libc_object(parent, "crtn", c_file); | 390 | return build_libc_object(parent, "crtn", c_file); |
| 326 | } else if (strcmp(file, "start.os") == 0) { | 391 | } else if (strcmp(file, "start.os") == 0) { |
| 327 | CFile *c_file = allocate<CFile>(1); | 392 | CFile *c_file = allocate<CFile>(1); |
| 328 | c_file->source_path = path_from_libc(parent, "glibc" OS_SEP "sysdeps" OS_SEP "x86_64" OS_SEP "start.S"); | 393 | c_file->source_path = glibc_start_asm_path(parent, "start.S"); |
| 329 | glibc_add_include_dirs(parent, c_file); | 394 | glibc_add_include_dirs(parent, c_file); |
| 330 | c_file->args.append("-D_LIBC_REENTRANT"); | 395 | c_file->args.append("-D_LIBC_REENTRANT"); |
| 331 | c_file->args.append("-include"); | 396 | c_file->args.append("-include"); |