nodejs-22.2.0-lto-update.patch 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. Subject: Update support for ThinLTO, Mold LTO, and Gold LTO. (For 22.2.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. --- node-v22.2.0.orig/common.gypi 2024-05-15 05:34:59.000000000 -0700
  6. +++ node-v22.2.0/common.gypi 2024-05-21 15:25:21.153213630 -0700
  7. @@ -183,11 +183,21 @@
  8. }, {
  9. 'MSVC_runtimeType': 2 # MultiThreadedDLL (/MD)
  10. }],
  11. - ['clang==1', {
  12. - 'lto': ' -flto ', # Clang
  13. - }, {
  14. + ['clang==0', {
  15. 'lto': ' -flto=4 -fuse-linker-plugin -ffat-lto-objects ', # GCC
  16. }],
  17. + ['clang==1 and with_goldlto=="true"', {
  18. + 'lto': ' -flto', # Clang Gold LTO
  19. + }],
  20. + ['clang==1 and with_moldlto=="true"', {
  21. + 'lto': ' -flto', # Mold LTO
  22. + }],
  23. + ['clang==1 and with_thinlto=="true"', {
  24. + 'lto': ' -flto=thin', # Clang ThinLTO
  25. + }],
  26. + ['clang==1 and with_goldlto=="false" and with_thinlto=="false" and with_mold=="false"', {
  27. + 'lto': ' -flto', # Clang with system default
  28. + }],
  29. ],
  30. },
  31. 'cflags': [ '-O3' ],
  32. @@ -199,6 +209,21 @@
  33. 'LLVM_LTO': 'YES',
  34. },
  35. }],
  36. + ['OS=="linux" and with_moldlto=="true"', {
  37. + 'ldflags': [
  38. + '-fuse-ld=mold',
  39. + ],
  40. + }],
  41. + ['OS=="linux" and with_thinlto=="true"', {
  42. + 'ldflags': [
  43. + '-fuse-ld=lld',
  44. + ],
  45. + }],
  46. + ['OS=="linux" and (with_goldlto=="true" or node_section_ordering_info!="")', {
  47. + 'ldflags': [
  48. + '-fuse-ld=gold',
  49. + ],
  50. + }],
  51. ['OS=="linux"', {
  52. 'conditions': [
  53. ['node_section_ordering_info!=""', {
  54. @@ -207,7 +232,6 @@
  55. '-ffunction-sections',
  56. ],
  57. 'ldflags': [
  58. - '-fuse-ld=gold',
  59. '-Wl,--section-ordering-file=<(node_section_ordering_info)',
  60. ],
  61. }],
  62. --- node-v22.2.0.orig/configure.py 2024-05-15 05:34:59.000000000 -0700
  63. +++ node-v22.2.0/configure.py 2024-05-21 15:19:37.572073374 -0700
  64. @@ -651,6 +651,24 @@ parser.add_argument('--use-section-order
  65. 'Node.js be linked using the gold linker. The gold linker must have ' +
  66. 'version 1.2 or greater.')
  67. +parser.add_argument('--with-goldlto',
  68. + action='store_true',
  69. + dest='with_goldlto',
  70. + default=None,
  71. + help='Use Gold LTO')
  72. +
  73. +parser.add_argument('--with-moldlto',
  74. + action='store_true',
  75. + dest='with_moldlto',
  76. + default=None,
  77. + help='Use Mold LTO')
  78. +
  79. +parser.add_argument('--with-thinlto',
  80. + action='store_true',
  81. + dest='with_thinlto',
  82. + default=None,
  83. + help='Use ThinLTO and LLD')
  84. +
  85. intl_optgroup.add_argument('--with-intl',
  86. action='store',
  87. dest='with_intl',
  88. @@ -1558,6 +1576,23 @@ def configure_node(o):
  89. print('Warning! Loading builtin modules from disk is for development')
  90. o['variables']['node_builtin_modules_path'] = options.node_builtin_modules_path
  91. + o['variables']['with_goldlto'] = 'false'
  92. + o['variables']['with_moldlto'] = 'false'
  93. + o['variables']['with_thinlto'] = 'false'
  94. + if options.enable_lto:
  95. + if options.with_goldlto and options.with_moldlto:
  96. + error('''with_goldlto and with_moldlto cannot both be enabled''')
  97. + if options.with_thinlto and options.with_goldlto:
  98. + error('''with_thinlto and with_goldlto cannot both be enabled''')
  99. + if options.with_thinlto and options.with_moldlto:
  100. + error('''with_thinlto and with_moldlto cannot both be enabled''')
  101. + if options.with_goldlto:
  102. + o['variables']['with_goldlto'] = 'true'
  103. + elif options.with_moldlto:
  104. + o['variables']['with_moldlto'] = 'true'
  105. + elif options.with_thinlto:
  106. + o['variables']['with_thinlto'] = 'true'
  107. +
  108. def configure_napi(output):
  109. version = getnapibuildversion.get_napi_version()
  110. output['variables']['napi_build_version'] = version
  111. @@ -2064,6 +2099,10 @@ def configure_inspector(o):
  112. o['variables']['v8_enable_inspector'] = 0 if disable_inspector else 1
  113. def configure_section_file(o):
  114. + if options.with_thinlto and options.node_section_ordering_info != "":
  115. + error('''node_section_ordering_info cannot be combined with thinlto''')
  116. + if options.with_moldlto and options.node_section_ordering_info != "":
  117. + error('''node_section_ordering_info cannot be combined with moldlto''')
  118. try:
  119. proc = subprocess.Popen(['ld.gold'] + ['-v'], stdin = subprocess.PIPE,
  120. stdout = subprocess.PIPE, stderr = subprocess.PIPE)
  121. @@ -2083,7 +2122,7 @@ def configure_section_file(o):
  122. error('''GNU gold version must be greater than 1.2 in order to use section
  123. reordering''')
  124. - if options.node_section_ordering_info != "":
  125. + if options.node_section_ordering_info != "" and options.with_thinlto == None and options.with_moldlto == None:
  126. o['variables']['node_section_ordering_info'] = os.path.realpath(
  127. str(options.node_section_ordering_info))
  128. else: