Skip to content

Commit 0e5a828

Browse files
author
Gabriel Schulhof
committed
build: add support for section ordering
Adds support for using a section ordering file with the gold linker. This makes it possible to reorder functions in a build to optimize for a specific workload. `hfsort` is a tool that can be used to generate such a file from perf- recorded last branch record (LBR) data by running Node.js as `node --perf-basic-prof`. Refs: https://github.com/facebook/hhvm/tree/9966d482c19c6120c621c6f3896525fb19fb3842/hphp/tools/hfsort Refs: https://software.intel.com/content/www/us/en/develop/articles/runtime-optimization-blueprint-IA-optimization-with-last-branch-record.html Refs: nodejs#16891 Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com>
1 parent 6eb15ce commit 0e5a828

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

common.gypi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,16 @@
172172
},
173173
'cflags': [ '-O3' ],
174174
'conditions': [
175+
['node_section_ordering_file!="-"', {
176+
'cflags': [
177+
'-fuse-ld=gold',
178+
'-ffunction-sections',
179+
],
180+
'ldflags': [
181+
'-fuse-ld=gold',
182+
'-Wl,--section-ordering-file=<(node_section_ordering_file)',
183+
]
184+
}],
175185
['OS=="solaris"', {
176186
# pull in V8's postmortem metadata
177187
'ldflags': [ '-Wl,-z,allextract' ]

configure.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,14 @@
502502
dest='node_use_large_pages_script_lld',
503503
help='This option has no effect. --use-largepages is now a runtime option.')
504504

505+
parser.add_option('--use-section-ordering-file',
506+
action='store',
507+
dest='node_section_ordering_file',
508+
default='',
509+
help='Pass a section ordering file to the linker. This requires that ' +
510+
'Node.js be linked using the gold linker. The gold linker must have ' +
511+
'version 1.2 or greater.')
512+
505513
intl_optgroup.add_option('--with-intl',
506514
action='store',
507515
dest='with_intl',
@@ -1766,6 +1774,29 @@ def configure_inspector(o):
17661774
options.without_ssl)
17671775
o['variables']['v8_enable_inspector'] = 0 if disable_inspector else 1
17681776

1777+
def configure_section_file(o):
1778+
try:
1779+
proc = subprocess.Popen(['ld.gold'] + ['-v'], stdin = subprocess.PIPE,
1780+
stdout = subprocess.PIPE, stderr = subprocess.PIPE)
1781+
except OSError:
1782+
return 0
1783+
1784+
match = re.match(r"^GNU gold.*([0-9]+)\.([0-9]+)$",
1785+
proc.communicate()[0].decode("utf-8"))
1786+
1787+
if match:
1788+
gold_major_version = match.group(1)
1789+
gold_minor_version = match.group(2)
1790+
if int(gold_major_version) == 1 and int(gold_minor_version) <= 1:
1791+
error('''GNU gold version must be greater than 1.2 in order to use section
1792+
reordering''')
1793+
1794+
if options.node_section_ordering_file != "":
1795+
o['variables']['node_section_ordering_file'] = os.path.realpath(
1796+
str(options.node_section_ordering_file))
1797+
else:
1798+
# An empty string here will cause gyp to fail.
1799+
o['variables']['node_section_ordering_file'] = "-"
17691800

17701801
def make_bin_override():
17711802
if sys.platform == 'win32':
@@ -1831,6 +1862,7 @@ def make_bin_override():
18311862
configure_intl(output)
18321863
configure_static(output)
18331864
configure_inspector(output)
1865+
configure_section_file(output)
18341866

18351867
# Forward OSS-Fuzz settings
18361868
output['variables']['ossfuzz'] = b(options.ossfuzz)

0 commit comments

Comments
 (0)