@@ -306,21 +306,7 @@ void TargetLoweringObjectFileELF::emitModuleMetadata(MCStreamer &Streamer,
306
306
Module &M) const {
307
307
auto &C = getContext ();
308
308
309
- if (NamedMDNode *LinkerOptions = M.getNamedMetadata (" llvm.linker.options" )) {
310
- auto *S = C.getELFSection (" .linker-options" , ELF::SHT_LLVM_LINKER_OPTIONS,
311
- ELF::SHF_EXCLUDE);
312
-
313
- Streamer.switchSection (S);
314
-
315
- for (const auto *Operand : LinkerOptions->operands ()) {
316
- if (cast<MDNode>(Operand)->getNumOperands () != 2 )
317
- report_fatal_error (" invalid llvm.linker.options" );
318
- for (const auto &Option : cast<MDNode>(Operand)->operands ()) {
319
- Streamer.emitBytes (cast<MDString>(Option)->getString ());
320
- Streamer.emitInt8 (0 );
321
- }
322
- }
323
- }
309
+ emitLinkerDirectives (Streamer, M);
324
310
325
311
if (NamedMDNode *DependentLibraries = M.getNamedMetadata (" llvm.dependent-libraries" )) {
326
312
auto *S = C.getELFSection (" .deplibs" , ELF::SHT_LLVM_DEPENDENT_LIBRARIES,
@@ -400,6 +386,26 @@ void TargetLoweringObjectFileELF::emitModuleMetadata(MCStreamer &Streamer,
400
386
emitCGProfileMetadata (Streamer, M);
401
387
}
402
388
389
+ void TargetLoweringObjectFileELF::emitLinkerDirectives (MCStreamer &Streamer,
390
+ Module &M) const {
391
+ auto &C = getContext ();
392
+ if (NamedMDNode *LinkerOptions = M.getNamedMetadata (" llvm.linker.options" )) {
393
+ auto *S = C.getELFSection (" .linker-options" , ELF::SHT_LLVM_LINKER_OPTIONS,
394
+ ELF::SHF_EXCLUDE);
395
+
396
+ Streamer.switchSection (S);
397
+
398
+ for (const auto *Operand : LinkerOptions->operands ()) {
399
+ if (cast<MDNode>(Operand)->getNumOperands () != 2 )
400
+ report_fatal_error (" invalid llvm.linker.options" );
401
+ for (const auto &Option : cast<MDNode>(Operand)->operands ()) {
402
+ Streamer.emitBytes (cast<MDString>(Option)->getString ());
403
+ Streamer.emitInt8 (0 );
404
+ }
405
+ }
406
+ }
407
+ }
408
+
403
409
MCSymbol *TargetLoweringObjectFileELF::getCFIPersonalitySymbol (
404
410
const GlobalValue *GV, const TargetMachine &TM,
405
411
MachineModuleInfo *MMI) const {
@@ -1244,14 +1250,7 @@ MCSection *TargetLoweringObjectFileMachO::getStaticDtorSection(
1244
1250
void TargetLoweringObjectFileMachO::emitModuleMetadata (MCStreamer &Streamer,
1245
1251
Module &M) const {
1246
1252
// Emit the linker options if present.
1247
- if (auto *LinkerOptions = M.getNamedMetadata (" llvm.linker.options" )) {
1248
- for (const auto *Option : LinkerOptions->operands ()) {
1249
- SmallVector<std::string, 4 > StrOptions;
1250
- for (const auto &Piece : cast<MDNode>(Option)->operands ())
1251
- StrOptions.push_back (std::string (cast<MDString>(Piece)->getString ()));
1252
- Streamer.emitLinkerOptions (StrOptions);
1253
- }
1254
- }
1253
+ emitLinkerDirectives (Streamer, M);
1255
1254
1256
1255
unsigned VersionVal = 0 ;
1257
1256
unsigned ImageInfoFlags = 0 ;
@@ -1285,6 +1284,18 @@ void TargetLoweringObjectFileMachO::emitModuleMetadata(MCStreamer &Streamer,
1285
1284
Streamer.addBlankLine ();
1286
1285
}
1287
1286
1287
+ void TargetLoweringObjectFileMachO::emitLinkerDirectives (MCStreamer &Streamer,
1288
+ Module &M) const {
1289
+ if (auto *LinkerOptions = M.getNamedMetadata (" llvm.linker.options" )) {
1290
+ for (const auto *Option : LinkerOptions->operands ()) {
1291
+ SmallVector<std::string, 4 > StrOptions;
1292
+ for (const auto &Piece : cast<MDNode>(Option)->operands ())
1293
+ StrOptions.push_back (std::string (cast<MDString>(Piece)->getString ()));
1294
+ Streamer.emitLinkerOptions (StrOptions);
1295
+ }
1296
+ }
1297
+ }
1298
+
1288
1299
static void checkMachOComdat (const GlobalValue *GV) {
1289
1300
const Comdat *C = GV->getComdat ();
1290
1301
if (!C)
0 commit comments