nodejs-16.13.2-lto-update.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. Subject: Update support for ThinLTO, Mold LTO, and Gold LTO. (For 16.x to 17.x)
  2. Author: Orson Teodoro <orsonteodoro@hotmail.com
  3. Date: Fri Feb 4 10:41:12 PM PST 2022 (Unix time: 1644043272)
  4. Patch status: Testing
  5. diff -urp node-v16.13.2.orig/common.gypi node-v16.13.2/common.gypi
  6. --- node-v16.13.2.orig/common.gypi 2022-02-04 21:37:23.667470037 -0800
  7. +++ node-v16.13.2/common.gypi 2022-02-04 22:00:56.500753953 -0800
  8. @@ -177,8 +177,18 @@
  9. }],
  10. ['llvm_version=="0.0"', {
  11. 'lto': ' -flto=4 -fuse-linker-plugin -ffat-lto-objects ', # GCC
  12. - }, {
  13. - 'lto': ' -flto ', # Clang
  14. + }],
  15. + ['llvm_version!="0.0" and with_goldlto=="true"', {
  16. + 'lto': ' -flto', # Clang Gold LTO
  17. + }],
  18. + ['llvm_version!="0.0" and with_moldlto=="true"', {
  19. + 'lto': ' -flto', # Mold LTO
  20. + }],
  21. + ['llvm_version!="0.0" and with_thinlto=="true"', {
  22. + 'lto': ' -flto=thin', # Clang ThinLTO
  23. + }],
  24. + ['llvm_version!="0.0" and with_goldlto=="false" and with_thinlto=="false" and with_mold=="false"', {
  25. + 'lto': ' -flto', # Clang with system default
  26. }],
  27. ],
  28. },
  29. @@ -190,6 +194,21 @@
  30. 'LLVM_LTO': 'YES',
  31. },
  32. }],
  33. + ['OS=="linux" and with_moldlto=="true"', {
  34. + 'ldflags': [
  35. + '-fuse-ld=mold',
  36. + ],
  37. + }],
  38. + ['OS=="linux" and with_thinlto=="true"', {
  39. + 'ldflags': [
  40. + '-fuse-ld=lld',
  41. + ],
  42. + }],
  43. + ['OS=="linux" and (with_goldlto=="true" or node_section_ordering_info!="")', {
  44. + 'ldflags': [
  45. + '-fuse-ld=gold',
  46. + ],
  47. + }],
  48. ['OS=="linux"', {
  49. 'conditions': [
  50. ['node_section_ordering_info!=""', {
  51. @@ -198,7 +212,6 @@
  52. '-ffunction-sections',
  53. ],
  54. 'ldflags': [
  55. - '-fuse-ld=gold',
  56. '-Wl,--section-ordering-file=<(node_section_ordering_info)',
  57. ],
  58. }],
  59. diff -urp node-v16.13.2.orig/configure.py node-v16.13.2/configure.py
  60. --- node-v16.13.2.orig/configure.py 2022-01-10 13:33:29.000000000 -0800
  61. +++ node-v16.13.2/configure.py 2022-02-04 22:00:58.260824431 -0800
  62. @@ -540,6 +540,24 @@ parser.add_argument('--use-section-order
  63. 'Node.js be linked using the gold linker. The gold linker must have ' +
  64. 'version 1.2 or greater.')
  65. +parser.add_argument('--with-goldlto',
  66. + action='store_true',
  67. + dest='with_goldlto',
  68. + default=None,
  69. + help='Use Gold LTO')
  70. +
  71. +parser.add_argument('--with-moldlto',
  72. + action='store_true',
  73. + dest='with_moldlto',
  74. + default=None,
  75. + help='Use Mold LTO')
  76. +
  77. +parser.add_argument('--with-thinlto',
  78. + action='store_true',
  79. + dest='with_thinlto',
  80. + default=None,
  81. + help='Use ThinLTO and LLD')
  82. +
  83. intl_optgroup.add_argument('--with-intl',
  84. action='store',
  85. dest='with_intl',
  86. @@ -1344,6 +1350,23 @@ def configure_node(o):
  87. print('Warning! Loading builtin modules from disk is for development')
  88. o['variables']['node_builtin_modules_path'] = options.node_builtin_modules_path
  89. + o['variables']['with_goldlto'] = 'false'
  90. + o['variables']['with_moldlto'] = 'false'
  91. + o['variables']['with_thinlto'] = 'false'
  92. + if options.enable_lto:
  93. + if options.with_goldlto and options.with_moldlto:
  94. + error('''with_goldlto and with_moldlto cannot both be enabled''')
  95. + if options.with_thinlto and options.with_goldlto:
  96. + error('''with_thinlto and with_goldlto cannot both be enabled''')
  97. + if options.with_thinlto and options.with_moldlto:
  98. + error('''with_thinlto and with_moldlto cannot both be enabled''')
  99. + if options.with_goldlto:
  100. + o['variables']['with_goldlto'] = 'true'
  101. + elif options.with_moldlto:
  102. + o['variables']['with_moldlto'] = 'true'
  103. + elif options.with_thinlto:
  104. + o['variables']['with_thinlto'] = 'true'
  105. +
  106. def configure_napi(output):
  107. version = getnapibuildversion.get_napi_version()
  108. output['variables']['napi_build_version'] = version
  109. @@ -1825,6 +1841,10 @@ def configure_inspector(o):
  110. o['variables']['v8_enable_inspector'] = 0 if disable_inspector else 1
  111. def configure_section_file(o):
  112. + if options.with_thinlto and options.node_section_ordering_info != "":
  113. + error('''node_section_ordering_info cannot be combined with thinlto''')
  114. + if options.with_moldlto and options.node_section_ordering_info != "":
  115. + error('''node_section_ordering_info cannot be combined with moldlto''')
  116. try:
  117. proc = subprocess.Popen(['ld.gold'] + ['-v'], stdin = subprocess.PIPE,
  118. stdout = subprocess.PIPE, stderr = subprocess.PIPE)
  119. @@ -1843,7 +1861,7 @@ def configure_section_file(o):
  120. error('''GNU gold version must be greater than 1.2 in order to use section
  121. reordering''')
  122. - if options.node_section_ordering_info != "":
  123. + if options.node_section_ordering_info != "" and options.with_thinlto == None and options.with_moldlto == None:
  124. o['variables']['node_section_ordering_info'] = os.path.realpath(
  125. str(options.node_section_ordering_info))
  126. else: