Skip to content

Commit 869ded3

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: #16891 Signed-off-by: Gabriel Schulhof <[email protected]> PR-URL: #35272 Reviewed-By: Christian Clauss <[email protected]> Reviewed-By: Richard Lau <[email protected]>
1 parent ff4cf81 commit 869ded3

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

common.gypi

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@
111111
['target_arch in "ppc64 s390x"', {
112112
'v8_enable_backtrace': 1,
113113
}],
114+
['OS=="linux"', {
115+
'node_section_ordering_info%': ''
116+
}]
114117
],
115118
},
116119

@@ -172,6 +175,20 @@
172175
},
173176
'cflags': [ '-O3' ],
174177
'conditions': [
178+
['OS=="linux"', {
179+
'conditions': [
180+
['node_section_ordering_info!=""', {
181+
'cflags': [
182+
'-fuse-ld=gold',
183+
'-ffunction-sections',
184+
],
185+
'ldflags': [
186+
'-fuse-ld=gold',
187+
'-Wl,--section-ordering-file=<(node_section_ordering_info)',
188+
],
189+
}],
190+
],
191+
}],
175192
['OS=="solaris"', {
176193
# pull in V8's postmortem metadata
177194
'ldflags': [ '-Wl,-z,allextract' ]

configure.py

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

501+
parser.add_option('--use-section-ordering-file',
502+
action='store',
503+
dest='node_section_ordering_info',
504+
default='',
505+
help='Pass a section ordering file to the linker. This requires that ' +
506+
'Node.js be linked using the gold linker. The gold linker must have ' +
507+
'version 1.2 or greater.')
508+
501509
intl_optgroup.add_option('--with-intl',
502510
action='store',
503511
dest='with_intl',
@@ -1748,6 +1756,29 @@ def configure_inspector(o):
17481756
options.without_ssl)
17491757
o['variables']['v8_enable_inspector'] = 0 if disable_inspector else 1
17501758

1759+
def configure_section_file(o):
1760+
try:
1761+
proc = subprocess.Popen(['ld.gold'] + ['-v'], stdin = subprocess.PIPE,
1762+
stdout = subprocess.PIPE, stderr = subprocess.PIPE)
1763+
except OSError:
1764+
warn('''No acceptable ld.gold linker found!''')
1765+
return 0
1766+
1767+
match = re.match(r"^GNU gold.*([0-9]+)\.([0-9]+)$",
1768+
proc.communicate()[0].decode("utf-8"))
1769+
1770+
if match:
1771+
gold_major_version = match.group(1)
1772+
gold_minor_version = match.group(2)
1773+
if int(gold_major_version) == 1 and int(gold_minor_version) <= 1:
1774+
error('''GNU gold version must be greater than 1.2 in order to use section
1775+
reordering''')
1776+
1777+
if options.node_section_ordering_info != "":
1778+
o['variables']['node_section_ordering_info'] = os.path.realpath(
1779+
str(options.node_section_ordering_info))
1780+
else:
1781+
o['variables']['node_section_ordering_info'] = ""
17511782

17521783
def make_bin_override():
17531784
if sys.platform == 'win32':
@@ -1813,6 +1844,7 @@ def make_bin_override():
18131844
configure_intl(output)
18141845
configure_static(output)
18151846
configure_inspector(output)
1847+
configure_section_file(output)
18161848

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

0 commit comments

Comments
 (0)