@@ -226,7 +226,7 @@ static llvm::CachePruningPolicy getLTOCachePolicy(InputArgList &args) {
226
226
227
227
static DenseMap<StringRef, ArchiveFile *> loadedArchives;
228
228
229
- static InputFile *addFile (StringRef path, bool forceLoadArchive,
229
+ static InputFile *addFile (StringRef path, ForceLoad forceLoadArchive,
230
230
bool isExplicit = true , bool isBundleLoader = false ) {
231
231
Optional<MemoryBufferRef> buffer = readFile (path);
232
232
if (!buffer)
@@ -253,11 +253,13 @@ static InputFile *addFile(StringRef path, bool forceLoadArchive,
253
253
error (path + " : archive has no index; run ranlib to add one" );
254
254
255
255
auto *file = make<ArchiveFile>(std::move (archive));
256
- if (config->allLoad || forceLoadArchive) {
256
+ if ((forceLoadArchive == ForceLoad::Default && config->allLoad ) ||
257
+ forceLoadArchive == ForceLoad::Yes) {
257
258
if (Optional<MemoryBufferRef> buffer = readFile (path)) {
258
259
Error e = Error::success ();
259
260
for (const object::Archive::Child &c : file->getArchive ().children (e)) {
260
- StringRef reason = forceLoadArchive ? " -force_load" : " -all_load" ;
261
+ StringRef reason =
262
+ forceLoadArchive == ForceLoad::Yes ? " -force_load" : " -all_load" ;
261
263
if (Error e = file->fetch (c, reason))
262
264
error (toString (file) + " : " + reason +
263
265
" failed to load archive member: " + toString (std::move (e)));
@@ -266,7 +268,8 @@ static InputFile *addFile(StringRef path, bool forceLoadArchive,
266
268
error (toString (file) +
267
269
" : Archive::children failed: " + toString (std::move (e)));
268
270
}
269
- } else if (config->forceLoadObjC ) {
271
+ } else if (forceLoadArchive == ForceLoad::Default &&
272
+ config->forceLoadObjC ) {
270
273
for (const object::Archive::Symbol &sym : file->getArchive ().symbols ())
271
274
if (sym.getName ().startswith (objc::klass))
272
275
file->fetch (sym);
@@ -331,10 +334,11 @@ static InputFile *addFile(StringRef path, bool forceLoadArchive,
331
334
}
332
335
333
336
static void addLibrary (StringRef name, bool isNeeded, bool isWeak,
334
- bool isReexport, bool isExplicit, bool forceLoad) {
337
+ bool isReexport, bool isExplicit,
338
+ ForceLoad forceLoadArchive) {
335
339
if (Optional<StringRef> path = findLibrary (name)) {
336
340
if (auto *dylibFile = dyn_cast_or_null<DylibFile>(
337
- addFile (*path, forceLoad , isExplicit))) {
341
+ addFile (*path, forceLoadArchive , isExplicit))) {
338
342
if (isNeeded)
339
343
dylibFile->forceNeeded = true ;
340
344
if (isWeak)
@@ -350,10 +354,11 @@ static void addLibrary(StringRef name, bool isNeeded, bool isWeak,
350
354
}
351
355
352
356
static void addFramework (StringRef name, bool isNeeded, bool isWeak,
353
- bool isReexport, bool isExplicit) {
357
+ bool isReexport, bool isExplicit,
358
+ ForceLoad forceLoadArchive) {
354
359
if (Optional<StringRef> path = findFramework (name)) {
355
360
if (auto *dylibFile = dyn_cast_or_null<DylibFile>(
356
- addFile (*path, /* forceLoadArchive= */ false , isExplicit))) {
361
+ addFile (*path, forceLoadArchive, isExplicit))) {
357
362
if (isNeeded)
358
363
dylibFile->forceNeeded = true ;
359
364
if (isWeak)
@@ -392,15 +397,16 @@ void macho::parseLCLinkerOption(InputFile *f, unsigned argc, StringRef data) {
392
397
switch (arg->getOption ().getID ()) {
393
398
case OPT_l: {
394
399
StringRef name = arg->getValue ();
395
- bool forceLoad =
396
- config->forceLoadSwift ? name.startswith (" swift" ) : false ;
400
+ ForceLoad forceLoadArchive =
401
+ config->forceLoadSwift && name.startswith (" swift" ) ? ForceLoad::Yes
402
+ : ForceLoad::No;
397
403
addLibrary (name, /* isNeeded=*/ false , /* isWeak=*/ false ,
398
- /* isReexport=*/ false , /* isExplicit=*/ false , forceLoad );
404
+ /* isReexport=*/ false , /* isExplicit=*/ false , forceLoadArchive );
399
405
break ;
400
406
}
401
407
case OPT_framework:
402
408
addFramework (arg->getValue (), /* isNeeded=*/ false , /* isWeak=*/ false ,
403
- /* isReexport=*/ false , /* isExplicit=*/ false );
409
+ /* isReexport=*/ false , /* isExplicit=*/ false , ForceLoad::No );
404
410
break ;
405
411
default :
406
412
error (arg->getSpelling () + " is not allowed in LC_LINKER_OPTION" );
@@ -414,7 +420,7 @@ static void addFileList(StringRef path) {
414
420
return ;
415
421
MemoryBufferRef mbref = *buffer;
416
422
for (StringRef path : args::getLines (mbref))
417
- addFile (rerootPath (path), /* forceLoadArchive= */ false );
423
+ addFile (rerootPath (path), ForceLoad::Default );
418
424
}
419
425
420
426
// An order file has one entry per line, in the following format:
@@ -947,46 +953,47 @@ static void createFiles(const InputArgList &args) {
947
953
948
954
switch (opt.getID ()) {
949
955
case OPT_INPUT:
950
- addFile (rerootPath (arg->getValue ()), /* forceLoadArchive= */ false );
956
+ addFile (rerootPath (arg->getValue ()), ForceLoad::Default );
951
957
break ;
952
958
case OPT_needed_library:
953
959
if (auto *dylibFile = dyn_cast_or_null<DylibFile>(
954
- addFile (rerootPath (arg->getValue ()), false )))
960
+ addFile (rerootPath (arg->getValue ()), ForceLoad::Default )))
955
961
dylibFile->forceNeeded = true ;
956
962
break ;
957
963
case OPT_reexport_library:
958
- if (auto *dylibFile = dyn_cast_or_null<DylibFile>(addFile (
959
- rerootPath (arg->getValue ()), /* forceLoadArchive= */ false ))) {
964
+ if (auto *dylibFile = dyn_cast_or_null<DylibFile>(
965
+ addFile ( rerootPath (arg->getValue ()), ForceLoad::Default ))) {
960
966
config->hasReexports = true ;
961
967
dylibFile->reexport = true ;
962
968
}
963
969
break ;
964
970
case OPT_weak_library:
965
971
if (auto *dylibFile = dyn_cast_or_null<DylibFile>(
966
- addFile (rerootPath (arg->getValue ()), /* forceLoadArchive= */ false )))
972
+ addFile (rerootPath (arg->getValue ()), ForceLoad::Default )))
967
973
dylibFile->forceWeakImport = true ;
968
974
break ;
969
975
case OPT_filelist:
970
976
addFileList (arg->getValue ());
971
977
break ;
972
978
case OPT_force_load:
973
- addFile (rerootPath (arg->getValue ()), /* forceLoadArchive= */ true );
979
+ addFile (rerootPath (arg->getValue ()), ForceLoad::Yes );
974
980
break ;
975
981
case OPT_l:
976
982
case OPT_needed_l:
977
983
case OPT_reexport_l:
978
984
case OPT_weak_l:
979
985
addLibrary (arg->getValue (), opt.getID () == OPT_needed_l,
980
986
opt.getID () == OPT_weak_l, opt.getID () == OPT_reexport_l,
981
- /* isExplicit=*/ true , /* forceLoad= */ false );
987
+ /* isExplicit=*/ true , ForceLoad::Default );
982
988
break ;
983
989
case OPT_framework:
984
990
case OPT_needed_framework:
985
991
case OPT_reexport_framework:
986
992
case OPT_weak_framework:
987
993
addFramework (arg->getValue (), opt.getID () == OPT_needed_framework,
988
994
opt.getID () == OPT_weak_framework,
989
- opt.getID () == OPT_reexport_framework, /* isExplicit=*/ true );
995
+ opt.getID () == OPT_reexport_framework, /* isExplicit=*/ true ,
996
+ ForceLoad::Default);
990
997
break ;
991
998
default :
992
999
break ;
@@ -1175,7 +1182,7 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
1175
1182
if (const Arg *arg = args.getLastArg (OPT_bundle_loader)) {
1176
1183
if (config->outputType != MH_BUNDLE)
1177
1184
error (" -bundle_loader can only be used with MachO bundle output" );
1178
- addFile (arg->getValue (), /* forceLoadArchive= */ false , /* isExplicit=*/ false ,
1185
+ addFile (arg->getValue (), ForceLoad::Default , /* isExplicit=*/ false ,
1179
1186
/* isBundleLoader=*/ true );
1180
1187
}
1181
1188
if (const Arg *arg = args.getLastArg (OPT_umbrella)) {
0 commit comments