@@ -468,24 +468,13 @@ static void thinLTOInternalizeAndPromoteGUID(
468
468
if (!EnableLTOInternalization)
469
469
continue ;
470
470
471
- // Ignore local and appending linkage values since the linker
472
- // doesn't resolve them (and there is no need to internalize if this is
473
- // already internal).
474
- if (GlobalValue::isLocalLinkage (S->linkage ()) ||
475
- S->linkage () == GlobalValue::AppendingLinkage)
476
- continue ;
477
-
478
- // We can't internalize available_externally globals because this
479
- // can break function pointer equality.
480
- if (S->linkage () == GlobalValue::AvailableExternallyLinkage)
481
- continue ;
482
-
483
- bool IsPrevailing = isPrevailing (VI.getGUID (), S.get ());
484
-
485
- if (GlobalValue::isInterposableLinkage (S->linkage ()) && !IsPrevailing)
471
+ // Non-exported values with external linkage can be internalized.
472
+ if (GlobalValue::isExternalLinkage (S->linkage ())) {
473
+ S->setLinkage (GlobalValue::InternalLinkage);
486
474
continue ;
475
+ }
487
476
488
- // Non-exported functions and variables with linkonce_odr or weak_odr
477
+ // Non-exported function and variable definitions with a weak-for-linker
489
478
// linkage can be internalized in certain cases. The minimum legality
490
479
// requirements would be that they are not address taken to ensure that we
491
480
// don't break pointer equality checks, and that variables are either read-
@@ -494,7 +483,7 @@ static void thinLTOInternalizeAndPromoteGUID(
494
483
// (which is how this is guaranteed for variables, when analyzing whether
495
484
// they are read or write-only).
496
485
//
497
- // However, we only get to this code for weak/linkonce ODR values in one of
486
+ // However, we only get to this code for weak-for-linkage values in one of
498
487
// two cases:
499
488
// 1) The prevailing copy is not in IR (it is in native code).
500
489
// 2) The prevailing copy in IR is not exported from its module.
@@ -506,10 +495,10 @@ static void thinLTOInternalizeAndPromoteGUID(
506
495
// duplicate linkonce_odr copies as exported via the tool, so we need
507
496
// to handle that case below by checking the number of copies.
508
497
//
509
- // Generally, we only want to internalize a linkonce/ weak ODR value in case
498
+ // Generally, we only want to internalize a weak-for-linker value in case
510
499
// 2, because in case 1 we cannot see how the value is used to know if it
511
500
// is read or write-only. We also don't want to bloat the binary with
512
- // multiple internalized copies of non-prevailing linkonce_odr functions.
501
+ // multiple internalized copies of non-prevailing linkonce/weak functions.
513
502
// Note if we don't internalize, we will convert non-prevailing copies to
514
503
// available_externally anyway, so that we drop them after inlining. The
515
504
// only reason to internalize such a function is if we indeed have a single
@@ -520,18 +509,16 @@ static void thinLTOInternalizeAndPromoteGUID(
520
509
// already perform this elsewhere in the ThinLTO backend handling for
521
510
// read or write-only variables (processGlobalForThinLTO).
522
511
//
523
- // Therefore, only internalize linkonce/weak ODR if there is a single copy,
524
- // that is prevailing in this IR module. We can do so aggressively, without
512
+ // Therefore, only internalize linkonce/weak if there is a single copy, that
513
+ // is prevailing in this IR module. We can do so aggressively, without
525
514
// requiring the address to be insignificant, or that a variable be read or
526
515
// write-only.
527
- if ((S->linkage () == GlobalValue::WeakODRLinkage ||
528
- S->linkage () == GlobalValue::LinkOnceODRLinkage) &&
529
- // We can have only one copy in ThinLTO that isn't prevailing, if the
530
- // prevailing copy is in a native object.
531
- (!IsPrevailing || ExternallyVisibleCopies > 1 ))
516
+ if (!GlobalValue::isWeakForLinker (S->linkage ()) ||
517
+ GlobalValue::isExternalWeakLinkage (S->linkage ()))
532
518
continue ;
533
519
534
- S->setLinkage (GlobalValue::InternalLinkage);
520
+ if (isPrevailing (VI.getGUID (), S.get ()) && ExternallyVisibleCopies == 1 )
521
+ S->setLinkage (GlobalValue::InternalLinkage);
535
522
}
536
523
}
537
524
0 commit comments