Skip to content

Commit

Permalink
Backout expandlibs part of bug 812179 for breaking bug 603370. r=me
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Mar 6, 2013
1 parent 8ff8099 commit fcb2bbf
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 96 deletions.
8 changes: 4 additions & 4 deletions config/expandlibs.py
Expand Up @@ -26,6 +26,7 @@
descriptor contains. And for each of these LIBS, also apply the same
rules.
'''
from __future__ import with_statement
import sys, os, errno
import expandlibs_config as conf

Expand All @@ -35,7 +36,7 @@ def ensureParentDir(file):
if dir and not os.path.exists(dir):
try:
os.makedirs(dir)
except OSError as error:
except OSError, error:
if error.errno != errno.EEXIST:
raise

Expand Down Expand Up @@ -89,8 +90,7 @@ def __init__(self, content=None):

def __str__(self):
'''Serializes the lib descriptor'''
return '\n'.join('{0} = {1}'.format(k, ' '.join(self[k]))
for k in self.KEYS if len(self[k]))
return '\n'.join('%s = %s' % (k, ' '.join(self[k])) for k in self.KEYS if len(self[k]))

class ExpandArgs(list):
def __init__(self, args):
Expand Down Expand Up @@ -135,4 +135,4 @@ def _expand_desc(self, arg):
return objs

if __name__ == '__main__':
print(" ".join(ExpandArgs(sys.argv[1:])))
print " ".join(ExpandArgs(sys.argv[1:]))
63 changes: 25 additions & 38 deletions config/expandlibs_exec.py
Expand Up @@ -20,11 +20,10 @@
relevant linker options to change the order in which the linker puts the
symbols appear in the resulting binary. Only works for ELF targets.
'''
from __future__ import print_function
from __future__ import with_statement
import sys
import os
from expandlibs import (ExpandArgs, relativize, isObject, ensureParentDir,
ExpandLibsDeps)
from expandlibs import ExpandArgs, relativize, isObject, ensureParentDir, ExpandLibsDeps
import expandlibs_config as conf
from optparse import OptionParser
import subprocess
Expand Down Expand Up @@ -93,10 +92,10 @@ def makelist(self):
if not len(objs): return
fd, tmp = tempfile.mkstemp(suffix=".list",dir=os.curdir)
if conf.EXPAND_LIBS_LIST_STYLE == "linkerscript":
content = ['INPUT("{0}")\n'.format(obj) for obj in objs]
content = ['INPUT("%s")\n' % obj for obj in objs]
ref = tmp
elif conf.EXPAND_LIBS_LIST_STYLE == "list":
content = ["{0}\n".format(obj) for obj in objs]
content = ["%s\n" % obj for obj in objs]
ref = "@" + tmp
else:
os.close(fd)
Expand Down Expand Up @@ -140,13 +139,9 @@ def _getFoldedSections(self):
def _getOrderedSections(self, ordered_symbols):
'''Given an ordered list of symbols, returns the corresponding list
of sections following the order.'''
if conf.EXPAND_LIBS_ORDER_STYLE not in ['linkerscript',
'section-ordering-file']:
raise Exception('EXPAND_LIBS_ORDER_STYLE "{0}" is not supported'
.format(conf.EXPAND_LIBS_ORDER_STYLE))
finder = SectionFinder([arg for arg in self
if isObject(arg) or
os.path.splitext(arg)[1] == conf.LIB_SUFFIX])
if not conf.EXPAND_LIBS_ORDER_STYLE in ['linkerscript', 'section-ordering-file']:
raise Exception('EXPAND_LIBS_ORDER_STYLE "%s" is not supported' % conf.EXPAND_LIBS_ORDER_STYLE)
finder = SectionFinder([arg for arg in self if isObject(arg) or os.path.splitext(arg)[1] == conf.LIB_SUFFIX])
folded = self._getFoldedSections()
sections = set()
ordered_sections = []
Expand Down Expand Up @@ -187,35 +182,32 @@ def orderSymbols(self, order):
linked_sections = [s for s in linked_sections if s in split_sections]

if conf.EXPAND_LIBS_ORDER_STYLE == 'section-ordering-file':
option = '-Wl,--section-ordering-file,{0}'
option = '-Wl,--section-ordering-file,%s'
content = sections
for linked_section in linked_sections:
content.extend(split_sections[linked_section])
content.append('{0}.*'.format(linked_section))
content.append('%s.*' % linked_section)
content.append(linked_section)

elif conf.EXPAND_LIBS_ORDER_STYLE == 'linkerscript':
option = '-Wl,-T,{0}'
option = '-Wl,-T,%s'
section_insert_before = dict(SECTION_INSERT_BEFORE)
for linked_section in linked_sections:
content.append('SECTIONS {{')
content.append(' {0} : {{'.format(linked_section))
content.extend(' *({0})'
.format(s for s in split_sections[linked_section]))
content.append(' }}')
content.append('}}')
content.append('INSERT BEFORE {0}'
.format(section_insert_before[linked_section]))
content.append('SECTIONS {')
content.append(' %s : {' % linked_section)
content.extend(' *(%s)' % s for s in split_sections[linked_section])
content.append(' }')
content.append('}')
content.append('INSERT BEFORE %s' % section_insert_before[linked_section])
else:
raise Exception('EXPAND_LIBS_ORDER_STYLE "{0}" is not supported'
.format(conf.EXPAND_LIBS_ORDER_STYLE))
raise Exception('EXPAND_LIBS_ORDER_STYLE "%s" is not supported' % conf.EXPAND_LIBS_ORDER_STYLE)

fd, tmp = tempfile.mkstemp(dir=os.curdir)
f = os.fdopen(fd, "w")
f.write('\n'.join(content)+'\n')
f.close()
self.tmp.append(tmp)
self.append(option.format(tmp))
self.append(option % tmp)

class SectionFinder(object):
'''Instances of this class allow to map symbol names to sections in
Expand All @@ -224,17 +216,15 @@ class SectionFinder(object):
def __init__(self, objs):
'''Creates an instance, given a list of object files.'''
if not conf.EXPAND_LIBS_ORDER_STYLE in ['linkerscript', 'section-ordering-file']:
raise Exception('EXPAND_LIBS_ORDER_STYLE "{0}" is not supported'
.format(conf.EXPAND_LIBS_ORDER_STYLE))
raise Exception('EXPAND_LIBS_ORDER_STYLE "%s" is not supported' % conf.EXPAND_LIBS_ORDER_STYLE)
self.mapping = {}
for obj in objs:
if not isObject(obj) and os.path.splitext(obj)[1] != conf.LIB_SUFFIX:
raise Exception('{0} is not an object nor a static library'
.format(obj))
raise Exception('%s is not an object nor a static library' % obj)
for symbol, section in SectionFinder._getSymbols(obj):
sym = SectionFinder._normalize(symbol)
if sym in self.mapping:
if section not in self.mapping[sym]:
if not section in self.mapping[sym]:
self.mapping[sym].append(section)
else:
self.mapping[sym] = [section]
Expand Down Expand Up @@ -278,11 +268,11 @@ def _getSymbols(obj):
return syms

def print_command(out, args):
print("Executing: " + " ".join(args), file=out)
print >>out, "Executing: " + " ".join(args)
for tmp in [f for f in args.tmp if os.path.isfile(f)]:
print(tmp + ":", file=out)
print >>out, tmp + ":"
with open(tmp) as file:
print("".join([" " + l for l in file.readlines()]), file=out)
print >>out, "".join([" " + l for l in file.readlines()])
out.flush()

def main():
Expand Down Expand Up @@ -333,10 +323,7 @@ def main():
return
ensureParentDir(options.depend)
with open(options.depend, 'w') as depfile:
depfile.write("{0} : {1}\n"
.format(options.target, ' '.join(dep for dep in deps
if os.path.isfile(dep) and
dep != options.target)))
depfile.write("%s : %s\n" % (options.target, ' '.join(dep for dep in deps if os.path.isfile(dep) and dep != options.target)))


if __name__ == '__main__':
Expand Down
12 changes: 6 additions & 6 deletions config/expandlibs_gen.py
@@ -1,10 +1,11 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import print_function

'''Given a list of object files and library names, prints a library
descriptor to standard output'''

from __future__ import with_statement
import sys
import os
import expandlibs_config as conf
Expand All @@ -18,12 +19,12 @@ def generate(args):
if os.path.exists(arg):
desc['OBJS'].append(os.path.abspath(arg))
else:
raise Exception("File not found: {0}".format(arg))
raise Exception("File not found: %s" % arg)
elif os.path.splitext(arg)[1] == conf.LIB_SUFFIX:
if os.path.exists(arg) or os.path.exists(arg + conf.LIBS_DESC_SUFFIX):
desc['LIBS'].append(os.path.abspath(arg))
else:
raise Exception("File not found: {0}".format(arg))
raise Exception("File not found: %s" % arg)
return desc

if __name__ == '__main__':
Expand All @@ -39,9 +40,8 @@ def generate(args):

ensureParentDir(options.output)
with open(options.output, 'w') as outfile:
print(generate(args), file=outfile)
print >>outfile, generate(args)
if options.depend:
ensureParentDir(options.depend)
with open(options.depend, 'w') as depfile:
depfile.write("{0} : {1}\n".format(options.output,
' '.join(ExpandLibsDeps(args))))
depfile.write("%s : %s\n" % (options.output, ' '.join(ExpandLibsDeps(args))))
8 changes: 4 additions & 4 deletions js/src/config/expandlibs.py
Expand Up @@ -26,6 +26,7 @@
descriptor contains. And for each of these LIBS, also apply the same
rules.
'''
from __future__ import with_statement
import sys, os, errno
import expandlibs_config as conf

