diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 0d78830bf435..79ffd3039e41 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -100,6 +100,12 @@ void LinkerDriver::main(ArrayRef ArgsArr) { opt::InputArgList Args = parseArgs(&Alloc, ArgsArr); createFiles(Args); + // Traditional linkers can generate re-linkable object files instead + // of executables or DSOs. We don't support that since the feature + // does not seem to provide more value than the static archiver. + if (Args.hasArg(OPT_relocatable)) + error("-r option is not supported. Use 'ar' command instead."); + switch (Config->EKind) { case ELF32LEKind: link(Args); diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td index 655c932241bd..8dbf4634a684 100644 --- a/lld/ELF/Options.td +++ b/lld/ELF/Options.td @@ -82,6 +82,8 @@ def o : Separate<["-"], "o">, MetaVarName<"">, def rpath : Separate<["-"], "rpath">, HelpText<"Add a DT_RUNPATH to the output">; +def relocatable : Flag<["--"], "relocatable">; + def script : Separate<["--"], "script">, HelpText<"Read linker script">; def shared : Flag<["-"], "shared">, @@ -123,6 +125,7 @@ def alias_init_init : Joined<["-"], "init=">, Alias; def alias_l__library : Joined<["--"], "library=">, Alias; def alias_o_output : Joined<["--"], "output=">, Alias; def alias_rpath_rpath : Joined<["-"], "rpath=">, Alias; +def alias_relocatable_r : Flag<["-"], "r">, Alias; def alias_shared_Bshareable : Flag<["-"], "Bshareable">, Alias; def alias_soname_h : Separate<["-"], "h">, Alias; def alias_soname_soname : Separate<["-"], "soname">, Alias; diff --git a/lld/test/elf2/relocatable.s b/lld/test/elf2/relocatable.s new file mode 100644 index 000000000000..1a2f89394331 --- /dev/null +++ b/lld/test/elf2/relocatable.s @@ -0,0 +1,9 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: not ld.lld2 -r %t -o %t2 2>&1 | FileCheck %s + +# CHECK: -r option is not supported. Use 'ar' command instead. + +.globl _start; +_start: