diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -1012,6 +1012,14 @@ if (config->splitStackAdjustSize < 0) error("--split-stack-adjust-size: size must be >= 0"); + // The text segment is traditionally the first segment, whose address equals + // the base address. However, lld places the R PT_LOAD first. -Ttext-segment + // is an old-fashioned option that does not play well with lld's layout. + // Suggest --image-base as a likely alternative. + if (args.hasArg(OPT_Ttext_segment)) + error("-Ttext-segment is not supported. Use --image-base if you " + "intend to set the base address"); + // Parse ELF{32,64}{LE,BE} and CPU type. if (auto *arg = args.getLastArg(OPT_m)) { StringRef s = arg->getValue(); diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td --- a/lld/ELF/Options.td +++ b/lld/ELF/Options.td @@ -59,6 +59,8 @@ defm Ttext: Eq<"Ttext", "Same as --section-start with .text as the sectionname">; +def Ttext_segment: Separate<["-", "--"], "Ttext-segment">; + defm allow_multiple_definition: B<"allow-multiple-definition", "Allow multiple definitions", "Do not allow multiple definitions (default)">; @@ -462,9 +464,8 @@ def: Flag<["-"], "s">, Alias, HelpText<"Alias for --strip-all">; def: Flag<["-"], "S">, Alias, HelpText<"Alias for --strip-debug">; def: Flag<["-"], "t">, Alias, HelpText<"Alias for --trace">; +def: Joined<["-", "--"], "Ttext-segment=">, Alias; def: JoinedOrSeparate<["-"], "y">, Alias, HelpText<"Alias for --trace-symbol">; -def: Separate<["-", "--"], "Ttext-segment">, Alias, HelpText<"Alias for --Ttext">; -def: Joined<["-", "--"], "Ttext-segment=">, Alias, HelpText<"Alias for --Ttext">; def: JoinedOrSeparate<["-"], "u">, Alias, HelpText<"Alias for --undefined">; def: Flag<["-"], "V">, Alias, HelpText<"Alias for --version">; diff --git a/lld/test/ELF/sectionstart.s b/lld/test/ELF/sectionstart.s --- a/lld/test/ELF/sectionstart.s +++ b/lld/test/ELF/sectionstart.s @@ -20,12 +20,6 @@ # RUN: ld.lld %t.o -Ttext=0x100000 -Tdata=0x110000 -Tbss=0x200000 -o %t4 # RUN: llvm-objdump -section-headers %t4 | FileCheck %s -## Check Ttext-segment X and Ttext-segment=X forms. -# RUN: ld.lld %t.o -Ttext-segment=0x100000 -Tdata=0x110000 -Tbss=0x200000 -o %t4 -# RUN: llvm-objdump -section-headers %t4 | FileCheck %s -# RUN: ld.lld %t.o -Ttext-segment 0x100000 -Tdata=0x110000 -Tbss=0x200000 -o %t4 -# RUN: llvm-objdump -section-headers %t4 | FileCheck %s - ## The same, but dropped "0x" prefix. # RUN: ld.lld %t.o -Ttext=100000 -Tdata=110000 -Tbss=200000 -o %t5 # RUN: llvm-objdump -section-headers %t5 | FileCheck %s diff --git a/lld/test/ELF/ttext-segment.s b/lld/test/ELF/ttext-segment.s new file mode 100644 --- /dev/null +++ b/lld/test/ELF/ttext-segment.s @@ -0,0 +1,8 @@ +# REQUIRES: x86 +## Check that we emit an error for -Ttext-segment. + +# RUN: llvm-mc -filetype=obj -triple=x86_64 /dev/null -o %t.o +# RUN: not ld.lld %t.o -Ttext-segment=0x100000 -o /dev/null 2>&1 | FileCheck %s +# RUN: not ld.lld %t.o -Ttext-segment 0x100000 -o /dev/null 2>&1 | FileCheck %s + +# CHECK: error: -Ttext-segment is not supported. Use --image-base if you intend to set the base address