diff --git a/src/build/config/compiler/BUILD.gn b/src/build/config/compiler/BUILD.gn index 5391a83edf..62e80c786b 100644 --- a/src/build/config/compiler/BUILD.gn +++ b/src/build/config/compiler/BUILD.gn @@ -143,6 +143,8 @@ declare_args() { # This allows to make behavior of uninitialized memory bugs consistent, easier to # recognize when debugging and often just to crash immediately. init_stack_vars = false + + is_openwrt = false } declare_args() { @@ -576,6 +578,11 @@ config("compiler") { ldflags += [ "-stdlib=libc++" ] } + if (is_openwrt && current_cpu == target_cpu) { + defines += [ "_LIBCPP_HAS_MUSL_LIBC", "__UCLIBC__" ] + libs = [ "atomic" ] + } + # Add flags for link-time optimization. These flags enable # optimizations/transformations that require whole-program visibility at link # time, so they need to be applied to all translation units, and we may end up @@ -779,6 +786,9 @@ config("compiler_cpu_abi") { if (is_android) { cflags += [ "--target=mipsel-linux-android" ] ldflags += [ "--target=mipsel-linux-android" ] + } else if (is_openwrt) { + cflags += [ "--target=mipsel-openwrt-linux-musl" ] + ldflags += [ "--target=mipsel-openwrt-linux-musl" ] } else { cflags += [ "--target=mipsel-linux-gnu" ] ldflags += [ "--target=mipsel-linux-gnu" ] @@ -861,8 +871,13 @@ config("compiler_cpu_abi") { ldflags += [ "-Wl,--hash-style=sysv" ] if (custom_toolchain == "") { if (is_clang) { - cflags += [ "--target=mips-linux-gnu" ] - ldflags += [ "--target=mips-linux-gnu" ] + if (is_openwrt) { + cflags += [ "--target=mips-openwrt-linux-musl" ] + ldflags += [ "--target=mips-openwrt-linux-musl" ] + } else { + cflags += [ "--target=mips-linux-gnu" ] + ldflags += [ "--target=mips-linux-gnu" ] + } } else { cflags += [ "-EB" ] ldflags += [ "-EB" ] @@ -910,6 +925,9 @@ config("compiler_cpu_abi") { if (is_android) { cflags += [ "--target=mips64el-linux-android" ] ldflags += [ "--target=mips64el-linux-android" ] + } else if (is_openwrt) { + cflags += [ "--target=mips64el-openwrt-linux-musl" ] + ldflags += [ "--target=mips64el-openwrt-linux-musl" ] } else { cflags += [ "--target=mips64el-linux-gnuabi64" ] ldflags += [ "--target=mips64el-linux-gnuabi64" ] @@ -970,8 +988,13 @@ config("compiler_cpu_abi") { ldflags += [ "-Wl,--hash-style=sysv" ] if (custom_toolchain == "") { if (is_clang) { - cflags += [ "--target=mips64-linux-gnuabi64" ] - ldflags += [ "--target=mips64-linux-gnuabi64" ] + if (is_openwrt) { + cflags += [ "--target=mips64-openwrt-linux-musl" ] + ldflags += [ "--target=mips64-openwrt-linux-musl" ] + } else { + cflags += [ "--target=mips64-linux-gnuabi64" ] + ldflags += [ "--target=mips64-linux-gnuabi64" ] + } } else { cflags += [ "-EB", diff --git a/src/build/config/gcc/BUILD.gn b/src/build/config/gcc/BUILD.gn index 747245f376..6c0a1a431c 100644 --- a/src/build/config/gcc/BUILD.gn +++ b/src/build/config/gcc/BUILD.gn @@ -108,6 +108,11 @@ config("executable_config") { "-Wl,--disable-new-dtags", ] } + + # Needed for non-standard ldso on OpenWRT + if (ldso_path != "" && current_cpu == target_cpu) { + ldflags += [ "-Wl,--dynamic-linker=${ldso_path}" ] + } } # Settings for shared libraries.