Commit 9ba50ebc authored by azarchs's avatar azarchs Committed by Commit bot

Fix a bunch of issues blocking 64-bit orderfile generation.

Fix a cast that didn't play nice in 64-bit.

Modify patch_orderfile.py and cyglog_to_orderfile to accept a --target_arch parameter.

Pass architecture to symbol_extractor.

BUG=448054

Review URL: https://codereview.chromium.org/902633002

Cr-Commit-Position: refs/heads/master@{#314802}
parent bcd64440
...@@ -220,11 +220,18 @@ def _OutputOrderfile(offsets, offset_to_symbol_infos, symbol_to_section_map, ...@@ -220,11 +220,18 @@ def _OutputOrderfile(offsets, offset_to_symbol_infos, symbol_to_section_map,
def main(): def main():
if len(sys.argv) != 4: parser = optparse.OptionParser(usage=
logging.error('Usage: cyglog_to_orderfile.py <merged_cyglog> ' 'usage: %prog [options] <merged_cyglog> <library> <output_filename>')
'<library> <output_filename>') parser.add_option('--target-arch', action='store', dest='arch',
default='arm',
choices=['arm', 'arm64', 'x86', 'x86_64', 'x64', 'mips'],
help='The target architecture for libchrome.so')
options, argv = parser.parse_args(sys.argv)
if len(argv) != 4:
parser.print_help()
return 1 return 1
(log_filename, lib_filename, output_filename) = sys.argv[1:] (log_filename, lib_filename, output_filename) = argv[1:]
symbol_extractor.SetArchitecture(options.arch)
obj_dir = os.path.abspath(os.path.join( obj_dir = os.path.abspath(os.path.join(
os.path.dirname(lib_filename), '../obj')) os.path.dirname(lib_filename), '../obj'))
......
...@@ -46,12 +46,12 @@ TEST(CygprofileTest, ThreadLogBasic) { ...@@ -46,12 +46,12 @@ TEST(CygprofileTest, ThreadLogBasic) {
ASSERT_EQ(2U, entries.size()); ASSERT_EQ(2U, entries.size());
// The entries should appear in their insertion order. // The entries should appear in their insertion order.
const LogEntry& first_entry = entries[0]; const LogEntry& first_entry = entries[0];
ASSERT_EQ(reinterpret_cast<int>(first_entry.address), 2); ASSERT_EQ(reinterpret_cast<uintptr_t>(first_entry.address), 2);
ASSERT_EQ(getpid(), first_entry.pid); ASSERT_EQ(getpid(), first_entry.pid);
ASSERT_LT(0, first_entry.tid); ASSERT_LT(0, first_entry.tid);
const LogEntry& second_entry = entries[1]; const LogEntry& second_entry = entries[1];
ASSERT_EQ(1, reinterpret_cast<int>(second_entry.address)); ASSERT_EQ(1, reinterpret_cast<uintptr_t>(second_entry.address));
ASSERT_EQ(first_entry.pid, second_entry.pid); ASSERT_EQ(first_entry.pid, second_entry.pid);
ASSERT_EQ(first_entry.tid, second_entry.tid); ASSERT_EQ(first_entry.tid, second_entry.tid);
...@@ -87,8 +87,8 @@ TEST(CygprofileTest, ManagerBasic) { ...@@ -87,8 +87,8 @@ TEST(CygprofileTest, ManagerBasic) {
// The flush should have moved the data to the local vector of entries. // The flush should have moved the data to the local vector of entries.
EXPECT_EQ(2U, entries.size()); EXPECT_EQ(2U, entries.size());
ASSERT_EQ(2, reinterpret_cast<int>(entries[0].address)); ASSERT_EQ(2, reinterpret_cast<uintptr_t>(entries[0].address));
ASSERT_EQ(3, reinterpret_cast<int>(entries[1].address)); ASSERT_EQ(3, reinterpret_cast<uintptr_t>(entries[1].address));
} }
} // namespace } // namespace
......
...@@ -26,6 +26,7 @@ The general pipeline is: ...@@ -26,6 +26,7 @@ The general pipeline is:
import collections import collections
import logging import logging
import optparse
import sys import sys
import symbol_extractor import symbol_extractor
...@@ -204,11 +205,19 @@ def _PrintSymbolsWithPrefixes(symbol_names, output_file): ...@@ -204,11 +205,19 @@ def _PrintSymbolsWithPrefixes(symbol_names, output_file):
def main(argv): def main(argv):
parser = optparse.OptionParser(usage=
'usage: %prog [options] <unpatched_orderfile> <library>')
parser.add_option('--target-arch', action='store', dest='arch',
default='arm',
choices=['arm', 'arm64', 'x86', 'x86_64', 'x64', 'mips'],
help='The target architecture for the library.')
options, argv = parser.parse_args(argv)
if len(argv) != 3: if len(argv) != 3:
print 'Usage: %s <unpatched_orderfile> <libchrome.so>' % argv[0] parser.print_help()
return 1 return 1
orderfile_filename = argv[1] orderfile_filename = argv[1]
binary_filename = argv[2] binary_filename = argv[2]
symbol_extractor.SetArchitecture(options.arch)
(offset_to_symbol_infos, name_to_symbol_infos) = _GroupSymbolInfosFromBinary( (offset_to_symbol_infos, name_to_symbol_infos) = _GroupSymbolInfosFromBinary(
binary_filename) binary_filename)
profiled_symbols = GetSymbolsFromOrderfile(orderfile_filename) profiled_symbols = GetSymbolsFromOrderfile(orderfile_filename)
......
...@@ -18,14 +18,13 @@ sys.path.insert( ...@@ -18,14 +18,13 @@ sys.path.insert(
import symbol import symbol
# TODO(lizeb): Change symbol.ARCH to the proper value when "arm" is no longer
# the only possible value.
_OBJDUMP_BINARY = symbol.ToolPath('objdump')
SymbolInfo = collections.namedtuple('SymbolInfo', ('name', 'offset', 'size', SymbolInfo = collections.namedtuple('SymbolInfo', ('name', 'offset', 'size',
'section')) 'section'))
def SetArchitecture(arch):
"""Set the architecture for binaries to be symbolized."""
symbol.ARCH = arch
def _FromObjdumpLine(line): def _FromObjdumpLine(line):
"""Create a SymbolInfo by parsing a properly formatted objdump output line. """Create a SymbolInfo by parsing a properly formatted objdump output line.
...@@ -81,7 +80,7 @@ def SymbolInfosFromBinary(binary_filename): ...@@ -81,7 +80,7 @@ def SymbolInfosFromBinary(binary_filename):
Returns: Returns:
A list of SymbolInfo from the binary. A list of SymbolInfo from the binary.
""" """
command = (_OBJDUMP_BINARY, '-t', '-w', binary_filename) command = (symbol.ToolPath('objdump'), '-t', '-w', binary_filename)
p = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE) p = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE)
try: try:
result = _SymbolInfosFromStream(p.stdout) result = _SymbolInfosFromStream(p.stdout)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment