@@ -69,6 +69,13 @@ struct LinkerCLOptions : public LinkerOptions {
6969 }
7070 StringRef outputSplitMarker () const { return outputSplitMarkerFlag; }
7171
72+ // / Sort symbols in the output module.
73+ LinkerCLOptions &sortSymbols (bool sort) {
74+ sortSymbolsFlag = sort;
75+ return *this ;
76+ }
77+ bool shouldSortSymbols () const { return sortSymbolsFlag; }
78+
7279 // / Creates and initializes a LinkerOptions from command line options.
7380 // / These options are static but use ExternalStorage to initialize the
7481 // / members of the LinkerOptions class.
@@ -104,6 +111,10 @@ struct LinkerCLOptions : public LinkerOptions {
104111 }),
105112 cl::location (splitInputFileFlag), cl::init (" " ), cl::cat (getCategory ()));
106113
114+ static cl::opt<bool , /* ExternalStorage=*/ true > clSortSymbols (
115+ " sort-symbols" , cl::desc (" Sort symbols in the output module" ),
116+ cl::location (sortSymbolsFlag), cl::init (false ), cl::cat (getCategory ()));
117+
107118 static cl::opt<std::string, /* ExternalStorage=*/ true > clOutputSplitMarker (
108119 " output-split-marker" ,
109120 cl::desc (" Split marker to use for merging the ouput" ),
@@ -136,6 +147,9 @@ struct LinkerCLOptions : public LinkerOptions {
136147 // / Show the registered dialects before trying to load the input file.
137148 bool showDialectsFlag = false ;
138149
150+ // / Sort symbols in the output module.
151+ bool sortSymbolsFlag = false ;
152+
139153 // / Split the input file based on the given marker into chunks and process
140154 // / each chunk independently. Input is not split if empty.
141155 std::string splitInputFileFlag = " " ;
@@ -265,7 +279,7 @@ LogicalResult mlir::MlirLinkMain(int argc, char **argv,
265279 if (failed (proc.linkFiles (options.inputFiles )))
266280 return failure ();
267281
268- OwningOpRef<ModuleOp> composite = linker.link ();
282+ OwningOpRef<ModuleOp> composite = linker.link (options. shouldSortSymbols () );
269283 if (failed (verify (composite.get (), true ))) {
270284 return composite->emitError (" verification after linking failed" );
271285 }
0 commit comments