Index: test/tools/gold/X86/code-model.ll =================================================================== --- /dev/null +++ test/tools/gold/X86/code-model.ll @@ -0,0 +1,24 @@ +; RUN: llvm-as %s -o %t.o + +; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \ +; RUN: -plugin-opt=-code-model=default -shared %t.o -o %t2.o +; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \ +; RUN: -plugin-opt=-code-model=small -shared %t.o -o %t2.o +; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \ +; RUN: -plugin-opt=-code-model=kernel -shared %t.o -o %t2.o +; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \ +; RUN: -plugin-opt=-code-model=medium -shared %t.o -o %t2.o +; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \ +; RUN: -plugin-opt=-code-model=large -shared %t.o -o %t2.o + +; RUN: not %gold -plugin %llvmshlibdir/LLVMgold.so \ +; RUN: --plugin-opt=-code-model=bad_model -shared %t.o -o %t2.o 2>&1 | \ +; RUN: FileCheck --check-prefix=BAD_MODEL %s +; BAD_MODEL: Cannot find option named 'bad_model'! + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target datalayout = "m:w" + +define void @f() { + ret void +} Index: tools/gold/gold-plugin.cpp =================================================================== --- tools/gold/gold-plugin.cpp +++ tools/gold/gold-plugin.cpp @@ -689,6 +689,7 @@ Conf.MAttrs = MAttrs; Conf.RelocModel = *RelocationModel; + Conf.CodeModel = CMModel; Conf.CGOptLevel = getCGOptLevel(); Conf.DisableVerify = options::DisableVerify; Conf.OptLevel = options::OptLevel; Index: tools/lld/ELF/LTO.cpp =================================================================== --- tools/lld/ELF/LTO.cpp +++ tools/lld/ELF/LTO.cpp @@ -73,6 +73,7 @@ Conf.Options.RelaxELFRelocations = true; Conf.RelocModel = Config->Pic ? Reloc::PIC_ : Reloc::Static; + Conf.CodeModel = GetCommandLineCodeModel(); Conf.DisableVerify = Config->DisableVerify; Conf.DiagHandler = diagnosticHandler; Conf.OptLevel = Config->LTOO; Index: tools/lld/include/lld/Core/TargetOptionsCommandFlags.h =================================================================== --- tools/lld/include/lld/Core/TargetOptionsCommandFlags.h +++ tools/lld/include/lld/Core/TargetOptionsCommandFlags.h @@ -11,8 +11,10 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Support/CodeGen.h" #include "llvm/Target/TargetOptions.h" namespace lld { llvm::TargetOptions InitTargetOptionsFromCodeGenFlags(); +llvm::CodeModel::Model GetCommandLineCodeModel(); } Index: tools/lld/lib/Core/TargetOptionsCommandFlags.cpp =================================================================== --- tools/lld/lib/Core/TargetOptionsCommandFlags.cpp +++ tools/lld/lib/Core/TargetOptionsCommandFlags.cpp @@ -26,3 +26,7 @@ llvm::TargetOptions lld::InitTargetOptionsFromCodeGenFlags() { return ::InitTargetOptionsFromCodeGenFlags(); } + +llvm::CodeModel::Model lld::GetCommandLineCodeModel() { + return CMModel; +} Index: tools/lld/test/ELF/code-model.s =================================================================== --- /dev/null +++ tools/lld/test/ELF/code-model.s @@ -0,0 +1,20 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t + +# RUN: ld.lld %t -mllvm -code-model=default -o %t2 +# RUN: ld.lld %t -mllvm -code-model=small -o %t2 +# RUN: ld.lld %t -mllvm -code-model=kernel -o %t2 +# RUN: ld.lld %t -mllvm -code-model=medium -o %t2 +# RUN: ld.lld %t -mllvm -code-model=large -o %t2 + +# RUN: not ld.lld %t -mllvm -code-model=bad_model -o %t2 2>&1 | \ +# RUN: FileCheck --check-prefix=BAD_MODEL %s +# BAD_MODEL: Cannot find option named 'bad_model'! + +.globl _start +_start: + mov $60, %rax + mov $37, %rdi + syscall +