diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp b/clang/lib/Driver/ToolChains/OpenBSD.cpp --- a/clang/lib/Driver/ToolChains/OpenBSD.cpp +++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp @@ -160,7 +160,8 @@ assert(Output.isNothing() && "Invalid output."); } - if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) { + if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, + options::OPT_r)) { const char *crt0 = nullptr; const char *crtbegin = nullptr; if (!Args.hasArg(options::OPT_shared)) { @@ -191,7 +192,8 @@ bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs); AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA); - if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { + if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs, + options::OPT_r)) { // Use the static OpenMP runtime with -static-openmp bool StaticOpenMP = Args.hasArg(options::OPT_static_openmp) && !Args.hasArg(options::OPT_static); @@ -234,7 +236,8 @@ CmdArgs.push_back("-lcompiler_rt"); } - if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) { + if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, + options::OPT_r)) { const char *crtend = nullptr; if (!Args.hasArg(options::OPT_shared)) crtend = "crtend.o"; diff --git a/clang/test/Driver/openbsd.c b/clang/test/Driver/openbsd.c --- a/clang/test/Driver/openbsd.c +++ b/clang/test/Driver/openbsd.c @@ -40,8 +40,9 @@ // RUN: | FileCheck --check-prefix=CHECK-MIPS64-LD %s // RUN: %clang -no-canonical-prefixes -target mips64el-unknown-openbsd %s -### 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-MIPS64EL-LD %s -// CHECK-LD-R: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd" -// CHECK-LD-R: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-r" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" "{{.*}}crtend.o" +// CHECK-LD-R: "-r" +// CHECK-LD-R-NOT: "-l +// CHECK-LD-R-NOT: crt{{[^.]+}}.o // CHECK-LD-S: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd" // CHECK-LD-S: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-s" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" "{{.*}}crtend.o" // CHECK-LD-T: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd"