-
Notifications
You must be signed in to change notification settings - Fork 29.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for including GNU Gold linker's section ordering #16891
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,9 @@ import string | |
# If not run from node/, cd to node/. | ||
os.chdir(os.path.dirname(__file__) or '.') | ||
|
||
# Set by configure_node(). | ||
cross_compiling = False | ||
|
||
# gcc and g++ as defaults matches what GYP's Makefile generator does, | ||
# except on OS X. | ||
CC = os.environ.get('CC', 'cc' if sys.platform == 'darwin' else 'gcc') | ||
|
@@ -150,6 +153,12 @@ parser.add_option("--enable-vtune-profiling", | |
"JavaScript code executed in nodejs. This feature is only available " | ||
"for x32, x86, and x64 architectures.") | ||
|
||
parser.add_option("--enable-section-ordering", | ||
action="store", | ||
dest="section_ordering", | ||
help="Use GNU Gold linker capability to reorder sections in a binary." | ||
"This field will be passed to Gold linker's --section-ordering-file" | ||
"Provide a section ordering file to override the default") | ||
|
||
parser.add_option("--link-module", | ||
action="append", | ||
|
@@ -706,7 +715,6 @@ def check_compiler(o): | |
else: | ||
o['variables']['gas_version'] = get_gas_version(CC) | ||
|
||
|
||
def cc_macros(cc=None): | ||
"""Checks predefined macros using the C compiler command.""" | ||
|
||
|
@@ -865,6 +873,7 @@ def configure_node(o): | |
o['variables']['target_arch'] = target_arch | ||
o['variables']['node_byteorder'] = sys.byteorder | ||
|
||
global cross_compiling | ||
cross_compiling = (options.cross_compiling | ||
if options.cross_compiling is not None | ||
else target_arch != host_arch) | ||
|
@@ -1099,6 +1108,25 @@ def configure_static(o): | |
o['libraries'] += ['-static-libasan'] | ||
|
||
|
||
def configure_gold(o): | ||
try: | ||
proc = subprocess.Popen(['ld.gold'] + ['-v'], stdin=subprocess.PIPE, | ||
stderr=subprocess.PIPE, stdout=subprocess.PIPE) | ||
except OSError: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The try/except block should just be around the Popen call. |
||
return 0 | ||
match = re.match(r"(GNU gold) .* ([0-9]\.[0-9]+)", | ||
proc.communicate()[0]) | ||
if match: | ||
gold_version = match.group(2) | ||
if gold_version > '1.1': | ||
if options.section_ordering: | ||
o['variables']['gold_section_ordering_file'] = options.section_ordering | ||
else: | ||
o['variables']['gold_section_ordering_file'] = \ | ||
os.path.realpath('tools/gold_linker_section_reordering.txt') | ||
else: | ||
return 0 | ||
|
||
def write(filename, data): | ||
filename = filename | ||
print('creating %s' % filename) | ||
|
@@ -1425,6 +1453,7 @@ output = { | |
'libraries': [], | ||
'defines': [], | ||
'cflags': [], | ||
'ldflags': [], | ||
} | ||
|
||
# Print a warning when the compiler is too old. | ||
|
@@ -1450,6 +1479,8 @@ configure_v8(output) | |
configure_openssl(output) | ||
configure_intl(output) | ||
configure_static(output) | ||
if not cross_compiling and not os.environ.get('LD'): | ||
configure_gold(output) | ||
configure_inspector(output) | ||
|
||
# variables should be a root level element, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
Once the workload, production server has reached a steady state/ post warm-up phase | ||
|
||
- [] Collect the perf profile for the workload: | ||
``` | ||
perf record -ag -e cycles:pp -o <perf_profile_cycles_pp> -- sleep 30 | ||
``` | ||
`:pp` offers a more precise dist of cycles accounting | ||
|
||
- [] Use perf script command to decode the collected profile | ||
``` | ||
perf script -i perf_profile_inst -f comm,ip -c node | gzip -c > perf_profile_decoded.pds.gz | ||
``` | ||
- [] Use nm to dump the binary's symbol information | ||
``` | ||
nm -S node > node.nm | ||
``` | ||
- [] Run the hfsort program to determine the function ordering | ||
for the node binary ideal for this workload. | ||
https://github.com/facebook/hhvm/tree/master/hphp/tools/hfsort | ||
``` | ||
Usage: hfsort [-p] [-e <EDGCNT_FILE>] <SYMBOL_FILE> <PERF_DATA_FILE> | ||
|
||
-p, use pettis-hansen algorithm for code layout (optional) | ||
|
||
-e <EDGCNT_FILE>, use edge profile result to build the call graph | ||
|
||
hfsort -p node.nm perf_profile_decoded.pds.gz | ||
``` | ||
This application will create 2 files hotfuncs.txt and result-hfsort.txt | ||
|
||
hotfuncs.txt is what is used here. hfsort is one way to generate it. | ||
hfsort generates the minimal working order set required to optimally run the program. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you undo this change?