Expand All @@ -35,7 +36,7 @@ def ensureParentDir(file):
if dir and not os.path.exists(dir):
try:
os.makedirs(dir)
except OSError as error:
except OSError, error:
if error.errno != errno.EEXIST:
raise

Expand Down Expand Up @@ -89,8 +90,7 @@ def __init__(self, content=None):

def __str__(self):
'''Serializes the lib descriptor'''
return '\n'.join('{0} = {1}'.format(k, ' '.join(self[k]))
for k in self.KEYS if len(self[k]))
return '\n'.join('%s = %s' % (k, ' '.join(self[k])) for k in self.KEYS if len(self[k]))

class ExpandArgs(list):
def __init__(self, args):
Expand Down Expand Up @@ -135,4 +135,4 @@ def _expand_desc(self, arg):
return objs

if __name__ == '__main__':
print(" ".join(ExpandArgs(sys.argv[1:])))
print " ".join(ExpandArgs(sys.argv[1:]))
63 changes: 25 additions & 38 deletions js/src/config/expandlibs_exec.py
Expand Up @@ -20,11 +20,10 @@
relevant linker options to change the order in which the linker puts the
symbols appear in the resulting binary. Only works for ELF targets.
'''
from __future__ import print_function
from __future__ import with_statement
import sys
import os
from expandlibs import (ExpandArgs, relativize, isObject, ensureParentDir,
ExpandLibsDeps)
from expandlibs import ExpandArgs, relativize, isObject, ensureParentDir, ExpandLibsDeps
import expandlibs_config as conf
from optparse import OptionParser
import subprocess
Expand Down Expand Up @@ -93,10 +92,10 @@ def makelist(self):
if not len(objs): return
fd, tmp = tempfile.mkstemp(suffix=".list",dir=os.curdir)
if conf.EXPAND_LIBS_LIST_STYLE == "linkerscript":
content = ['INPUT("{0}")\n'.format(obj) for obj in objs]
content = ['INPUT("%s")\n' % obj for obj in objs]
ref = tmp
elif conf.EXPAND_LIBS_LIST_STYLE == "list":
content = ["{0}\n".format(obj) for obj in objs]
content = ["%s\n" % obj for obj in objs]
ref = "@" + tmp
else:
os.close(fd)
Expand Down Expand Up @@ -140,13 +139,9 @@ def _getFoldedSections(self):
def _getOrderedSections(self, ordered_symbols):
'''Given an ordered list of symbols, returns the corresponding list
of sections following the order.'''
if conf.EXPAND_LIBS_ORDER_STYLE not in ['linkerscript',
'section-ordering-file']:
raise Exception('EXPAND_LIBS_ORDER_STYLE "{0}" is not supported'
.format(conf.EXPAND_LIBS_ORDER_STYLE))
finder = SectionFinder([arg for arg in self
if isObject(arg) or
os.path.splitext(arg)[1] == conf.LIB_SUFFIX])
if not conf.EXPAND_LIBS_ORDER_STYLE in ['linkerscript', 'section-ordering-file']:
raise Exception('EXPAND_LIBS_ORDER_STYLE "%s" is not supported' % conf.EXPAND_LIBS_ORDER_STYLE)
finder = SectionFinder([arg for arg in self if isObject(arg) or os.path.splitext(arg)[1] == conf.LIB_SUFFIX])
folded = self._getFoldedSections()
sections = set()
ordered_sections = []
Expand Down Expand Up @@ -187,35 +182,32 @@ def orderSymbols(self, order):
linked_sections = [s for s in linked_sections if s in split_sections]

if conf.EXPAND_LIBS_ORDER_STYLE == 'section-ordering-file':
option = '-Wl,--section-ordering-file,{0}'
option = '-Wl,--section-ordering-file,%s'
content = sections
for linked_section in linked_sections:
content.extend(split_sections[linked_section])
content.append('{0}.*'.format(linked_section))
content.append('%s.*' % linked_section)
content.append(linked_section)

elif conf.EXPAND_LIBS_ORDER_STYLE == 'linkerscript':
option = '-Wl,-T,{0}'
option = '-Wl,-T,%s'
section_insert_before = dict(SECTION_INSERT_BEFORE)
for linked_section in linked_sections:
content.append('SECTIONS {{')
content.append(' {0} : {{'.format(linked_section))
content.extend(' *({0})'
.format(s for s in split_sections[linked_section]))
content.append(' }}')
content.append('}}')
content.append('INSERT BEFORE {0}'
.format(section_insert_before[linked_section]))
content.append('SECTIONS {')
content.append(' %s : {' % linked_section)
content.extend(' *(%s)' % s for s in split_sections[linked_section])
content.append(' }')
content.append('}')
content.append('INSERT BEFORE %s' % section_insert_before[linked_section])
else:
raise Exception('EXPAND_LIBS_ORDER_STYLE "{0}" is not supported'
.format(conf.EXPAND_LIBS_ORDER_STYLE))
raise Exception('EXPAND_LIBS_ORDER_STYLE "%s" is not supported' % conf.EXPAND_LIBS_ORDER_STYLE)

fd, tmp = tempfile.mkstemp(dir=os.curdir)
f = os.fdopen(fd, "w")
f.write('\n'.join(content)+'\n')
f.close()
self.tmp.append(tmp)
self.append(option.format(tmp))
self.append(option % tmp)

class SectionFinder(object):
'''Instances of this class allow to map symbol names to sections in
Expand All @@ -224,17 +216,15 @@ class SectionFinder(object):
def __init__(self, objs):
'''Creates an instance, given a list of object files.'''
if not conf.EXPAND_LIBS_ORDER_STYLE in ['linkerscript', 'section-ordering-file']:
raise Exception('EXPAND_LIBS_ORDER_STYLE "{0}" is not supported'
.format(conf.EXPAND_LIBS_ORDER_STYLE))
raise Exception('EXPAND_LIBS_ORDER_STYLE "%s" is not supported' % conf.EXPAND_LIBS_ORDER_STYLE)
self.mapping = {}
for obj in objs:
if not isObject(obj) and os.path.splitext(obj)[1] != conf.LIB_SUFFIX:
raise Exception('{0} is not an object nor a static library'
.format(obj))
raise Exception('%s is not an object nor a static library' % obj)
for symbol, section in SectionFinder._getSymbols(obj):
sym = SectionFinder._normalize(symbol)
if sym in self.mapping:
if section not in self.mapping[sym]:
if not section in self.mapping[sym]:
self.mapping[sym].append(section)
else:
self.mapping[sym] = [section]
Expand Down Expand Up @@ -278,11 +268,11 @@ def _getSymbols(obj):
return syms

def print_command(out, args):
print("Executing: " + " ".join(args), file=out)
print >>out, "Executing: " + " ".join(args)
for tmp in [f for f in args.tmp if os.path.isfile(f)]:
print(tmp + ":", file=out)
print >>out, tmp + ":"
with open(tmp) as file:
print("".join([" " + l for l in file.readlines()]), file=out)
print >>out, "".join([" " + l for l in file.readlines()])
out.flush()

def main():
Expand Down Expand Up @@ -333,10 +323,7 @@ def main():
return
ensureParentDir(options.depend)
with open(options.depend, 'w') as depfile:
depfile.write("{0} : {1}\n"
.format(options.target, ' '.join(dep for dep in deps
if os.path.isfile(dep) and
dep != options.target)))
depfile.write("%s : %s\n" % (options.target, ' '.join(dep for dep in deps if os.path.isfile(dep) and dep != options.target)))


if __name__ == '__main__':
Expand Down

0 comments on commit fcb2bbf

Please sign in to comment.