Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -442,6 +442,7 @@ unsigned readPhdrType(); void readProvide(bool Hidden); void readAlign(OutputSectionCommand *Cmd); + void readSort(); Expr readExpr(); Expr readExpr1(Expr Lhs, int MinPrec); @@ -701,6 +702,12 @@ expect(")"); } +void ScriptParser::readSort() { + expect("("); + expect("CONSTRUCTORS"); + expect(")"); +} + void ScriptParser::readOutputSectionDescription(StringRef OutSec) { OutputSectionCommand *Cmd = new OutputSectionCommand(OutSec); Opt.Commands.emplace_back(Cmd); @@ -736,6 +743,8 @@ readProvide(false); } else if (Tok == "PROVIDE_HIDDEN") { readProvide(true); + } else if (Tok == "SORT") { + readSort(); } else { setError("unknown command " + Tok); } Index: test/ELF/linkerscript/linkerscript-sort-constructors.s =================================================================== --- test/ELF/linkerscript/linkerscript-sort-constructors.s +++ test/ELF/linkerscript/linkerscript-sort-constructors.s @@ -0,0 +1,5 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o +# RUN: echo "SECTIONS { .aaa : { SORT(CONSTRUCTORS) } }" > %t1.script +# RUN: ld.lld -shared -o %t1 --script %t1.script %t1.o +# RUN: llvm-readobj %t1 > /dev/null