4fc7fc
commit e6fd79f3795d46dfb583e124be49fc063bc3d58b
4fc7fc
Author: Chung-Lin Tang <cltang@codesourcery.com>
4fc7fc
Date:   Thu Oct 21 21:41:21 2021 +0800
4fc7fc
4fc7fc
    elf: Testing infrastructure for ld.so DSO sorting (BZ #17645)
4fc7fc
    
4fc7fc
    This is the first of a 2-part patch set that fixes slow DSO sorting behavior in
4fc7fc
    the dynamic loader, as reported in BZ #17645. In order to facilitate such a
4fc7fc
    large modification to the dynamic loader, this first patch implements a testing
4fc7fc
    framework for validating shared object sorting behavior, to enable comparison
4fc7fc
    between old/new sorting algorithms, and any later enhancements.
4fc7fc
    
4fc7fc
    This testing infrastructure consists of a Python script
4fc7fc
    scripts/dso-ordering-test.py' which takes in a description language, consisting
4fc7fc
    of strings that describe a set of link dependency relations between DSOs, and
4fc7fc
    generates testcase programs and Makefile fragments to automatically test the
4fc7fc
    described situation, for example:
4fc7fc
    
4fc7fc
      a->b->c->d          # four objects linked one after another
4fc7fc
    
4fc7fc
      a->[bc]->d;b->c     # a depends on b and c, which both depend on d,
4fc7fc
                          # b depends on c (b,c linked to object a in fixed order)
4fc7fc
    
4fc7fc
      a->b->c;{+a;%a;-a}  # a, b, c serially dependent, main program uses
4fc7fc
                          # dlopen/dlsym/dlclose on object a
4fc7fc
    
4fc7fc
      a->b->c;{}!->[abc]  # a, b, c serially dependent; multiple tests generated
4fc7fc
                          # to test all permutations of a, b, c ordering linked
4fc7fc
                          # to main program
4fc7fc
    
4fc7fc
     (Above is just a short description of what the script can do, more
4fc7fc
      documentation is in the script comments.)
4fc7fc
    
4fc7fc
    Two files containing several new tests, elf/dso-sort-tests-[12].def are added,
4fc7fc
    including test scenarios for BZ #15311 and Redhat issue #1162810 [1].
4fc7fc
    
4fc7fc
    Due to the nature of dynamic loader tests, where the sorting behavior and test
4fc7fc
    output occurs before/after main(), generating testcases to use
4fc7fc
    support/test-driver.c does not suffice to control meaningful timeout for ld.so.
4fc7fc
    Therefore a new utility program 'support/test-run-command', based on
4fc7fc
    test-driver.c/support_test_main.c has been added. This does the same testcase
4fc7fc
    control, but for a program specified through a command-line rather than at the
4fc7fc
    source code level. This utility is used to run the dynamic loader testcases
4fc7fc
    generated by dso-ordering-test.py.
4fc7fc
    
4fc7fc
    [1] https://bugzilla.redhat.com/show_bug.cgi?id=1162810
4fc7fc
    
4fc7fc
    Signed-off-by: Chung-Lin Tang  <cltang@codesourcery.com>
4fc7fc
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
4fc7fc
4fc7fc
diff --git a/elf/Makefile b/elf/Makefile
4fc7fc
index 1fdf40cbd49e233e..e92f62f279566684 100644
4fc7fc
--- a/elf/Makefile
4fc7fc
+++ b/elf/Makefile
4fc7fc
@@ -986,6 +986,21 @@ tests-special += \
4fc7fc
   # tests-special
4fc7fc
 endif
4fc7fc
 
4fc7fc
+# DSO sorting tests:
4fc7fc
+# The dso-ordering-test.py script generates testcase source files in $(objpfx),
4fc7fc
+# creating a $(objpfx)<testcase-name>-dir for each testcase, and creates a
4fc7fc
+# Makefile fragment to be included.
4fc7fc
+define include_dsosort_tests
4fc7fc
+$(objpfx)$(1).generated-makefile: $(1)
4fc7fc
+	$(PYTHON) $(..)scripts/dso-ordering-test.py \
4fc7fc
+	--description-file $$< --objpfx $(objpfx) --output-makefile $$@
4fc7fc
+include $(objpfx)$(1).generated-makefile
4fc7fc
+endef
4fc7fc
+
4fc7fc
+# Generate from each testcase description file
4fc7fc
+$(eval $(call include_dsosort_tests,dso-sort-tests-1.def))
4fc7fc
+$(eval $(call include_dsosort_tests,dso-sort-tests-2.def))
4fc7fc
+
4fc7fc
 check-abi: $(objpfx)check-abi-ld.out
4fc7fc
 tests-special += $(objpfx)check-abi-ld.out
4fc7fc
 update-abi: update-abi-ld
4fc7fc
diff --git a/elf/dso-sort-tests-1.def b/elf/dso-sort-tests-1.def
4fc7fc
new file mode 100644
4fc7fc
index 0000000000000000..873ddf55d91155c6
4fc7fc
--- /dev/null
4fc7fc
+++ b/elf/dso-sort-tests-1.def
4fc7fc
@@ -0,0 +1,66 @@
4fc7fc
+# DSO sorting test descriptions.
4fc7fc
+# This file is to be processed by ../scripts/dso-ordering-test.py, see usage
4fc7fc
+# in elf/Makefile for how it is executed.
4fc7fc
+
4fc7fc
+# We test both dynamic loader sorting algorithms
4fc7fc
+tunable_option: glibc.rtld.dynamic_sort=1
4fc7fc
+tunable_option: glibc.rtld.dynamic_sort=2
4fc7fc
+
4fc7fc
+# Sequence of single dependencies with no cycles.
4fc7fc
+tst-dso-ordering1: a->b->c
4fc7fc
+output: c>b>a>{}
4fc7fc
+
4fc7fc
+# Sequence including 2 dependent DSOs not at the end of the graph.
4fc7fc
+tst-dso-ordering2: a->b->[cd]->e
4fc7fc
+output: e>d>c>b>a>{}
4fc7fc
+
4fc7fc
+# Complex order with 3 "layers" of full dependencies
4fc7fc
+tst-dso-ordering3: a->[bc]->[def]->[gh]->i
4fc7fc
+output: i>h>g>f>e>d>c>b>a>{}
4fc7fc
+
4fc7fc
+# Sequence including 2 dependent DSOs at the end of the graph.
4fc7fc
+# Additionally the same dependencies appear in two paths.
4fc7fc
+tst-dso-ordering4: a->b->[de];a->c->d->e
4fc7fc
+output: e>d>c>b>a>{}
4fc7fc
+
4fc7fc
+# Test that b->c cross link is respected correctly
4fc7fc
+tst-dso-ordering5: a!->[bc]->d;b->c
4fc7fc
+output: d>c>b>a>{}
4fc7fc
+
4fc7fc
+# First DSO fully dependent on 4 DSOs, with another DSO at the end of chain.
4fc7fc
+tst-dso-ordering6: a->[bcde]->f
4fc7fc
+output: f>e>d>c>b>a>{}
4fc7fc
+
4fc7fc
+# Sequence including 2 dependent and 3 dependent DSOs, and one of the
4fc7fc
+# dependent DSOs is dependent on an earlier DSO.
4fc7fc
+tst-dso-ordering7: a->[bc];b->[cde];e->f
4fc7fc
+output: f>e>d>c>b>a>{}
4fc7fc
+
4fc7fc
+# Sequence where the DSO c is unerlinked and calls a function in DSO a which
4fc7fc
+# is technically a cycle.  The main executable depends on the first two DSOs.
4fc7fc
+# Note: This test has unspecified behavior.
4fc7fc
+tst-dso-ordering8: a->b->c=>a;{}->[ba]
4fc7fc
+output: c>b>a>{}
4fc7fc
+
4fc7fc
+# Generate the permutation of DT_NEEDED order between the main binary and
4fc7fc
+# all 5 DSOs; all link orders should produce exact same init/fini ordering
4fc7fc
+tst-dso-ordering9: a->b->c->d->e;{}!->[abcde]
4fc7fc
+output: e>d>c>b>a>{}
4fc7fc
+
4fc7fc
+# Test if init/fini ordering behavior is proper, despite main program with
4fc7fc
+# an soname that may cause confusion
4fc7fc
+tst-dso-ordering10: {}->a->b->c;soname({})=c
4fc7fc
+output: b>a>{}
4fc7fc
+
4fc7fc
+# Complex example from Bugzilla #15311, under-linked and with circular
4fc7fc
+# relocation(dynamic) dependencies. While this is technically unspecified, the
4fc7fc
+# presumed reasonable practical behavior is for the destructor order to respect
4fc7fc
+# the static DT_NEEDED links (here this means the a->b->c->d order).
4fc7fc
+# The older dynamic_sort=1 algorithm does not achieve this, while the DFS-based
4fc7fc
+# dynamic_sort=2 algorithm does, although it is still arguable whether going
4fc7fc
+# beyond spec to do this is the right thing to do.
4fc7fc
+# The below expected outputs are what the two algorithms currently produce
4fc7fc
+# respectively, for regression testing purposes.
4fc7fc
+tst-bz15311: {+a;+e;+f;+g;+d;%d;-d;-g;-f;-e;-a};a->b->c->d;d=>[ba];c=>a;b=>e=>a;c=>f=>b;d=>g=>c
4fc7fc
+xfail_output(glibc.rtld.dynamic_sort=1): {+a[d>c>b>a>];+e[e>];+f[f>];+g[g>];+d[];%d(b(e(a()))a()g(c(a()f(b(e(a()))))));-d[];-g[];-f[];-e[];-a[
4fc7fc
+output(glibc.rtld.dynamic_sort=2): {+a[d>c>b>a>];+e[e>];+f[f>];+g[g>];+d[];%d(b(e(a()))a()g(c(a()f(b(e(a()))))));-d[];-g[];-f[];-e[];-a[
4fc7fc
diff --git a/elf/dso-sort-tests-2.def b/elf/dso-sort-tests-2.def
4fc7fc
new file mode 100644
4fc7fc
index 0000000000000000..b79e79ecb7dc3dbf
4fc7fc
--- /dev/null
4fc7fc
+++ b/elf/dso-sort-tests-2.def
4fc7fc
@@ -0,0 +1,614 @@
4fc7fc
+# Large DSO sorting testcase adapted from Red Hat Bugzilla 1162810
4fc7fc
+#
4fc7fc
+# Note that below we specify different expected outputs between dynamic_sort=1
4fc7fc
+# and dynamic_sort=2 algorithms, due to circular dependencies in the testcase
4fc7fc
+# causing different sorting behavior.  These expected outputs are what the two
4fc7fc
+# algorithms currently produce, and are used for regression comparison tests.
4fc7fc
+# They are not "definitively" correct outputs, for circular dependencies
4fc7fc
+# inherently have unspecified behavior.
4fc7fc
+
4fc7fc
+xtest(tst-redhat-1162810):
4fc7fc
+{}->A101
4fc7fc
+{}->*
4fc7fc
+A101->(B101 B163 B122 B181)
4fc7fc
+A102->(B102 B140 B199 B158)
4fc7fc
+A103->(B103 B117 B176 B135)
4fc7fc
+A104->(B104 B194 B153 B112)
4fc7fc
+A105->(B105 B171 B130 B189)
4fc7fc
+A106->(B106 B148 B107 B166)
4fc7fc
+A107->(B107 B125 B184 B143)
4fc7fc
+A108->(B108 B102 B161 B120)
4fc7fc
+A109->(B109 B179 B138 B197)
4fc7fc
+A110->(B110 B156 B115 B174)
4fc7fc
+A111->(B111 B133 B192 B151)
4fc7fc
+A112->(B112 B110 B169 B128)
4fc7fc
+A113->(B113 B187 B146 B105)
4fc7fc
+A114->(B114 B164 B123 B182)
4fc7fc
+A115->(B115 B141 B200 B159)
4fc7fc
+A116->(B116 B118 B177 B136)
4fc7fc
+A117->(B117 B195 B154 B113)
4fc7fc
+A118->(B118 B172 B131 B190)
4fc7fc
+A119->(B119 B149 B108 B167)
4fc7fc
+A120->(B120 B126 B185 B144)
4fc7fc
+A121->(B121 B103 B162)
4fc7fc
+A122->(B122 B180 B139 B198)
4fc7fc
+A123->(B123 B157 B116 B175)
4fc7fc
+A124->(B124 B134 B193 B152)
4fc7fc
+A125->(B125 B111 B170 B129)
4fc7fc
+A126->(B126 B188 B147 B106)
4fc7fc
+A127->(B127 B165 B124 B183)
4fc7fc
+A128->(B128 B142 B101 B160)
4fc7fc
+A129->(B129 B119 B178 B137)
4fc7fc
+A130->(B130 B196 B155 B114)
4fc7fc
+A131->(B131 B173 B132 B191)
4fc7fc
+A132->(B132 B150 B109 B168)
4fc7fc
+A133->(B133 B127 B186 B145)
4fc7fc
+A134->(B134 B104 B163 B122)
4fc7fc
+A135->(B135 B181 B140 B199)
4fc7fc
+A136->(B136 B158 B117 B176)
4fc7fc
+A137->(B137 B135 B194 B153)
4fc7fc
+A138->(B138 B112 B171 B130)
4fc7fc
+A139->(B139 B189 B148 B107)
4fc7fc
+A140->(B140 B166 B125 B184)
4fc7fc
+A141->(B141 B143 B102 B161)
4fc7fc
+A142->(B142 B120 B179 B138)
4fc7fc
+A143->(B143 B197 B156 B115)
4fc7fc
+A144->(B144 B174 B133 B192)
4fc7fc
+A145->(B145 B151 B110 B169)
4fc7fc
+A146->(B146 B128 B187)
4fc7fc
+A147->(B147 B105 B164 B123)
4fc7fc
+A148->(B148 B182 B141 B200)
4fc7fc
+A149->(B149 B159 B118 B177)
4fc7fc
+A150->(B150 B136 B195 B154)
4fc7fc
+A151->(B151 B113 B172 B131)
4fc7fc
+A152->(B152 B190 B149 B108)
4fc7fc
+A153->(B153 B167 B126 B185)
4fc7fc
+A154->(B154 B144 B103 B162)
4fc7fc
+A155->(B155 B121 B180 B139)
4fc7fc
+A156->(B156 B198 B157 B116)
4fc7fc
+A157->(B157 B175 B134 B193)
4fc7fc
+A158->(B158 B152 B111 B170)
4fc7fc
+A159->(B159 B129 B188 B147)
4fc7fc
+A160->(B160 B106 B165 B124)
4fc7fc
+A161->(B161 B183 B142 B101)
4fc7fc
+A162->(B162 B160 B119 B178)
4fc7fc
+A163->(B163 B137 B196 B155)
4fc7fc
+A164->(B164 B114 B173 B132)
4fc7fc
+A165->(B165 B191 B150 B109)
4fc7fc
+A166->(B166 B168 B127 B186)
4fc7fc
+A167->(B167 B145 B104 B163)
4fc7fc
+A168->(B168 B122 B181 B140)
4fc7fc
+A169->(B169 B199 B158 B117)
4fc7fc
+A170->(B170 B176 B135 B194)
4fc7fc
+A171->(B171 B153 B112)
4fc7fc
+A172->(B172 B130 B189 B148)
4fc7fc
+A173->(B173 B107 B166 B125)
4fc7fc
+A174->(B174 B184 B143 B102)
4fc7fc
+A175->(B175 B161 B120 B179)
4fc7fc
+A176->(B176 B138 B197 B156)
4fc7fc
+A177->(B177 B115 B174 B133)
4fc7fc
+A178->(B178 B192 B151 B110)
4fc7fc
+A179->(B179 B169 B128 B187)
4fc7fc
+A180->(B180 B146 B105 B164)
4fc7fc
+A181->(B181 B123 B182 B141)
4fc7fc
+A182->(B182 B200 B159 B118)
4fc7fc
+A183->(B183 B177 B136 B195)
4fc7fc
+A184->(B184 B154 B113 B172)
4fc7fc
+A185->(B185 B131 B190 B149)
4fc7fc
+A186->(B186 B108 B167 B126)
4fc7fc
+A187->(B187 B185 B144 B103)
4fc7fc
+A188->(B188 B162 B121 B180)
4fc7fc
+A189->(B189 B139 B198 B157)
4fc7fc
+A190->(B190 B116 B175 B134)
4fc7fc
+A191->(B191 B193 B152 B111)
4fc7fc
+A192->(B192 B170 B129 B188)
4fc7fc
+A193->(B193 B147 B106 B165)
4fc7fc
+A194->(B194 B124 B183 B142)
4fc7fc
+A195->(B195 B101 B160 B119)
4fc7fc
+A196->(B196 B178 B137)
4fc7fc
+A197->(B197 B155 B114 B173)
4fc7fc
+A198->(B198 B132 B191 B150)
4fc7fc
+A199->(B199 B109 B168 B127)
4fc7fc
+A200->(B200 B186 B145 B104)
4fc7fc
+B101->(C101 C164 C123 C182)
4fc7fc
+B102->(C102 C141 C200 C159)
4fc7fc
+B103->(C103 C118 C177 C136)
4fc7fc
+B104->(C104 C195 C154 C113)
4fc7fc
+B105->(C105 C172 C131 C190)
4fc7fc
+B106->(C106 C149 C108 C167)
4fc7fc
+B107->(C107 C126 C185 C144)
4fc7fc
+B108->(C108 C103 C162 C121)
4fc7fc
+B109->(C109 C180 C139 C198)
4fc7fc
+B110->(C110 C157 C116 C175)
4fc7fc
+B111->(C111 C134 C193 C152)
4fc7fc
+B112->(C112 C111 C170 C129)
4fc7fc
+B113->(C113 C188 C147 C106)
4fc7fc
+B114->(C114 C165 C124 C183)
4fc7fc
+B115->(C115 C142 C101 C160)
4fc7fc
+B116->(C116 C119 C178 C137)
4fc7fc
+B117->(C117 C196 C155 C114)
4fc7fc
+B118->(C118 C173 C132 C191)
4fc7fc
+B119->(C119 C150 C109 C168)
4fc7fc
+B120->(C120 C127 C186 C145)
4fc7fc
+B121->(C121 C104 C163 C122)
4fc7fc
+B122->(C122 C181 C140 C199)
4fc7fc
+B123->(C123 C158 C117 C176)
4fc7fc
+B124->(C124 C135 C194 C153)
4fc7fc
+B125->(C125 C112 C171 C130)
4fc7fc
+B126->(C126 C189 C148 C107)
4fc7fc
+B127->(C127 C166 C125 C184)
4fc7fc
+B128->(C128 C143 C102 C161)
4fc7fc
+B129->(C129 C120 C179 C138)
4fc7fc
+B130->(C130 C197 C156 C115)
4fc7fc
+B131->(C131 C174 C133 C192)
4fc7fc
+B132->(C132 C151 C110 C169)
4fc7fc
+B133->(C133 C128 C187 C146)
4fc7fc
+B134->(C134 C105 C164 C123)
4fc7fc
+B135->(C135 C182 C141 C200)
4fc7fc
+B136->(C136 C159 C118 C177)
4fc7fc
+B137->(C137 C136 C195 C154)
4fc7fc
+B138->(C138 C113 C172 C131)
4fc7fc
+B139->(C139 C190 C149 C108)
4fc7fc
+B140->(C140 C167 C126 C185)
4fc7fc
+B141->(C141 C144 C103 C162)
4fc7fc
+B142->(C142 C121 C180 C139)
4fc7fc
+B143->(C143 C198 C157 C116)
4fc7fc
+B144->(C144 C175 C134 C193)
4fc7fc
+B145->(C145 C152 C111 C170)
4fc7fc
+B146->(C146 C129 C188 C147)
4fc7fc
+B147->(C147 C106 C165 C124)
4fc7fc
+B148->(C148 C183 C142 C101)
4fc7fc
+B149->(C149 C160 C119 C178)
4fc7fc
+B150->(C150 C137 C196 C155)
4fc7fc
+B151->(C151 C114 C173 C132)
4fc7fc
+B152->(C152 C191 C150 C109)
4fc7fc
+B153->(C153 C168 C127 C186)
4fc7fc
+B154->(C154 C145 C104 C163)
4fc7fc
+B155->(C155 C122 C181 C140)
4fc7fc
+B156->(C156 C199 C158 C117)
4fc7fc
+B157->(C157 C176 C135 C194)
4fc7fc
+B158->(C158 C153 C112 C171)
4fc7fc
+B159->(C159 C130 C189 C148)
4fc7fc
+B160->(C160 C107 C166 C125)
4fc7fc
+B161->(C161 C184 C143 C102)
4fc7fc
+B162->(C162 C161 C120 C179)
4fc7fc
+B163->(C163 C138 C197 C156)
4fc7fc
+B164->(C164 C115 C174 C133)
4fc7fc
+B165->(C165 C192 C151 C110)
4fc7fc
+B166->(C166 C169 C128 C187)
4fc7fc
+B167->(C167 C146 C105 C164)
4fc7fc
+B168->(C168 C123 C182 C141)
4fc7fc
+B169->(C169 C200 C159 C118)
4fc7fc
+B170->(C170 C177 C136 C195)
4fc7fc
+B171->(C171 C154 C113 C172)
4fc7fc
+B172->(C172 C131 C190 C149)
4fc7fc
+B173->(C173 C108 C167 C126)
4fc7fc
+B174->(C174 C185 C144 C103)
4fc7fc
+B175->(C175 C162 C121 C180)
4fc7fc
+B176->(C176 C139 C198 C157)
4fc7fc
+B177->(C177 C116 C175 C134)
4fc7fc
+B178->(C178 C193 C152 C111)
4fc7fc
+B179->(C179 C170 C129 C188)
4fc7fc
+B180->(C180 C147 C106 C165)
4fc7fc
+B181->(C181 C124 C183 C142)
4fc7fc
+B182->(C182 C101 C160 C119)
4fc7fc
+B183->(C183 C178 C137 C196)
4fc7fc
+B184->(C184 C155 C114 C173)
4fc7fc
+B185->(C185 C132 C191 C150)
4fc7fc
+B186->(C186 C109 C168 C127)
4fc7fc
+B187->(C187 C186 C145 C104)
4fc7fc
+B188->(C188 C163 C122 C181)
4fc7fc
+B189->(C189 C140 C199 C158)
4fc7fc
+B190->(C190 C117 C176 C135)
4fc7fc
+B191->(C191 C194 C153 C112)
4fc7fc
+B192->(C192 C171 C130 C189)
4fc7fc
+B193->(C193 C148 C107 C166)
4fc7fc
+B194->(C194 C125 C184 C143)
4fc7fc
+B195->(C195 C102 C161 C120)
4fc7fc
+B196->(C196 C179 C138 C197)
4fc7fc
+B197->(C197 C156 C115 C174)
4fc7fc
+B198->(C198 C133 C192 C151)
4fc7fc
+B199->(C199 C110 C169 C128)
4fc7fc
+B200->(C200 C187 C146 C105)
4fc7fc
+C101->(A165 A124)
4fc7fc
+C102->(A183 A142)
4fc7fc
+C103->(A101 A160)
4fc7fc
+C104->(A119 A178)
4fc7fc
+C105->(A137 A196)
4fc7fc
+C106->(A155 A114)
4fc7fc
+C107->(A173 A132)
4fc7fc
+C108->(A191 A150)
4fc7fc
+C109->(A109 A168)
4fc7fc
+C110->(A127 A186)
4fc7fc
+C111->(A145 A104)
4fc7fc
+C112->(A163 A122)
4fc7fc
+C113->(A181 A140)
4fc7fc
+C114->(A199 A158)
4fc7fc
+C115->(A117 A176)
4fc7fc
+C116->(A135 A194)
4fc7fc
+C117->(A153 A112)
4fc7fc
+C118->(A171 A130)
4fc7fc
+C119->(A189 A148)
4fc7fc
+C120->(A107 A166)
4fc7fc
+C121->(A125 A184)
4fc7fc
+C122->(A143 A102)
4fc7fc
+C123->(A161 A120)
4fc7fc
+C124->(A179 A138)
4fc7fc
+C125->(A197 A156)
4fc7fc
+C126->(A115 A174)
4fc7fc
+C127->(A133 A192)
4fc7fc
+C128->(A151 A110)
4fc7fc
+C129->(A169 A128)
4fc7fc
+C130->(A187 A146)
4fc7fc
+C131->(A105 A164)
4fc7fc
+C132->(A123 A182)
4fc7fc
+C133->(A141 A200)
4fc7fc
+C134->(A159 A118)
4fc7fc
+C135->(A177 A136)
4fc7fc
+C136->(A195 A154)
4fc7fc
+C137->(A113 A172)
4fc7fc
+C138->(A131 A190)
4fc7fc
+C139->(A149 A108)
4fc7fc
+C140->(A167 A126)
4fc7fc
+C141->(A185 A144)
4fc7fc
+C142->(A103 A162)
4fc7fc
+C143->(A121 A180)
4fc7fc
+C144->(A139 A198)
4fc7fc
+C145->(A157 A116)
4fc7fc
+C146->(A175 A134)
4fc7fc
+C147->(A193 A152)
4fc7fc
+C148->(A111 A170)
4fc7fc
+C149->(A129 A188)
4fc7fc
+C150->(A147 A106)
4fc7fc
+C151->(A165 A124)
4fc7fc
+C152->(A183 A142)
4fc7fc
+C153->(A101 A160)
4fc7fc
+C154->(A119 A178)
4fc7fc
+C155->(A137 A196)
4fc7fc
+C156->(A155 A114)
4fc7fc
+C157->(A173 A132)
4fc7fc
+C158->(A191 A150)
4fc7fc
+C159->(A109 A168)
4fc7fc
+C160->(A127 A186)
4fc7fc
+C161->(A145 A104)
4fc7fc
+C162->(A163 A122)
4fc7fc
+C163->(A181 A140)
4fc7fc
+C164->(A199 A158)
4fc7fc
+C165->(A117 A176)
4fc7fc
+C166->(A135 A194)
4fc7fc
+C167->(A153 A112)
4fc7fc
+C168->(A171 A130)
4fc7fc
+C169->(A189 A148)
4fc7fc
+C170->(A107 A166)
4fc7fc
+C171->(A125 A184)
4fc7fc
+C172->(A143 A102)
4fc7fc
+C173->(A161 A120)
4fc7fc
+C174->(A179 A138)
4fc7fc
+C175->(A197 A156)
4fc7fc
+C176->(A115 A174)
4fc7fc
+C177->(A133 A192)
4fc7fc
+C178->(A151 A110)
4fc7fc
+C179->(A169 A128)
4fc7fc
+C180->(A187 A146)
4fc7fc
+C181->(A105 A164)
4fc7fc
+C182->(A123 A182)
4fc7fc
+C183->(A141 A200)
4fc7fc
+C184->(A159 A118)
4fc7fc
+C185->(A177 A136)
4fc7fc
+C186->(A195 A154)
4fc7fc
+C187->(A113 A172)
4fc7fc
+C188->(A131 A190)
4fc7fc
+C189->(A149 A108)
4fc7fc
+C190->(A167 A126)
4fc7fc
+C191->(A185 A144)
4fc7fc
+C192->(A103 A162)
4fc7fc
+C193->(A121 A180)
4fc7fc
+C194->(A139 A198)
4fc7fc
+C195->(A157 A116)
4fc7fc
+C196->(A175 A134)
4fc7fc
+C197->(A193 A152)
4fc7fc
+C198->(A111 A170)
4fc7fc
+C199->(A129 A188)
4fc7fc
+C200->(A147 A106)
4fc7fc
+M11X11->(M13X14 M12X13 M12X12 M12X11)
4fc7fc
+M11X12->(M13X25 M12X24 M12X23 M12X22)
4fc7fc
+M11X13->(M13X21 M12X20 M12X19 M12X18)
4fc7fc
+M11X14->(M13X17 M12X16 M12X15 M12X14)
4fc7fc
+M11X15->(M13X13 M12X12 M12X11 M12X25)
4fc7fc
+M11X16->(M13X24 M12X23 M12X22 M12X21)
4fc7fc
+M11X17->(M13X20 M12X19 M12X18 M12X17)
4fc7fc
+M11X18->(M13X16 M12X15 M12X14 M12X13)
4fc7fc
+M11X19->(M13X12 M12X11 M12X25 M12X24)
4fc7fc
+M11X20->(M13X23 M12X22 M12X21 M12X20)
4fc7fc
+M11X21->(M13X19 M12X18 M12X17 M12X16)
4fc7fc
+M11X22->(M13X15 M12X14 M12X13 M12X12)
4fc7fc
+M11X23->(M13X11 M12X25 M12X24 M12X23)
4fc7fc
+M11X24->(M13X22 M12X21 M12X20 M12X19)
4fc7fc
+M11X25->(M13X18 M12X17 M12X16 M12X15)
4fc7fc
+M12X11->(M14X14 M13X13 M13X12 M13X11)
4fc7fc
+M12X12->(M14X25 M13X24 M13X23 M13X22)
4fc7fc
+M12X13->(M14X21 M13X20 M13X19 M13X18)
4fc7fc
+M12X14->(M14X17 M13X16 M13X15 M13X14)
4fc7fc
+M12X15->(M14X13 M13X12 M13X11 M13X25)
4fc7fc
+M12X16->(M14X24 M13X23 M13X22 M13X21)
4fc7fc
+M12X17->(M14X20 M13X19 M13X18 M13X17)
4fc7fc
+M12X18->(M14X16 M13X15 M13X14 M13X13)
4fc7fc
+M12X19->(M14X12 M13X11 M13X25 M13X24)
4fc7fc
+M12X20->(M14X23 M13X22 M13X21 M13X20)
4fc7fc
+M12X21->(M14X19 M13X18 M13X17 M13X16)
4fc7fc
+M12X22->(M14X15 M13X14 M13X13 M13X12)
4fc7fc
+M12X23->(M14X11 M13X25 M13X24 M13X23)
4fc7fc
+M12X24->(M14X22 M13X21 M13X20 M13X19)
4fc7fc
+M12X25->(M14X18 M13X17 M13X16 M13X15)
4fc7fc
+M13X11->(M15X14 M14X13 M14X12 M14X11)
4fc7fc
+M13X12->(M15X25 M14X24 M14X23 M14X22)
4fc7fc
+M13X13->(M15X21 M14X20 M14X19 M14X18)
4fc7fc
+M13X14->(M15X17 M14X16 M14X15 M14X14)
4fc7fc
+M13X15->(M15X13 M14X12 M14X11 M14X25)
4fc7fc
+M13X16->(M15X24 M14X23 M14X22 M14X21)
4fc7fc
+M13X17->(M15X20 M14X19 M14X18 M14X17)
4fc7fc
+M13X18->(M15X16 M14X15 M14X14 M14X13)
4fc7fc
+M13X19->(M15X12 M14X11 M14X25 M14X24)
4fc7fc
+M13X20->(M15X23 M14X22 M14X21 M14X20)
4fc7fc
+M13X21->(M15X19 M14X18 M14X17 M14X16)
4fc7fc
+M13X22->(M15X15 M14X14 M14X13 M14X12)
4fc7fc
+M13X23->(M15X11 M14X25 M14X24 M14X23)
4fc7fc
+M13X24->(M15X22 M14X21 M14X20 M14X19)
4fc7fc
+M13X25->(M15X18 M14X17 M14X16 M14X15)
4fc7fc
+M14X11->(M16X14 M15X13 M15X12 M15X11)
4fc7fc
+M14X12->(M16X25 M15X24 M15X23 M15X22)
4fc7fc
+M14X13->(M16X21 M15X20 M15X19 M15X18)
4fc7fc
+M14X14->(M16X17 M15X16 M15X15 M15X14)
4fc7fc
+M14X15->(M16X13 M15X12 M15X11 M15X25)
4fc7fc
+M14X16->(M16X24 M15X23 M15X22 M15X21)
4fc7fc
+M14X17->(M16X20 M15X19 M15X18 M15X17)
4fc7fc
+M14X18->(M16X16 M15X15 M15X14 M15X13)
4fc7fc
+M14X19->(M16X12 M15X11 M15X25 M15X24)
4fc7fc
+M14X20->(M16X23 M15X22 M15X21 M15X20)
4fc7fc
+M14X21->(M16X19 M15X18 M15X17 M15X16)
4fc7fc
+M14X22->(M16X15 M15X14 M15X13 M15X12)
4fc7fc
+M14X23->(M16X11 M15X25 M15X24 M15X23)
4fc7fc
+M14X24->(M16X22 M15X21 M15X20 M15X19)
4fc7fc
+M14X25->(M16X18 M15X17 M15X16 M15X15)
4fc7fc
+M15X11->(M17X14 M16X13 M16X12 M16X11)
4fc7fc
+M15X12->(M17X25 M16X24 M16X23 M16X22)
4fc7fc
+M15X13->(M17X21 M16X20 M16X19 M16X18)
4fc7fc
+M15X14->(M17X17 M16X16 M16X15 M16X14)
4fc7fc
+M15X15->(M17X13 M16X12 M16X11 M16X25)
4fc7fc
+M15X16->(M17X24 M16X23 M16X22 M16X21)
4fc7fc
+M15X17->(M17X20 M16X19 M16X18 M16X17)
4fc7fc
+M15X18->(M17X16 M16X15 M16X14 M16X13)
4fc7fc
+M15X19->(M17X12 M16X11 M16X25 M16X24)
4fc7fc
+M15X20->(M17X23 M16X22 M16X21 M16X20)
4fc7fc
+M15X21->(M17X19 M16X18 M16X17 M16X16)
4fc7fc
+M15X22->(M17X15 M16X14 M16X13 M16X12)
4fc7fc
+M15X23->(M17X11 M16X25 M16X24 M16X23)
4fc7fc
+M15X24->(M17X22 M16X21 M16X20 M16X19)
4fc7fc
+M15X25->(M17X18 M16X17 M16X16 M16X15)
4fc7fc
+M16X11->(M18X14 M17X13 M17X12 M17X11)
4fc7fc
+M16X12->(M18X25 M17X24 M17X23 M17X22)
4fc7fc
+M16X13->(M18X21 M17X20 M17X19 M17X18)
4fc7fc
+M16X14->(M18X17 M17X16 M17X15 M17X14)
4fc7fc
+M16X15->(M18X13 M17X12 M17X11 M17X25)
4fc7fc
+M16X16->(M18X24 M17X23 M17X22 M17X21)
4fc7fc
+M16X17->(M18X20 M17X19 M17X18 M17X17)
4fc7fc
+M16X18->(M18X16 M17X15 M17X14 M17X13)
4fc7fc
+M16X19->(M18X12 M17X11 M17X25 M17X24)
4fc7fc
+M16X20->(M18X23 M17X22 M17X21 M17X20)
4fc7fc
+M16X21->(M18X19 M17X18 M17X17 M17X16)
4fc7fc
+M16X22->(M18X15 M17X14 M17X13 M17X12)
4fc7fc
+M16X23->(M18X11 M17X25 M17X24 M17X23)
4fc7fc
+M16X24->(M18X22 M17X21 M17X20 M17X19)
4fc7fc
+M16X25->(M18X18 M17X17 M17X16 M17X15)
4fc7fc
+M17X11->(M19X14 M18X13 M18X12 M18X11)
4fc7fc
+M17X12->(M19X25 M18X24 M18X23 M18X22)
4fc7fc
+M17X13->(M19X21 M18X20 M18X19 M18X18)
4fc7fc
+M17X14->(M19X17 M18X16 M18X15 M18X14)
4fc7fc
+M17X15->(M19X13 M18X12 M18X11 M18X25)
4fc7fc
+M17X16->(M19X24 M18X23 M18X22 M18X21)
4fc7fc
+M17X17->(M19X20 M18X19 M18X18 M18X17)
4fc7fc
+M17X18->(M19X16 M18X15 M18X14 M18X13)
4fc7fc
+M17X19->(M19X12 M18X11 M18X25 M18X24)
4fc7fc
+M17X20->(M19X23 M18X22 M18X21 M18X20)
4fc7fc
+M17X21->(M19X19 M18X18 M18X17 M18X16)
4fc7fc
+M17X22->(M19X15 M18X14 M18X13 M18X12)
4fc7fc
+M17X23->(M19X11 M18X25 M18X24 M18X23)
4fc7fc
+M17X24->(M19X22 M18X21 M18X20 M18X19)
4fc7fc
+M17X25->(M19X18 M18X17 M18X16 M18X15)
4fc7fc
+M18X11->(M20X14 M19X13 M19X12 M19X11)
4fc7fc
+M18X12->(M20X25 M19X24 M19X23 M19X22)
4fc7fc
+M18X13->(M20X21 M19X20 M19X19 M19X18)
4fc7fc
+M18X14->(M20X17 M19X16 M19X15 M19X14)
4fc7fc
+M18X15->(M20X13 M19X12 M19X11 M19X25)
4fc7fc
+M18X16->(M20X24 M19X23 M19X22 M19X21)
4fc7fc
+M18X17->(M20X20 M19X19 M19X18 M19X17)
4fc7fc
+M18X18->(M20X16 M19X15 M19X14 M19X13)
4fc7fc
+M18X19->(M20X12 M19X11 M19X25 M19X24)
4fc7fc
+M18X20->(M20X23 M19X22 M19X21 M19X20)
4fc7fc
+M18X21->(M20X19 M19X18 M19X17 M19X16)
4fc7fc
+M18X22->(M20X15 M19X14 M19X13 M19X12)
4fc7fc
+M18X23->(M20X11 M19X25 M19X24 M19X23)
4fc7fc
+M18X24->(M20X22 M19X21 M19X20 M19X19)
4fc7fc
+M18X25->(M20X18 M19X17 M19X16 M19X15)
4fc7fc
+M19X11->(M21X14 M20X13 M20X12 M20X11)
4fc7fc
+M19X12->(M21X25 M20X24 M20X23 M20X22)
4fc7fc
+M19X13->(M21X21 M20X20 M20X19 M20X18)
4fc7fc
+M19X14->(M21X17 M20X16 M20X15 M20X14)
4fc7fc
+M19X15->(M21X13 M20X12 M20X11 M20X25)
4fc7fc
+M19X16->(M21X24 M20X23 M20X22 M20X21)
4fc7fc
+M19X17->(M21X20 M20X19 M20X18 M20X17)
4fc7fc
+M19X18->(M21X16 M20X15 M20X14 M20X13)
4fc7fc
+M19X19->(M21X12 M20X11 M20X25 M20X24)
4fc7fc
+M19X20->(M21X23 M20X22 M20X21 M20X20)
4fc7fc
+M19X21->(M21X19 M20X18 M20X17 M20X16)
4fc7fc
+M19X22->(M21X15 M20X14 M20X13 M20X12)
4fc7fc
+M19X23->(M21X11 M20X25 M20X24 M20X23)
4fc7fc
+M19X24->(M21X22 M20X21 M20X20 M20X19)
4fc7fc
+M19X25->(M21X18 M20X17 M20X16 M20X15)
4fc7fc
+M20X11->(M22X14 M21X13 M21X12 M21X11)
4fc7fc
+M20X12->(M22X25 M21X24 M21X23 M21X22)
4fc7fc
+M20X13->(M22X21 M21X20 M21X19 M21X18)
4fc7fc
+M20X14->(M22X17 M21X16 M21X15 M21X14)
4fc7fc
+M20X15->(M22X13 M21X12 M21X11 M21X25)
4fc7fc
+M20X16->(M22X24 M21X23 M21X22 M21X21)
4fc7fc
+M20X17->(M22X20 M21X19 M21X18 M21X17)
4fc7fc
+M20X18->(M22X16 M21X15 M21X14 M21X13)
4fc7fc
+M20X19->(M22X12 M21X11 M21X25 M21X24)
4fc7fc
+M20X20->(M22X23 M21X22 M21X21 M21X20)
4fc7fc
+M20X21->(M22X19 M21X18 M21X17 M21X16)
4fc7fc
+M20X22->(M22X15 M21X14 M21X13 M21X12)
4fc7fc
+M20X23->(M22X11 M21X25 M21X24 M21X23)
4fc7fc
+M20X24->(M22X22 M21X21 M21X20 M21X19)
4fc7fc
+M20X25->(M22X18 M21X17 M21X16 M21X15)
4fc7fc
+M21X11->(M23X15 M22X14 M22X13 M22X12)
4fc7fc
+M21X12->(M11X11 M23X25 M22X24 M22X23 M22X22)
4fc7fc
+M21X13->(M23X21 M22X20 M22X19 M22X18)
4fc7fc
+M21X14->(M23X17 M22X16 M22X15 M22X14)
4fc7fc
+M21X15->(M23X13 M22X12 M22X11 M22X25)
4fc7fc
+M21X16->(M23X24 M22X23 M22X22 M22X21)
4fc7fc
+M21X17->(M23X20 M22X19 M22X18 M22X17)
4fc7fc
+M21X18->(M23X16 M22X15 M22X14 M22X13)
4fc7fc
+M21X19->(M23X12 M22X11 M22X25 M22X24)
4fc7fc
+M21X20->(M23X23 M22X22 M22X21 M22X20)
4fc7fc
+M21X21->(M23X19 M22X18 M22X17 M22X16)
4fc7fc
+M21X22->(M23X15 M22X14 M22X13 M22X12)
4fc7fc
+M21X23->(M23X11 M22X25 M22X24 M22X23)
4fc7fc
+M21X24->(M23X22 M22X21 M22X20 M22X19)
4fc7fc
+M21X25->(M23X18 M22X17 M22X16 M22X15)
4fc7fc
+M22X11->(M24X16 M23X15 M23X14 M23X13)
4fc7fc
+M22X12->(M12X12 M24X11 M23X25 M23X24 M23X23)
4fc7fc
+M22X13->(M24X22 M23X21 M23X20 M23X19)
4fc7fc
+M22X14->(M24X18 M23X17 M23X16 M23X15)
4fc7fc
+M22X15->(M24X14 M23X13 M23X12 M23X11)
4fc7fc
+M22X16->(M24X25 M23X24 M23X23 M23X22)
4fc7fc
+M22X17->(M24X21 M23X20 M23X19 M23X18)
4fc7fc
+M22X18->(M24X17 M23X16 M23X15 M23X14)
4fc7fc
+M22X19->(M24X13 M23X12 M23X11 M23X25)
4fc7fc
+M22X20->(M24X24 M23X23 M23X22 M23X21)
4fc7fc
+M22X21->(M24X20 M23X19 M23X18 M23X17)
4fc7fc
+M22X22->(M24X16 M23X15 M23X14 M23X13)
4fc7fc
+M22X23->(M24X12 M23X11 M23X25 M23X24)
4fc7fc
+M22X24->(M24X23 M23X22 M23X21 M23X20)
4fc7fc
+M22X25->(M24X19 M23X18 M23X17 M23X16)
4fc7fc
+M23X11->(M25X17 M24X16 M24X15 M24X14)
4fc7fc
+M23X12->(M13X13 M25X12 M24X11 M24X25 M24X24)
4fc7fc
+M23X13->(M25X23 M24X22 M24X21 M24X20)
4fc7fc
+M23X14->(M25X19 M24X18 M24X17 M24X16)
4fc7fc
+M23X15->(M25X15 M24X14 M24X13 M24X12)
4fc7fc
+M23X16->(M25X11 M24X25 M24X24 M24X23)
4fc7fc
+M23X17->(M25X22 M24X21 M24X20 M24X19)
4fc7fc
+M23X18->(M25X18 M24X17 M24X16 M24X15)
4fc7fc
+M23X19->(M25X14 M24X13 M24X12 M24X11)
4fc7fc
+M23X20->(M25X25 M24X24 M24X23 M24X22)
4fc7fc
+M23X21->(M25X21 M24X20 M24X19 M24X18)
4fc7fc
+M23X22->(M25X17 M24X16 M24X15 M24X14)
4fc7fc
+M23X23->(M25X13 M24X12 M24X11 M24X25)
4fc7fc
+M23X24->(M25X24 M24X23 M24X22 M24X21)
4fc7fc
+M23X25->(M25X20 M24X19 M24X18 M24X17)
4fc7fc
+M24X11->(M26X18 M25X17 M25X16 M25X15)
4fc7fc
+M24X12->(M14X14 M26X13 M25X12 M25X11 M25X25)
4fc7fc
+M24X13->(M26X24 M25X23 M25X22 M25X21)
4fc7fc
+M24X14->(M26X20 M25X19 M25X18 M25X17)
4fc7fc
+M24X15->(M26X16 M25X15 M25X14 M25X13)
4fc7fc
+M24X16->(M26X12 M25X11 M25X25 M25X24)
4fc7fc
+M24X17->(M26X23 M25X22 M25X21 M25X20)
4fc7fc
+M24X18->(M26X19 M25X18 M25X17 M25X16)
4fc7fc
+M24X19->(M26X15 M25X14 M25X13 M25X12)
4fc7fc
+M24X20->(M26X11 M25X25 M25X24 M25X23)
4fc7fc
+M24X21->(M26X22 M25X21 M25X20 M25X19)
4fc7fc
+M24X22->(M26X18 M25X17 M25X16 M25X15)
4fc7fc
+M24X23->(M26X14 M25X13 M25X12 M25X11)
4fc7fc
+M24X24->(M26X25 M25X24 M25X23 M25X22)
4fc7fc
+M24X25->(M26X21 M25X20 M25X19 M25X18)
4fc7fc
+M25X11->(M27X19 M26X18 M26X17 M26X16)
4fc7fc
+M25X12->(M15X15 M27X14 M26X13 M26X12 M26X11)
4fc7fc
+M25X13->(M27X25 M26X24 M26X23 M26X22)
4fc7fc
+M25X14->(M27X21 M26X20 M26X19 M26X18)
4fc7fc
+M25X15->(M27X17 M26X16 M26X15 M26X14)
4fc7fc
+M25X16->(M27X13 M26X12 M26X11 M26X25)
4fc7fc
+M25X17->(M27X24 M26X23 M26X22 M26X21)
4fc7fc
+M25X18->(M27X20 M26X19 M26X18 M26X17)
4fc7fc
+M25X19->(M27X16 M26X15 M26X14 M26X13)
4fc7fc
+M25X20->(M27X12 M26X11 M26X25 M26X24)
4fc7fc
+M25X21->(M27X23 M26X22 M26X21 M26X20)
4fc7fc
+M25X22->(M27X19 M26X18 M26X17 M26X16)
4fc7fc
+M25X23->(M27X15 M26X14 M26X13 M26X12)
4fc7fc
+M25X24->(M27X11 M26X25 M26X24 M26X23)
4fc7fc
+M25X25->(M27X22 M26X21 M26X20 M26X19)
4fc7fc
+M26X11->(M28X20 M27X19 M27X18 M27X17)
4fc7fc
+M26X12->(M16X16 M28X15 M27X14 M27X13 M27X12)
4fc7fc
+M26X13->(M28X11 M27X25 M27X24 M27X23)
4fc7fc
+M26X14->(M28X22 M27X21 M27X20 M27X19)
4fc7fc
+M26X15->(M28X18 M27X17 M27X16 M27X15)
4fc7fc
+M26X16->(M28X14 M27X13 M27X12 M27X11)
4fc7fc
+M26X17->(M28X25 M27X24 M27X23 M27X22)
4fc7fc
+M26X18->(M28X21 M27X20 M27X19 M27X18)
4fc7fc
+M26X19->(M28X17 M27X16 M27X15 M27X14)
4fc7fc
+M26X20->(M28X13 M27X12 M27X11 M27X25)
4fc7fc
+M26X21->(M28X24 M27X23 M27X22 M27X21)
4fc7fc
+M26X22->(M28X20 M27X19 M27X18 M27X17)
4fc7fc
+M26X23->(M28X16 M27X15 M27X14 M27X13)
4fc7fc
+M26X24->(M28X12 M27X11 M27X25 M27X24)
4fc7fc
+M26X25->(M28X23 M27X22 M27X21 M27X20)
4fc7fc
+M27X11->(M29X21 M28X20 M28X19 M28X18)
4fc7fc
+M27X12->(M17X17 M29X16 M28X15 M28X14 M28X13)
4fc7fc
+M27X13->(M29X12 M28X11 M28X25 M28X24)
4fc7fc
+M27X14->(M29X23 M28X22 M28X21 M28X20)
4fc7fc
+M27X15->(M29X19 M28X18 M28X17 M28X16)
4fc7fc
+M27X16->(M29X15 M28X14 M28X13 M28X12)
4fc7fc
+M27X17->(M29X11 M28X25 M28X24 M28X23)
4fc7fc
+M27X18->(M29X22 M28X21 M28X20 M28X19)
4fc7fc
+M27X19->(M29X18 M28X17 M28X16 M28X15)
4fc7fc
+M27X20->(M29X14 M28X13 M28X12 M28X11)
4fc7fc
+M27X21->(M29X25 M28X24 M28X23 M28X22)
4fc7fc
+M27X22->(M29X21 M28X20 M28X19 M28X18)
4fc7fc
+M27X23->(M29X17 M28X16 M28X15 M28X14)
4fc7fc
+M27X24->(M29X13 M28X12 M28X11 M28X25)
4fc7fc
+M27X25->(M29X24 M28X23 M28X22 M28X21)
4fc7fc
+M28X11->(M30X22 M29X21 M29X20 M29X19)
4fc7fc
+M28X12->(M18X18 M30X17 M29X16 M29X15 M29X14)
4fc7fc
+M28X13->(M30X13 M29X12 M29X11 M29X25)
4fc7fc
+M28X14->(M30X24 M29X23 M29X22 M29X21)
4fc7fc
+M28X15->(M30X20 M29X19 M29X18 M29X17)
4fc7fc
+M28X16->(M30X16 M29X15 M29X14 M29X13)
4fc7fc
+M28X17->(M30X12 M29X11 M29X25 M29X24)
4fc7fc
+M28X18->(M30X23 M29X22 M29X21 M29X20)
4fc7fc
+M28X19->(M30X19 M29X18 M29X17 M29X16)
4fc7fc
+M28X20->(M30X15 M29X14 M29X13 M29X12)
4fc7fc
+M28X21->(M30X11 M29X25 M29X24 M29X23)
4fc7fc
+M28X22->(M30X22 M29X21 M29X20 M29X19)
4fc7fc
+M28X23->(M30X18 M29X17 M29X16 M29X15)
4fc7fc
+M28X24->(M30X14 M29X13 M29X12 M29X11)
4fc7fc
+M28X25->(M30X25 M29X24 M29X23 M29X22)
4fc7fc
+M29X11->(M30X22 M30X21 M30X20)
4fc7fc
+M29X12->(M30X17 M30X16 M30X15)
4fc7fc
+M29X13->(M30X13 M30X12 M30X11)
4fc7fc
+M29X14->(M30X24 M30X23 M30X22)
4fc7fc
+M29X15->(M30X20 M30X19 M30X18)
4fc7fc
+M29X16->(M30X16 M30X15 M30X14)
4fc7fc
+M29X17->(M30X12 M30X11 M30X25)
4fc7fc
+M29X18->(M30X23 M30X22 M30X21)
4fc7fc
+M29X19->(M30X19 M30X18 M30X17)
4fc7fc
+M29X20->(M30X15 M30X14 M30X13)
4fc7fc
+M29X21->(M30X11 M30X25 M30X24)
4fc7fc
+M29X22->(M30X22 M30X21 M30X20)
4fc7fc
+M29X23->(M30X18 M30X17 M30X16)
4fc7fc
+M29X24->(M30X14 M30X13 M30X12)
4fc7fc
+M29X25->(M30X25 M30X24 M30X23)
4fc7fc
+M30X11
4fc7fc
+M30X12
4fc7fc
+M30X13
4fc7fc
+M30X14
4fc7fc
+M30X15
4fc7fc
+M30X16
4fc7fc
+M30X17
4fc7fc
+M30X18
4fc7fc
+M30X19
4fc7fc
+M30X20
4fc7fc
+M30X21
4fc7fc
+M30X22
4fc7fc
+M30X23
4fc7fc
+M30X24
4fc7fc
+M30X25
4fc7fc
+xfail_output(glibc.rtld.dynamic_sort=1): M30X19>M30X15>M30X16>M30X11>M30X12>M30X17>M30X13>M30X14>M29X20>M30X23>M30X24>M30X20>M30X18>M29X15>M29X12>M30X22>M30X21>M29X22>M30X25>M29X19>M29X23>M29X16>M29X24>M29X13>M29X17>M29X18>M28X19>M29X21>M29X25>M29X14>M28X20>M28X15>M28X16>M28X21>M27X18>M29X11>M28X17>M28X11>M28X22>M27X14>M28X18>M27X15>M28X13>M27X11>M28X23>M27X25>M28X14>M28X25>M27X23>M27X22>M28X24>M27X21>M27X13>M27X19>M27X17>M26X11>M26X23>M26X21>M26X22>M26X20>M26X16>M25X21>M17X22>M15X15>M20X14>M20X16>M18X18>M28X12>M27X24>M25X17>M27X20>M26X18>M26X17>M27X16>M26X19>M25X18>M26X24>M25X20>M24X17>M23X18>M25X13>M26X13>M17X23>M16X16>M26X12>M25X12>M26X15>M24X19>M25X23>M25X24>M25X25>M24X20>M25X19>M24X21>M23X17>M22X21>M24X14>M23X22>M24X24>M22X20>M24X13>M25X11>M24X12>M25X15>M23X15>M25X16>M24X22>M23X13>M24X18>M23X14>M22X22>M21X20>M24X25>M23X16>M22X25>M21X19>M22X14>M23X11>M22X15>M21X18>M22X19>M21X17>M20X17>M19X17>M21X24>M21X12>M20X22>M19X16>M18X25>M19X21>M19X20>M18X24>M20X12>M19X11>M23X20>M22X24>M22X16>M21X21>M25X14>M23X19>M23X24>M20X24>M19X12>M18X15>M17X14>M16X18>M14X25>M16X22>M16X20>M17X17>M22X12>M21X11>M20X15>M18X22>M19X24>M19X18>M18X21>M17X16>M17X18>M16X21>M15X20>M19X22>M18X20>M18X11>M17X19>M16X17>M15X21>M16X14>M16X13>M15X22>M14X20>M17X25>M16X19>M14X21>M13X24>M12X12>M16X24>M15X23>M14X16>M16X15>M15X25>M15X11>M15X12>M14X15>M13X14>M14X22>M13X20>M12X13>M11X11>M22X23>M21X15>M21X16>M20X21>M20X20>M18X17>M19X25>M18X23>M21X13>M15X17>M15X18>M18X19>M17X24>M16X12>M17X13>M20X25>M19X23>M15X19>M14X13>M13X18>M15X13>M17X12>M16X11>M18X13>M18X12>M14X11>M14X24>M13X19>M15X14>M17X20>M20X11>M20X13>M21X14>M15X24>M14X12>M13X22>M14X23>M13X23>M14X19>M17X15>M16X25>M17X11>M18X14>M19X19>M21X25>M13X12>M13X11>M14X18>M13X13>M12X11>M15X16>M14X14>M27X12>M17X21>M20X23>M22X13>M21X22>M24X16>M24X15>M26X25>M23X25>M26X14>M23X12>M22X18>M24X11>M16X23>M19X14>M19X13>M21X23>M22X17>M23X23>M23X21>M25X22>M18X16>M19X15>M20X18>M20X19>M22X11>M24X23>C156>C118>C143>C137>C147>C106>C168>C113>C163>C155>C105>C146>C187>A150>C139>C180>C164>C193>C157>A191>C158>B188>A159>C184>C121>C154>B171>A105>C131>C104>B104>C161>C111>B145>C160>B155>A163>C112>C142>B148>C133>B198>A198>A115>C114>B157>A156>C175>B144>A120>C173>B184>A174>C126>B107>A139>C194>B194>A194>C116>B116>C166>B160>B110>A110>C128>B128>A128>C179>B162>A154>C186>B187>A179>C124>B181>A101>C153>B158>A136>C135>C176>A192>B133>A133>C177>B177>A177>C185>C103>B141>A141>C183>A162>C192>C129>B179>C144>B124>B183>C127>B127>A127>B108>A112>B153>A153>C167>B167>A186>A122>C162>A144>B149>C174>B131>A185>C141>B106>A126>A167>C140>B122>A170>C198>B143>C117>C123>B123>A147>A106>C200>B169>C191>B175>A123>B118>A182>C132>B151>A145>A104>A109>C159>C150>B119>A119>A178>B164>B114>A164>C181>A102>C122>B134>A157>A116>C195>B191>B111>C172>B172>A118>B129>A129>C149>A107>C170>B197>A197>A173>B168>A132>C107>B165>A160>A131>C188>A168>B109>C178>A189>A148>C119>C190>C120>B166>B176>C108>B135>B139>A103>B178>A169>B132>C125>C138>B163>A111>B170>C110>A165>C151>C169>C199>A138>C182>A135>B101>B142>C101>C148>B193>B152>A158>A199>C136>B137>A161>B120>A108>A149>A125>B113>A184>C171>A134>A175>A124>B150>B161>B102>A146>A187>C130>B192>B200>A200>A142>A183>C102>B105>B156>A176>C165>B147>A137>A196>B190>A190>B125>C134>C189>B126>B186>A166>B136>B195>A195>B154>B138>B112>B173>A117>B159>B182>A181>A140>C145>B117>A152>A193>C197>B130>A172>A113>A151>B115>A143>B140>B185>B103>A121>A180>A130>A171>B199>C196>B146>B180>C115>B174>B121>A188>B196>B189>C152>C109>A155>A114>M14X17>M13X15>M13X16>M13X17>M12X17>M12X21>M12X25>M12X14>M13X25>M12X15>M13X21>M12X16>M12X18>M12X19>M12X20>M12X22>M12X23>M12X24>M11X25>M11X24>M11X23>M11X22>M11X21>M11X20>M11X19>M11X18>M11X17>M11X16>M11X15>M11X14>M11X13>M11X12>{}
4fc7fc
+output(glibc.rtld.dynamic_sort=2): M30X19>M30X15>M30X16>M30X11>M30X12>M30X17>M30X13>M30X14>M29X20>M30X23>M30X24>M30X20>M30X18>M29X15>M29X12>M30X22>M30X21>M29X22>M30X25>M29X19>M29X23>M29X16>M29X24>M29X13>M29X17>M29X18>M28X19>M29X21>M29X25>M29X14>M28X20>M28X15>M28X16>M28X21>M27X18>M29X11>M28X17>M28X11>M28X22>M28X24>M28X23>M27X21>M28X13>M27X20>M27X19>M26X14>M27X25>M28X18>M27X11>M28X25>M27X24>M26X24>M27X15>M27X14>M27X13>M26X23>M27X17>M26X22>M25X13>M28X14>M27X16>M26X19>M26X18>M27X23>M27X22>M26X17>M25X18>M26X21>M25X17>M26X20>M26X15>M26X13>M25X19>M24X14>M25X23>M26X11>M26X25>M25X16>M25X15>M24X22>M25X21>M25X20>M24X21>M25X25>M25X24>M24X20>M23X13>M22X15>M25X14>M24X19>M23X17>M24X25>M23X24>M24X13>M23X15>M24X18>M23X14>M22X11>M24X15>M23X22>M24X11>M23X19>M22X21>M24X24>M23X21>M22X20>M23X25>M22X19>M21X24>M20X23>M22X22>M25X11>M23X16>M22X18>M23X20>M22X17>M21X21>M21X20>M20X24>M22X14>M22X13>M21X11>M21X17>M22X23>M21X16>M20X25>M19X23>M18X16>M21X22>M20X20>M20X19>M21X13>M20X18>M19X13>M21X18>M20X21>M19X24>M18X12>M20X14>M20X13>M22X25>M20X12>M20X15>M19X14>M18X22>M19X18>M20X17>M19X17>M19X16>M18X21>M17X20>M19X19>M18X13>M17X11>M18X17>M19X25>M18X15>M17X25>M18X19>M17X24>M16X19>M15X17>M17X21>M16X24>M18X23>M17X16>M16X25>M19X15>M18X25>M17X23>M16X23>M15X23>M18X14>M17X14>M16X14>M17X18>M16X13>M17X22>M16X12>M15X22>M14X16>M17X12>M16X22>M15X12>M16X11>M15X11>M16X15>M15X25>M14X15>M13X14>M15X18>M16X21>M15X16>M14X21>M15X14>M16X20>M15X13>M14X22>M15X20>M14X20>M13X20>M14X11>M15X19>M14X24>M13X19>M14X13>M13X18>M12X13>M15X24>M14X23>M13X12>M14X12>M13X11>M12X11>M11X11>M21X12>M20X11>M19X11>M18X11>M17X15>M16X18>M14X25>M14X19>M13X24>M13X23>M13X22>M12X12>M22X12>M21X15>M19X22>M18X20>M16X17>M14X14>M24X12>M23X23>M22X16>M21X14>M20X22>M18X24>M16X16>M26X12>M24X16>M23X11>M21X23>M19X20>M17X17>M27X12>M26X16>M25X22>M24X17>M23X18>M21X25>M19X12>M17X19>M15X21>M14X18>M13X13>M23X12>M21X19>M19X21>M17X13>M15X15>M25X12>M24X23>M22X24>M20X16>M18X18>M28X12>A150>C158>B112>A112>C167>B146>A146>C180>B180>A180>C143>B143>A115>C126>B126>A126>C190>B190>A190>C138>B138>A138>C174>B174>A102>C122>B122>A122>C162>B162>A162>C142>B142>A142>C102>B102>A174>C176>B176>A176>C115>B115>A143>C172>B172>A172>C187>B187>A187>C130>B130>A130>C118>B118>A118>C184>B184>A184>C171>B171>A171>C168>B182>A182>C182>B168>A168>C109>B109>A109>C159>B159>A159>C134>B134>A134>C146>B167>A167>C140>B140>A140>C163>B163>A163>C112>B158>A158>C164>B164>A164>C131>B131>A131>C188>B188>A188>C199>B199>A199>C114>B114>A114>C106>B106>A106>C200>B200>A200>C183>B183>A183>C152>B152>A152>C147>B147>A147>C150>B150>A198>C144>B144>A144>C191>B191>A191>C108>B108>A108>C139>B139>A139>C194>B194>A194>C166>B166>A166>C120>B120>A120>C123>B123>A123>C132>B132>A132>C107>B107>A107>C170>B170>A170>C198>B198>A156>C125>B125>A125>C121>B121>A121>C193>B193>A193>C197>B197>A197>C175>B175>A175>C196>B196>A196>C105>B105>A105>C181>B181>A181>C113>B113>A113>C137>B137>A137>C155>B155>A155>C156>B156>A110>C128>B128>A128>C179>B179>A179>C124>B124>A124>C151>B151>A151>C178>B178>A178>C104>B104>A104>C111>B111>A111>C148>B148>A148>C169>B169>A169>C129>B129>A129>C149>B149>A149>C189>B189>A189>C119>B119>A119>C154>B154>A154>C136>B136>A136>C135>B135>A135>C116>B116>A116>C145>B145>A145>C161>B161>A161>C173>B173>A173>C157>B157>A157>C195>B195>A195>C186>B186>A186>C160>B160>A160>C153>B153>A153>C117>B117>A117>C165>B165>A165>C101>B101>A101>C103>B103>A103>C192>B192>A192>C177>B177>A177>C185>B185>A185>C141>B141>A141>C133>B133>A133>C127>B127>A127>C110>B110>M14X17>M13X15>M13X16>M13X17>M12X17>M12X21>M12X25>M12X14>M13X25>M12X15>M13X21>M12X16>M12X18>M12X19>M12X20>M12X22>M12X23>M12X24>M11X25>M11X24>M11X23>M11X22>M11X21>M11X20>M11X19>M11X18>M11X17>M11X16>M11X15>M11X14>M11X13>M11X12>{}
4fc7fc
diff --git a/scripts/dso-ordering-test.py b/scripts/dso-ordering-test.py
4fc7fc
new file mode 100644
4fc7fc
index 0000000000000000..944ee740527d60fd
4fc7fc
--- /dev/null
4fc7fc
+++ b/scripts/dso-ordering-test.py
4fc7fc
@@ -0,0 +1,1144 @@
4fc7fc
+#!/usr/bin/python3
4fc7fc
+# Generate testcase files and Makefile fragments for DSO sorting test
4fc7fc
+# Copyright (C) 2021 Free Software Foundation, Inc.
4fc7fc
+# This file is part of the GNU C Library.
4fc7fc
+#
4fc7fc
+# The GNU C Library is free software; you can redistribute it and/or
4fc7fc
+# modify it under the terms of the GNU Lesser General Public
4fc7fc
+# License as published by the Free Software Foundation; either
4fc7fc
+# version 2.1 of the License, or (at your option) any later version.
4fc7fc
+#
4fc7fc
+# The GNU C Library is distributed in the hope that it will be useful,
4fc7fc
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
4fc7fc
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4fc7fc
+# Lesser General Public License for more details.
4fc7fc
+#
4fc7fc
+# You should have received a copy of the GNU Lesser General Public
4fc7fc
+# License along with the GNU C Library; if not, see
4fc7fc
+# <http://www.gnu.org/licenses/>.
4fc7fc
+
4fc7fc
+"""Generate testcase files and Makefile fragments for DSO sorting test
4fc7fc
+
4fc7fc
+This script takes a small description string language, and generates
4fc7fc
+testcases for displaying the ELF dynamic linker's dependency sorting
4fc7fc
+behavior, allowing verification.
4fc7fc
+
4fc7fc
+Testcase descriptions are semicolon-separated description strings, and
4fc7fc
+this tool generates a testcase from the description, including main program,
4fc7fc
+associated modules, and Makefile fragments for including into elf/Makefile.
4fc7fc
+
4fc7fc
+This allows automation of what otherwise would be very laborous manual
4fc7fc
+construction of complex dependency cases, however it must be noted that this
4fc7fc
+is only a tool to speed up testcase construction, and thus the generation
4fc7fc
+features are largely mechanical in nature; inconsistencies or errors may occur
4fc7fc
+if the input description was itself erroneous or have unforeseen interactions.
4fc7fc
+
4fc7fc
+The format of the input test description files are:
4fc7fc
+
4fc7fc
+  # Each test description has a name, lines of description,
4fc7fc
+  # and an expected output specification.  Comments use '#'.
4fc7fc
+  testname1: <test-description-line>
4fc7fc
+  output: <expected-output-string>
4fc7fc
+
4fc7fc
+  # Tests can be marked to be XFAIL by using 'xfail_output' instead
4fc7fc
+  testname2: <test-description-line>
4fc7fc
+  xfail_output: <expected-output-string>
4fc7fc
+
4fc7fc
+  # A default set of GLIBC_TUNABLES tunables can be specified, for which
4fc7fc
+  # all following tests will run multiple times, once for each of the
4fc7fc
+  # GLIBC_TUNABLES=... strings set by the 'tunable_option' command.
4fc7fc
+  tunable_option: <glibc-tunable-string1>
4fc7fc
+  tunable_option: <glibc-tunable-string2>
4fc7fc
+
4fc7fc
+  # Test descriptions can use multiple lines, which will all be merged
4fc7fc
+  # together, so order is not important.
4fc7fc
+  testname3: <test-description-line>
4fc7fc
+  <test-description-line>
4fc7fc
+  <test-description-line>
4fc7fc
+  ...
4fc7fc
+  output: <expected-output-string>
4fc7fc
+
4fc7fc
+  # 'testname3' will be run and compared two times, for both
4fc7fc
+  # GLIBC_TUNABLES=<glibc-tunable-string1> and
4fc7fc
+  # GLIBC_TUNABLES=<glibc-tunable-string2>.  This can be cleared and reset by the
4fc7fc
+  # 'clear_tunables' command:
4fc7fc
+  clear_tunables
4fc7fc
+
4fc7fc
+  # Multiple expected outputs can also be specified, with an associated
4fc7fc
+  # tunable option in (), which multiple tests will be run with each
4fc7fc
+  # GLIBC_TUNABLES=... option tried.
4fc7fc
+  testname4:
4fc7fc
+  <test-description-line>
4fc7fc
+  ...
4fc7fc
+  output(<glibc-tunable-string1>): <expected-output-string-1>
4fc7fc
+  output(<glibc-tunable-string2>): <expected-output-string-2>
4fc7fc
+  # Individual tunable output cases can be XFAILed, though note that
4fc7fc
+  # this will have the effect of XFAILing the entire 'testname4' test
4fc7fc
+  # in the final top-level tests.sum summary.
4fc7fc
+  xfail_output(<glibc-tunable-string3>): <expected-output-string-3>
4fc7fc
+
4fc7fc
+  # When multiple outputs (with specific tunable strings) are specified,
4fc7fc
+  # these take priority over any active 'tunable_option' settings.
4fc7fc
+
4fc7fc
+  # When a test is meant to be placed under 'xtests' (not run under
4fc7fc
+  # "make check", but only when "make xtests" is used), the testcase name can be
4fc7fc
+  # declared using 'xtest(<test-name>)':
4fc7fc
+  ...
4fc7fc
+  xtest(test-too-big1): <test-description>
4fc7fc
+  output: <expected-output-string>
4fc7fc
+  ...
4fc7fc
+
4fc7fc
+  # Do note that under current elf/Makefile organization, for such a xtest case,
4fc7fc
+  # while the test execution is only run under 'make xtests', the associated
4fc7fc
+  # DSOs are always built even under 'make check'.
4fc7fc
+
4fc7fc
+On the description language used, an example description line string:
4fc7fc
+
4fc7fc
+  a->b!->[cdef];c=>g=>h;{+c;%c;-c}->a
4fc7fc
+
4fc7fc
+Each identifier represents a shared object module, currently sequences of
4fc7fc
+letters/digits are allowed, case-sensitive.
4fc7fc
+
4fc7fc
+All such shared objects have a constructor/destructor generated for them
4fc7fc
+that emits its name followed by a '>' for constructors, and '<' followed by
4fc7fc
+its name for destructors, e.g. if the name is 'obj1', then "obj1>" and "
4fc7fc
+is printed by its constructor/destructor respectively.
4fc7fc
+
4fc7fc
+The -> operator specifies a link time dependency, these can be chained for
4fc7fc
+convenience (e.g. a->b->c->d).
4fc7fc
+
4fc7fc
+The => operator creates a call-reference, e.g. for a=>b, an fn_a() function
4fc7fc
+is created inside module 'a', which calls fn_b() in module 'b'.
4fc7fc
+These module functions emit 'name()' output in nested form,
4fc7fc
+e.g. a=>b emits 'a(b())'
4fc7fc
+
4fc7fc
+For single character object names, square brackets [] in the description
4fc7fc
+allows specifying multiple objects; e.g. a->[bcd]->e is equivalent to
4fc7fc
+ a->b->e;a->c->e;a->d->e
4fc7fc
+
4fc7fc
+The () parenthesis construct with space separated names is also allowed for
4fc7fc
+specifying objects.  For names with integer suffixes a range can also be used,
4fc7fc
+e.g. (foo1 bar2-5), specifies DSOs foo1, bar2, bar2, bar3, bar4, bar5.
4fc7fc
+
4fc7fc
+A {} construct specifies the main test program, and its link dependencies
4fc7fc
+are also specified using ->.  Inside {}, a few ;-separated constructs are
4fc7fc
+allowed:
4fc7fc
+         +a   Loads module a using dlopen(RTLD_LAZY|RTLD_GLOBAL)
4fc7fc
+         ^a   Loads module a using dlopen(RTLD_LAZY)
4fc7fc
+         %a   Use dlsym() to load and call fn_a()
4fc7fc
+         @a   Calls fn_a() directly.
4fc7fc
+         -a   Unloads module a using dlclose()
4fc7fc
+
4fc7fc
+The generated main program outputs '{' '}' with all output from above
4fc7fc
+constructs in between.  The other output before/after {} are the ordered
4fc7fc
+constructor/destructor output.
4fc7fc
+
4fc7fc
+If no {} construct is present, a default empty main program is linked
4fc7fc
+against all objects which have no dependency linked to it. e.g. for
4fc7fc
+'[ab]->c;d->e', the default main program is equivalent to '{}->[abd]'
4fc7fc
+
4fc7fc
+Sometimes for very complex or large testcases, besides specifying a
4fc7fc
+few explicit dependencies from main{}, the above default dependency
4fc7fc
+behavior is still useful to automatically have, but is turned off
4fc7fc
+upon specifying a single explicit {}->dso_name.
4fc7fc
+In this case, add {}->* to explicitly add this generation behavior:
4fc7fc
+
4fc7fc
+   # Main program links to 'foo', and all other objects which have no
4fc7fc
+   # dependency linked to it.
4fc7fc
+   {}->foo,{}->*
4fc7fc
+
4fc7fc
+Note that '*' works not only on main{}, but can be used as the
4fc7fc
+dependency target of any object.  Note that it only works as a target,
4fc7fc
+not a dependency source.
4fc7fc
+
4fc7fc
+The '!' operator after object names turns on permutation of its
4fc7fc
+dependencies, e.g. while a->[bcd] only generates one set of objects,
4fc7fc
+with 'a.so' built with a link line of "b.so c.so d.so", for a!->[bcd]
4fc7fc
+permutations of a's dependencies creates multiple testcases with
4fc7fc
+different link line orders: "b.so c.so d.so", "c.so b.so d.so",
4fc7fc
+"b.so d.so c.so", etc.  Note that for a <test-name> specified on
4fc7fc
+the script command-line, multiple <test-name_1>, <test-name_2>, etc.
4fc7fc
+tests will be generated (e.g. for a!->[bc]!->[de], eight tests with
4fc7fc
+different link orders for a, b, and c will be generated)
4fc7fc
+
4fc7fc
+It is possible to specify the ELF soname field for an object or the
4fc7fc
+main program:
4fc7fc
+   # DSO 'a' will be linked with the appropriate -Wl,-soname=x setting
4fc7fc
+   a->b->c;soname(a)=x
4fc7fc
+   # The the main program can also have a soname specified
4fc7fc
+   soname({})=y
4fc7fc
+
4fc7fc
+This can be used to test how ld.so behaves when objects and/or the
4fc7fc
+main program have such a field set.
4fc7fc
+
4fc7fc
+
4fc7fc
+Strings Output by Generated Testcase Programs
4fc7fc
+
4fc7fc
+The text output produced by a generated testcase consists of three main
4fc7fc
+parts:
4fc7fc
+  1. The constructors' output
4fc7fc
+  2. Output from the main program
4fc7fc
+  3. Destructors' output
4fc7fc
+
4fc7fc
+To see by example, a simple test description "a->b->c" generates a testcase
4fc7fc
+that when run, outputs: "c>b>a>{}
4fc7fc
+
4fc7fc
+Each generated DSO constructor prints its name followed by a '>' character,
4fc7fc
+and the "c>b>a" part above is the full constructor output by all DSOs, the
4fc7fc
+order indicating that DSO 'c', which does not depend on any other DSO, has
4fc7fc
+its constructor run first, followed by 'b' and then 'a'.
4fc7fc
+
4fc7fc
+Destructor output for each DSO is a '<' character followed by its name,
4fc7fc
+reflecting its reverse nature of constructors.  In the above example, the
4fc7fc
+destructor output part is "
4fc7fc
+
4fc7fc
+The middle "{}" part is the main program.  In this simple example, nothing
4fc7fc
+was specified for the main program, so by default it is implicitly linked
4fc7fc
+to the DSO 'a' (with no other DSOs depending on it) and only prints the
4fc7fc
+brackets {} with no actions inside.
4fc7fc
+
4fc7fc
+To see an example with actions inside the main program, lets see an example
4fc7fc
+description: c->g=>h;{+c;%c;-c}->a->h
4fc7fc
+
4fc7fc
+This produces a testcase, that when executed outputs:
4fc7fc
+             h>a>{+c[g>c>];%c();-c[
4fc7fc
+
4fc7fc
+The constructor and destructor parts display the a->h dependency as expected.
4fc7fc
+Inside the main program, the "+c" action triggers a dlopen() of DSO 'c',
4fc7fc
+causing another chain of constructors "g>c>" to be triggered.  Here it is
4fc7fc
+displayed inside [] brackets for each dlopen call.  The same is done for "-c",
4fc7fc
+a dlclose() of 'c'.
4fc7fc
+
4fc7fc
+The "%c" output is due to calling to fn_c() inside DSO 'c', this comprises
4fc7fc
+of two parts: the '%' character is printed by the caller, here it is the main
4fc7fc
+program.  The 'c' character is printed from inside fn_c().  The '%' character
4fc7fc
+indicates that this is called by a dlsym() of "fn_c".  A '@' character would
4fc7fc
+mean a direct call (with a symbol reference).  These can all be controlled
4fc7fc
+by the main test program constructs documented earlier.
4fc7fc
+
4fc7fc
+The output strings described here is the exact same form placed in
4fc7fc
+test description files' "output: <expected output>" line.
4fc7fc
+"""
4fc7fc
+
4fc7fc
+import sys
4fc7fc
+import re
4fc7fc
+import os
4fc7fc
+import subprocess
4fc7fc
+import argparse
4fc7fc
+from collections import OrderedDict
4fc7fc
+import itertools
4fc7fc
+
4fc7fc
+# BUILD_GCC is only used under the --build option,
4fc7fc
+# which builds the generated testcase, including DSOs using BUILD_GCC.
4fc7fc
+# Mainly for testing purposes, especially debugging of this script,
4fc7fc
+# and can be changed here to another toolchain path if needed.
4fc7fc
+build_gcc = "gcc"
4fc7fc
+
4fc7fc
+def get_parser():
4fc7fc
+    parser = argparse.ArgumentParser("")
4fc7fc
+    parser.add_argument("description",
4fc7fc
+                         help="Description string of DSO dependency test to be "
4fc7fc
+                         "generated (see script source for documentation of "
4fc7fc
+                         "description language), either specified here as "
4fc7fc
+                         "command line argument, or by input file using "
4fc7fc
+                         "-f/--description-file option",
4fc7fc
+                         nargs="?", default="")
4fc7fc
+    parser.add_argument("test_name",
4fc7fc
+                        help="Identifier for testcase being generated",
4fc7fc
+                        nargs="?", default="")
4fc7fc
+    parser.add_argument("--objpfx",
4fc7fc
+                        help="Path to place generated files, defaults to "
4fc7fc
+                        "current directory if none specified",
4fc7fc
+                        nargs="?", default="./")
4fc7fc
+    parser.add_argument("-m", "--output-makefile",
4fc7fc
+                        help="File to write Makefile fragment to, defaults to "
4fc7fc
+                        "stdout when option not present",
4fc7fc
+                        nargs="?", default="")
4fc7fc
+    parser.add_argument("-f", "--description-file",
4fc7fc
+                        help="Input file containing testcase descriptions",
4fc7fc
+                        nargs="?", default="")
4fc7fc
+    parser.add_argument("--build", help="After C testcase generated, build it "
4fc7fc
+                        "using gcc (for manual testing purposes)",
4fc7fc
+                        action="store_true")
4fc7fc
+    parser.add_argument("--debug-output",
4fc7fc
+                        help="Prints some internal data "
4fc7fc
+                        "structures; used for debugging of this script",
4fc7fc
+                        action="store_true")
4fc7fc
+    return parser
4fc7fc
+
4fc7fc
+# Main script starts here.
4fc7fc
+cmdlineargs = get_parser().parse_args()
4fc7fc
+test_name = cmdlineargs.test_name
4fc7fc
+description = cmdlineargs.description
4fc7fc
+objpfx = cmdlineargs.objpfx
4fc7fc
+description_file = cmdlineargs.description_file
4fc7fc
+output_makefile = cmdlineargs.output_makefile
4fc7fc
+makefile = ""
4fc7fc
+default_tunable_options = []
4fc7fc
+
4fc7fc
+current_input_lineno = 0
4fc7fc
+def error(msg):
4fc7fc
+    global current_input_lineno
4fc7fc
+    print("Error: %s%s" % ((("Line %d, " % current_input_lineno)
4fc7fc
+                            if current_input_lineno != 0 else ""),
4fc7fc
+                           msg))
4fc7fc
+    exit(1)
4fc7fc
+
4fc7fc
+if(test_name or description) and description_file:
4fc7fc
+    error("both command-line testcase and input file specified")
4fc7fc
+if test_name and not description:
4fc7fc
+    error("command-line testcase name without description string")
4fc7fc
+
4fc7fc
+# Main class type describing a testcase.
4fc7fc
+class TestDescr:
4fc7fc
+    def __init__(self):
4fc7fc
+        self.objs = []              # list of all DSO objects
4fc7fc
+        self.deps = OrderedDict()   # map of DSO object -> list of dependencies
4fc7fc
+
4fc7fc
+        # map of DSO object -> list of call refs
4fc7fc
+        self.callrefs = OrderedDict()
4fc7fc
+
4fc7fc
+        # map of DSO object -> list of permutations of dependencies
4fc7fc
+        self.dep_permutations = OrderedDict()
4fc7fc
+
4fc7fc
+        # map of DSO object -> SONAME of object (if one is specified)
4fc7fc
+        self.soname_map = OrderedDict()
4fc7fc
+
4fc7fc
+        # list of main program operations
4fc7fc
+        self.main_program = []
4fc7fc
+        # set if default dependencies added to main
4fc7fc
+        self.main_program_default_deps = True
4fc7fc
+
4fc7fc
+        self.test_name = ""                   # name of testcase
4fc7fc
+        self.expected_outputs = OrderedDict() # expected outputs of testcase
4fc7fc
+        self.xfail = False                    # set if this is a XFAIL testcase
4fc7fc
+        self.xtest = False                    # set if this is put under 'xtests'
4fc7fc
+
4fc7fc
+    # Add 'object -> [object, object, ...]' relations to CURR_MAP
4fc7fc
+    def __add_deps_internal(self, src_objs, dst_objs, curr_map):
4fc7fc
+        for src in src_objs:
4fc7fc
+            for dst in dst_objs:
4fc7fc
+                if not src in curr_map:
4fc7fc
+                    curr_map[src] = []
4fc7fc
+                if not dst in curr_map[src]:
4fc7fc
+                    curr_map[src].append(dst)
4fc7fc
+    def add_deps(self, src_objs, dst_objs):
4fc7fc
+        self.__add_deps_internal(src_objs, dst_objs, self.deps)
4fc7fc
+    def add_callrefs(self, src_objs, dst_objs):
4fc7fc
+        self.__add_deps_internal(src_objs, dst_objs, self.callrefs)
4fc7fc
+
4fc7fc
+# Process commands inside the {} construct.
4fc7fc
+# Note that throughout this script, the main program object is represented
4fc7fc
+# by the '#' string.
4fc7fc
+def process_main_program(test_descr, mainprog_str):
4fc7fc
+    if mainprog_str:
4fc7fc
+        test_descr.main_program = mainprog_str.split(';')
4fc7fc
+    for s in test_descr.main_program:
4fc7fc
+        m = re.match(r"^([+\-%^@])([0-9a-zA-Z]+)$", s)
4fc7fc
+        if not m:
4fc7fc
+            error("'%s' is not recognized main program operation" % (s))
4fc7fc
+        opr = m.group(1)
4fc7fc
+        obj = m.group(2)
4fc7fc
+        if not obj in test_descr.objs:
4fc7fc
+            test_descr.objs.append(obj)
4fc7fc
+        if opr == '%' or opr == '@':
4fc7fc
+            test_descr.add_callrefs(['#'], [obj])
4fc7fc
+    # We have a main program specified, turn this off
4fc7fc
+    test_descr.main_program_default_deps = False
4fc7fc
+
4fc7fc
+# For(a1 a2 b1-12) object set descriptions, expand into an object list
4fc7fc
+def expand_object_set_string(descr_str):
4fc7fc
+    obj_list = []
4fc7fc
+    descr_list = descr_str.split()
4fc7fc
+    for descr in descr_list:
4fc7fc
+        m = re.match(r"^([a-zA-Z][0-9a-zA-Z]*)(-[0-9]+)?$", descr)
4fc7fc
+        if not m:
4fc7fc
+            error("'%s' is not a valid object set description" % (descr))
4fc7fc
+        obj = m.group(1)
4fc7fc
+        idx_end = m.group(2)
4fc7fc
+        if not idx_end:
4fc7fc
+            if not obj in obj_list:
4fc7fc
+                obj_list.append(obj)
4fc7fc
+        else:
4fc7fc
+            idx_end = int(idx_end[1:])
4fc7fc
+            m = re.match(r"^([0-9a-zA-Z][a-zA-Z]*)([0-9]+)$", obj)
4fc7fc
+            if not m:
4fc7fc
+                error("object description '%s' is malformed" % (obj))
4fc7fc
+            obj_name = m.group(1)
4fc7fc
+            idx_start = int(m.group (2))
4fc7fc
+            if idx_start > idx_end:
4fc7fc
+                error("index range %s-%s invalid" % (idx_start, idx_end))
4fc7fc
+            for i in range(idx_start, idx_end + 1):
4fc7fc
+                o = obj_name + str(i)
4fc7fc
+                if not o in obj_list:
4fc7fc
+                    obj_list.append(o)
4fc7fc
+    return obj_list
4fc7fc
+
4fc7fc
+# Lexer for tokens
4fc7fc
+tokenspec = [ ("SONAME",   r"soname\(([0-9a-zA-Z{}]+)\)=([0-9a-zA-Z]+)"),
4fc7fc
+              ("OBJ",      r"([0-9a-zA-Z]+)"),
4fc7fc
+              ("DEP",      r"->"),
4fc7fc
+              ("CALLREF",  r"=>"),
4fc7fc
+              ("OBJSET",   r"\[([0-9a-zA-Z]+)\]"),
4fc7fc
+              ("OBJSET2",  r"\(([0-9a-zA-Z \-]+)\)"),
4fc7fc
+              ("OBJSET3",  r"\*"),
4fc7fc
+              ("PROG",     r"{([0-9a-zA-Z;+^\-%@]*)}"),
4fc7fc
+              ("PERMUTE",  r"!"),
4fc7fc
+              ("SEMICOL",  r";"),
4fc7fc
+              ("ERROR",    r".") ]
4fc7fc
+tok_re = '|'.join('(?P<%s>%s)' % pair for pair in tokenspec)
4fc7fc
+
4fc7fc
+# Main line parser of description language
4fc7fc
+def parse_description_string(t, descr_str):
4fc7fc
+    # State used when parsing dependencies
4fc7fc
+    curr_objs = []
4fc7fc
+    in_dep = False
4fc7fc
+    in_callref = False
4fc7fc
+    def clear_dep_state():
4fc7fc
+        nonlocal in_dep, in_callref
4fc7fc
+        in_dep = in_callref = False
4fc7fc
+
4fc7fc
+    for m in re.finditer(tok_re, descr_str):
4fc7fc
+        kind = m.lastgroup
4fc7fc
+        value = m.group()
4fc7fc
+        if kind == "SONAME":
4fc7fc
+            s = re.match(r"soname\(([0-9a-zA-Z{}]+)\)=([0-9a-zA-Z]+)", value)
4fc7fc
+            obj = s.group(1)
4fc7fc
+            val = s.group(2)
4fc7fc
+            if obj == "{}":
4fc7fc
+                if '#' in t.soname_map:
4fc7fc
+                    error("soname of main program already set")
4fc7fc
+                # Adjust to internal name
4fc7fc
+                obj = '#'
4fc7fc
+            else:
4fc7fc
+                if re.match(r"[{}]", obj):
4fc7fc
+                    error("invalid object name '%s'" % (obj))
4fc7fc
+                if not obj in t.objs:
4fc7fc
+                    error("'%s' is not name of already defined object" % (obj))
4fc7fc
+                if obj in t.soname_map:
4fc7fc
+                    error("'%s' already has soname of '%s' set"
4fc7fc
+                          % (obj, t.soname_map[obj]))
4fc7fc
+            t.soname_map[obj] = val
4fc7fc
+
4fc7fc
+        elif kind == "OBJ":
4fc7fc
+            if in_dep:
4fc7fc
+                t.add_deps(curr_objs, [value])
4fc7fc
+            elif in_callref:
4fc7fc
+                t.add_callrefs(curr_objs, [value])
4fc7fc
+            clear_dep_state()
4fc7fc
+            curr_objs = [value]
4fc7fc
+            if not value in t.objs:
4fc7fc
+                t.objs.append(value)
4fc7fc
+
4fc7fc
+        elif kind == "OBJSET":
4fc7fc
+            objset = value[1:len(value)-1]
4fc7fc
+            if in_dep:
4fc7fc
+                t.add_deps(curr_objs, list (objset))
4fc7fc
+            elif in_callref:
4fc7fc
+                t.add_callrefs(curr_objs, list (objset))
4fc7fc
+            clear_dep_state()
4fc7fc
+            curr_objs = list(objset)
4fc7fc
+            for o in list(objset):
4fc7fc
+                if not o in t.objs:
4fc7fc
+                    t.objs.append(o)
4fc7fc
+
4fc7fc
+        elif kind == "OBJSET2":
4fc7fc
+            descr_str = value[1:len(value)-1]
4fc7fc
+            descr_str.strip()
4fc7fc
+            objs = expand_object_set_string(descr_str)
4fc7fc
+            if not objs:
4fc7fc
+                error("empty object set '%s'" % (value))
4fc7fc
+            if in_dep:
4fc7fc
+                t.add_deps(curr_objs, objs)
4fc7fc
+            elif in_callref:
4fc7fc
+                t.add_callrefs(curr_objs, objs)
4fc7fc
+            clear_dep_state()
4fc7fc
+            curr_objs = objs
4fc7fc
+            for o in objs:
4fc7fc
+                if not o in t.objs:
4fc7fc
+                    t.objs.append(o)
4fc7fc
+
4fc7fc
+        elif kind == "OBJSET3":
4fc7fc
+            if in_dep:
4fc7fc
+                t.add_deps(curr_objs, ['*'])
4fc7fc
+            elif in_callref:
4fc7fc
+                t.add_callrefs(curr_objs, ['*'])
4fc7fc
+            else:
4fc7fc
+                error("non-dependence target set '*' can only be used "
4fc7fc
+                      "as target of ->/=> operations")
4fc7fc
+            clear_dep_state()
4fc7fc
+            curr_objs = ['*']
4fc7fc
+
4fc7fc
+        elif kind == "PERMUTE":
4fc7fc
+            if in_dep or in_callref:
4fc7fc
+                error("syntax error, permute operation invalid here")
4fc7fc
+            if not curr_objs:
4fc7fc
+                error("syntax error, no objects to permute here")
4fc7fc
+
4fc7fc
+            for obj in curr_objs:
4fc7fc
+                if not obj in t.dep_permutations:
4fc7fc
+                    # Signal this object has permuted dependencies
4fc7fc
+                    t.dep_permutations[obj] = []
4fc7fc
+
4fc7fc
+        elif kind == "PROG":
4fc7fc
+            if t.main_program:
4fc7fc
+                error("cannot have more than one main program")
4fc7fc
+            if in_dep:
4fc7fc
+                error("objects cannot have dependency on main program")
4fc7fc
+            if in_callref:
4fc7fc
+                # TODO: A DSO can resolve to a symbol in the main binary,
4fc7fc
+                # which we syntactically allow here, but haven't yet
4fc7fc
+                # implemented.
4fc7fc
+                t.add_callrefs(curr_objs, ["#"])
4fc7fc
+            process_main_program(t, value[1:len(value)-1])
4fc7fc
+            clear_dep_state()
4fc7fc
+            curr_objs = ["#"]
4fc7fc
+
4fc7fc
+        elif kind == "DEP":
4fc7fc
+            if in_dep or in_callref:
4fc7fc
+                error("syntax error, multiple contiguous ->,=> operations")
4fc7fc
+            if '*' in curr_objs:
4fc7fc
+                error("non-dependence target set '*' can only be used "
4fc7fc
+                      "as target of ->/=> operations")
4fc7fc
+            in_dep = True
4fc7fc
+
4fc7fc
+        elif kind == "CALLREF":
4fc7fc
+            if in_dep or in_callref:
4fc7fc
+                error("syntax error, multiple contiguous ->,=> operations")
4fc7fc
+            if '*' in curr_objs:
4fc7fc
+                error("non-dependence target set '*' can only be used "
4fc7fc
+                      "as target of ->/=> operations")
4fc7fc
+            in_callref = True
4fc7fc
+
4fc7fc
+        elif kind == "SEMICOL":
4fc7fc
+            curr_objs = []
4fc7fc
+            clear_dep_state()
4fc7fc
+
4fc7fc
+        else:
4fc7fc
+            error("unknown token '%s'" % (value))
4fc7fc
+    return t
4fc7fc
+
4fc7fc
+# Main routine to process each testcase description
4fc7fc
+def process_testcase(t):
4fc7fc
+    global objpfx
4fc7fc
+    assert t.test_name
4fc7fc
+
4fc7fc
+    base_test_name = t.test_name
4fc7fc
+    test_subdir = base_test_name + "-dir"
4fc7fc
+    testpfx = objpfx + test_subdir + "/"
4fc7fc
+
4fc7fc
+    if not os.path.exists(testpfx):
4fc7fc
+        os.mkdir(testpfx)
4fc7fc
+
4fc7fc
+    def find_objs_not_depended_on(t):
4fc7fc
+        objs_not_depended_on = []
4fc7fc
+        for obj in t.objs:
4fc7fc
+            skip = False
4fc7fc
+            for r in t.deps.items():
4fc7fc
+                if obj in r[1]:
4fc7fc
+                    skip = True
4fc7fc
+                    break
4fc7fc
+            if not skip:
4fc7fc
+                objs_not_depended_on.append(obj)
4fc7fc
+        return objs_not_depended_on
4fc7fc
+
4fc7fc
+    non_dep_tgt_objs = find_objs_not_depended_on(t)
4fc7fc
+    for obj in t.objs:
4fc7fc
+        if obj in t.deps:
4fc7fc
+            deps = t.deps[obj]
4fc7fc
+            if '*' in deps:
4fc7fc
+                t.deps[obj].remove('*')
4fc7fc
+                t.add_deps([obj], non_dep_tgt_objs)
4fc7fc
+        if obj in t.callrefs:
4fc7fc
+            deps = t.callrefs[obj]
4fc7fc
+            if '*' in deps:
4fc7fc
+                t.deps[obj].remove('*')
4fc7fc
+                t.add_callrefs([obj], non_dep_tgt_objs)
4fc7fc
+    if "#" in t.deps:
4fc7fc
+        deps = t.deps["#"]
4fc7fc
+        if '*' in deps:
4fc7fc
+            t.deps["#"].remove('*')
4fc7fc
+            t.add_deps(["#"], non_dep_tgt_objs)
4fc7fc
+
4fc7fc
+    # If no main program was specified in dependency description, make a
4fc7fc
+    # default main program with deps pointing to all DSOs which are not
4fc7fc
+    # depended by another DSO.
4fc7fc
+    if t.main_program_default_deps:
4fc7fc
+        main_deps = non_dep_tgt_objs
4fc7fc
+        if not main_deps:
4fc7fc
+            error("no objects for default main program to point "
4fc7fc
+                  "dependency to(all objects strongly connected?)")
4fc7fc
+        t.add_deps(["#"], main_deps)
4fc7fc
+
4fc7fc
+    # Some debug output
4fc7fc
+    if cmdlineargs.debug_output:
4fc7fc
+        print("Testcase: %s" % (t.test_name))
4fc7fc
+        print("All objects: %s" % (t.objs))
4fc7fc
+        print("--- Static link dependencies ---")
4fc7fc
+        for r in t.deps.items():
4fc7fc
+            print("%s -> %s" % (r[0], r[1]))
4fc7fc
+        print("--- Objects whose dependencies are to be permuted ---")
4fc7fc
+        for r in t.dep_permutations.items():
4fc7fc
+            print("%s" % (r[0]))
4fc7fc
+        print("--- Call reference dependencies ---")
4fc7fc
+        for r in t.callrefs.items():
4fc7fc
+            print("%s => %s" % (r[0], r[1]))
4fc7fc
+        print("--- main program ---")
4fc7fc
+        print(t.main_program)
4fc7fc
+
4fc7fc
+    # Main testcase generation routine, does Makefile fragment generation,
4fc7fc
+    # testcase source generation, and if --build specified builds testcase.
4fc7fc
+    def generate_testcase(test_descr, test_suffix):
4fc7fc
+
4fc7fc
+        test_name = test_descr.test_name + test_suffix
4fc7fc
+
4fc7fc
+        # Print out needed Makefile fragments for use in glibc/elf/Makefile.
4fc7fc
+        module_names = ""
4fc7fc
+        for o in test_descr.objs:
4fc7fc
+            module_names += " " + test_subdir + "/" + test_name + "-" + o
4fc7fc
+        makefile.write("modules-names +=%s\n" % (module_names))
4fc7fc
+
4fc7fc
+        # Depth-first traversal, executing FN(OBJ) in post-order
4fc7fc
+        def dfs(t, fn):
4fc7fc
+            def dfs_rec(obj, fn, obj_visited):
4fc7fc
+                if obj in obj_visited:
4fc7fc
+                    return
4fc7fc
+                obj_visited[obj] = True
4fc7fc
+                if obj in t.deps:
4fc7fc
+                    for dep in t.deps[obj]:
4fc7fc
+                        dfs_rec(dep, fn, obj_visited)
4fc7fc
+                fn(obj)
4fc7fc
+
4fc7fc
+            obj_visited = {}
4fc7fc
+            for obj in t.objs:
4fc7fc
+                dfs_rec(obj, fn, obj_visited)
4fc7fc
+
4fc7fc
+        # Generate link dependencies for all DSOs, done in a DFS fashion.
4fc7fc
+        # Usually this doesn't need to be this complex, just listing the direct
4fc7fc
+        # dependencies is enough.  However to support creating circular
4fc7fc
+        # dependency situations, traversing it by DFS and tracking processing
4fc7fc
+        # status is the natural way to do it.
4fc7fc
+        obj_processed = {}
4fc7fc
+        fake_created = {}
4fc7fc
+        def gen_link_deps(obj):
4fc7fc
+            if obj in test_descr.deps:
4fc7fc
+                dso = test_subdir + "/" + test_name + "-" + obj + ".so"
4fc7fc
+                dependencies = ""
4fc7fc
+                for dep in test_descr.deps[obj]:
4fc7fc
+                    if dep in obj_processed:
4fc7fc
+                        depstr = (" $(objpfx)" + test_subdir + "/"
4fc7fc
+                                  + test_name + "-" + dep + ".so")
4fc7fc
+                    else:
4fc7fc
+                        # A circular dependency is satisfied by making a
4fc7fc
+                        # fake DSO tagged with the correct SONAME
4fc7fc
+                        depstr = (" $(objpfx)" + test_subdir + "/"
4fc7fc
+                                  + test_name + "-" + dep + ".FAKE.so")
4fc7fc
+                        # Create empty C file and Makefile fragments for fake
4fc7fc
+                        # object.  This only needs to be done at most once for
4fc7fc
+                        # an object name.
4fc7fc
+                        if not dep in fake_created:
4fc7fc
+                            f = open(testpfx + test_name + "-" + dep
4fc7fc
+                                     + ".FAKE.c", "w")
4fc7fc
+                            f.write(" \n")
4fc7fc
+                            f.close()
4fc7fc
+                            # Generate rule to create fake object
4fc7fc
+                            makefile.write \
4fc7fc
+                                ("LDFLAGS-%s = -Wl,--no-as-needed "
4fc7fc
+                                 "-Wl,-soname=%s\n"
4fc7fc
+                                 % (test_name + "-" + dep + ".FAKE.so",
4fc7fc
+                                    ("$(objpfx)" + test_subdir + "/"
4fc7fc
+                                     + test_name + "-" + dep + ".so")))
4fc7fc
+                            makefile.write \
4fc7fc
+                                ("modules-names += %s\n"
4fc7fc
+                                 % (test_subdir + "/"
4fc7fc
+                                    + test_name + "-" + dep + ".FAKE"))
4fc7fc
+                            fake_created[dep] = True
4fc7fc
+                    dependencies += depstr
4fc7fc
+                makefile.write("$(objpfx)%s:%s\n" % (dso, dependencies))
4fc7fc
+            # Mark obj as processed
4fc7fc
+            obj_processed[obj] = True
4fc7fc
+
4fc7fc
+        dfs(test_descr, gen_link_deps)
4fc7fc
+
4fc7fc
+        # Print LDFLAGS-* and *-no-z-defs
4fc7fc
+        for o in test_descr.objs:
4fc7fc
+            dso = test_name + "-" + o + ".so"
4fc7fc
+            ldflags = "-Wl,--no-as-needed"
4fc7fc
+            if o in test_descr.soname_map:
4fc7fc
+                soname = ("$(objpfx)" + test_subdir + "/"
4fc7fc
+                          + test_name + "-"
4fc7fc
+                          + test_descr.soname_map[o] + ".so")
4fc7fc
+                ldflags += (" -Wl,-soname=" + soname)
4fc7fc
+            makefile.write("LDFLAGS-%s = %s\n" % (dso, ldflags))
4fc7fc
+            if o in test_descr.callrefs:
4fc7fc
+                makefile.write("%s-no-z-defs = yes\n" % (dso))
4fc7fc
+
4fc7fc
+        # Print dependencies for main test program.
4fc7fc
+        depstr = ""
4fc7fc
+        if '#' in test_descr.deps:
4fc7fc
+            for o in test_descr.deps['#']:
4fc7fc
+                depstr += (" $(objpfx)" + test_subdir + "/"
4fc7fc
+                           + test_name + "-" + o + ".so")
4fc7fc
+        makefile.write("$(objpfx)%s/%s:%s\n" % (test_subdir, test_name, depstr))
4fc7fc
+        ldflags = "-Wl,--no-as-needed"
4fc7fc
+        if '#' in test_descr.soname_map:
4fc7fc
+            soname = ("$(objpfx)" + test_subdir + "/"
4fc7fc
+                      + test_name + "-"
4fc7fc
+                      + test_descr.soname_map['#'] + ".so")
4fc7fc
+            ldflags += (" -Wl,-soname=" + soname)
4fc7fc
+        makefile.write("LDFLAGS-%s = %s\n" % (test_name, ldflags))
4fc7fc
+
4fc7fc
+        not_depended_objs = find_objs_not_depended_on(test_descr)
4fc7fc
+        if not_depended_objs:
4fc7fc
+            depstr = ""
4fc7fc
+            for dep in not_depended_objs:
4fc7fc
+                depstr += (" $(objpfx)" + test_subdir + "/"
4fc7fc
+                           + test_name + "-" + dep + ".so")
4fc7fc
+            makefile.write("$(objpfx)%s.out:%s\n" % (base_test_name, depstr))
4fc7fc
+
4fc7fc
+        # Add main executable to test-srcs
4fc7fc
+        makefile.write("test-srcs += %s/%s\n" % (test_subdir, test_name))
4fc7fc
+        # Add dependency on main executable of test
4fc7fc
+        makefile.write("$(objpfx)%s.out: $(objpfx)%s/%s\n"
4fc7fc
+                        % (base_test_name, test_subdir, test_name))
4fc7fc
+
4fc7fc
+        for r in test_descr.expected_outputs.items():
4fc7fc
+            tunable_options = []
4fc7fc
+            specific_tunable = r[0]
4fc7fc
+            xfail = r[1][1]
4fc7fc
+            if specific_tunable != "":
4fc7fc
+                tunable_options = [specific_tunable]
4fc7fc
+            else:
4fc7fc
+                tunable_options = default_tunable_options
4fc7fc
+                if not tunable_options:
4fc7fc
+                    tunable_options = [""]
4fc7fc
+
4fc7fc
+            for tunable in tunable_options:
4fc7fc
+                tunable_env = ""
4fc7fc
+                tunable_sfx = ""
4fc7fc
+                exp_tunable_sfx = ""
4fc7fc
+                if tunable:
4fc7fc
+                    tunable_env = "GLIBC_TUNABLES=%s " % tunable
4fc7fc
+                    tunable_sfx = "-" + tunable.replace("=","_")
4fc7fc
+                if specific_tunable:
4fc7fc
+                    tunable_sfx = "-" + specific_tunable.replace("=","_")
4fc7fc
+                    exp_tunable_sfx = tunable_sfx
4fc7fc
+                tunable_descr = ("(%s)" % tunable_env.strip()
4fc7fc
+                                 if tunable_env else "")
4fc7fc
+                # Write out fragment of shell script for this single test.
4fc7fc
+                test_descr.sh.write \
4fc7fc
+                    ("%s${test_wrapper_env} ${run_program_env} \\\n"
4fc7fc
+                     "${common_objpfx}support/test-run-command \\\n"
4fc7fc
+                     "${common_objpfx}elf/ld.so \\\n"
4fc7fc
+                     "--library-path ${common_objpfx}elf/%s:"
4fc7fc
+                     "${common_objpfx}elf:${common_objpfx}.:"
4fc7fc
+                     "${common_objpfx}dlfcn \\\n"
4fc7fc
+                     "${common_objpfx}elf/%s/%s > \\\n"
4fc7fc
+                     "  ${common_objpfx}elf/%s/%s%s.output\n"
4fc7fc
+                     % (tunable_env ,test_subdir,
4fc7fc
+                        test_subdir, test_name, test_subdir, test_name,
4fc7fc
+                        tunable_sfx))
4fc7fc
+                # Generate a run of each test and compare with expected out
4fc7fc
+                test_descr.sh.write \
4fc7fc
+                    ("if [ $? -ne 0 ]; then\n"
4fc7fc
+                     "  echo '%sFAIL: %s%s execution test'\n"
4fc7fc
+                     "  something_failed=true\n"
4fc7fc
+                     "else\n"
4fc7fc
+                     "  diff -wu ${common_objpfx}elf/%s/%s%s.output \\\n"
4fc7fc
+                     "           ${common_objpfx}elf/%s/%s%s.exp\n"
4fc7fc
+                     "  if [ $? -ne 0 ]; then\n"
4fc7fc
+                     "    echo '%sFAIL: %s%s expected output comparison'\n"
4fc7fc
+                     "    something_failed=true\n"
4fc7fc
+                     "  fi\n"
4fc7fc
+                     "fi\n"
4fc7fc
+                     % (("X" if xfail else ""), test_name, tunable_descr,
4fc7fc
+                        test_subdir, test_name, tunable_sfx,
4fc7fc
+                        test_subdir, base_test_name, exp_tunable_sfx,
4fc7fc
+                        ("X" if xfail else ""), test_name, tunable_descr))
4fc7fc
+
4fc7fc
+        # Generate C files according to dependency and calling relations from
4fc7fc
+        # description string.
4fc7fc
+        for obj in test_descr.objs:
4fc7fc
+            src_name = test_name + "-" + obj + ".c"
4fc7fc
+            f = open(testpfx + src_name, "w")
4fc7fc
+            if obj in test_descr.callrefs:
4fc7fc
+                called_objs = test_descr.callrefs[obj]
4fc7fc
+                for callee in called_objs:
4fc7fc
+                    f.write("extern void fn_%s (void);\n" % (callee))
4fc7fc
+            if len(obj) == 1:
4fc7fc
+                f.write("extern int putchar(int);\n")
4fc7fc
+                f.write("static void __attribute__((constructor)) " +
4fc7fc
+                         "init(void){putchar('%s');putchar('>');}\n" % (obj))
4fc7fc
+                f.write("static void __attribute__((destructor)) " +
4fc7fc
+                         "fini(void){putchar('<');putchar('%s');}\n" % (obj))
4fc7fc
+            else:
4fc7fc
+                f.write('extern int printf(const char *, ...);\n')
4fc7fc
+                f.write('static void __attribute__((constructor)) ' +
4fc7fc
+                         'init(void){printf("%s>");}\n' % (obj))
4fc7fc
+                f.write('static void __attribute__((destructor)) ' +
4fc7fc
+                         'fini(void){printf("<%s");}\n' % (obj))
4fc7fc
+            if obj in test_descr.callrefs:
4fc7fc
+                called_objs = test_descr.callrefs[obj]
4fc7fc
+                if len(obj) != 1:
4fc7fc
+                    f.write("extern int putchar(int);\n")
4fc7fc
+                f.write("void fn_%s (void) {\n" % (obj))
4fc7fc
+                if len(obj) == 1:
4fc7fc
+                    f.write("  putchar ('%s');\n" % (obj));
4fc7fc
+                    f.write("  putchar ('(');\n");
4fc7fc
+                else:
4fc7fc
+                    f.write('  printf ("%s(");\n' % (obj));
4fc7fc
+                for callee in called_objs:
4fc7fc
+                    f.write("  fn_%s ();\n" % (callee))
4fc7fc
+                f.write("  putchar (')');\n");
4fc7fc
+                f.write("}\n")
4fc7fc
+            else:
4fc7fc
+                for callref in test_descr.callrefs.items():
4fc7fc
+                    if obj in callref[1]:
4fc7fc
+                        if len(obj) == 1:
4fc7fc
+                            # We need to declare printf here in this case.
4fc7fc
+                            f.write('extern int printf(const char *, ...);\n')
4fc7fc
+                        f.write("void fn_%s (void) {\n" % (obj))
4fc7fc
+                        f.write('  printf ("%s()");\n' % (obj))
4fc7fc
+                        f.write("}\n")
4fc7fc
+                        break
4fc7fc
+            f.close()
4fc7fc
+
4fc7fc
+        # Open C file for writing main program
4fc7fc
+        f = open(testpfx + test_name + ".c", "w")
4fc7fc
+
4fc7fc
+        # if there are some operations in main(), it means we need -ldl
4fc7fc
+        f.write("#include <stdio.h>\n")
4fc7fc
+        f.write("#include <stdlib.h>\n")
4fc7fc
+        f.write("#include <dlfcn.h>\n")
4fc7fc
+        for s in test_descr.main_program:
4fc7fc
+            if s[0] == '@':
4fc7fc
+                f.write("extern void fn_%s (void);\n" % (s[1:]));
4fc7fc
+        f.write("int main (void) {\n")
4fc7fc
+        f.write("  putchar('{');\n")
4fc7fc
+
4fc7fc
+        # Helper routine for generating sanity checking code.
4fc7fc
+        def put_fail_check(fail_cond, action_desc):
4fc7fc
+            f.write('  if (%s) { printf ("\\n%s failed: %%s\\n", '
4fc7fc
+                     'dlerror()); exit (1);}\n' % (fail_cond, action_desc))
4fc7fc
+        i = 0
4fc7fc
+        while i < len(test_descr.main_program):
4fc7fc
+            s = test_descr.main_program[i]
4fc7fc
+            obj = s[1:]
4fc7fc
+            dso = test_name + "-" + obj
4fc7fc
+            if s[0] == '+' or s[0] == '^':
4fc7fc
+                if s[0] == '+':
4fc7fc
+                    dlopen_flags = "RTLD_LAZY|RTLD_GLOBAL"
4fc7fc
+                    f.write("  putchar('+');\n");
4fc7fc
+                else:
4fc7fc
+                    dlopen_flags = "RTLD_LAZY"
4fc7fc
+                    f.write("  putchar(':');\n");
4fc7fc
+                if len(obj) == 1:
4fc7fc
+                    f.write("  putchar('%s');\n" % (obj));
4fc7fc
+                else:
4fc7fc
+                    f.write('  printf("%s");\n' % (obj));
4fc7fc
+                f.write("  putchar('[');\n");
4fc7fc
+                f.write('  void *%s = dlopen ("%s.so", %s);\n'
4fc7fc
+                         % (obj, dso, dlopen_flags))
4fc7fc
+                put_fail_check("!%s" % (obj),
4fc7fc
+                                "%s.so dlopen" % (dso))
4fc7fc
+                f.write("  putchar(']');\n");
4fc7fc
+            elif s[0] == '-':
4fc7fc
+                f.write("  putchar('-');\n");
4fc7fc
+                if len(obj) == 1:
4fc7fc
+                    f.write("  putchar('%s');\n" % (obj));
4fc7fc
+                else:
4fc7fc
+                    f.write('  printf("%s");\n' % (obj));
4fc7fc
+                f.write("  putchar('[');\n");
4fc7fc
+                put_fail_check("dlclose (%s) != 0" % (obj),
4fc7fc
+                                "%s.so dlclose" % (dso))
4fc7fc
+                f.write("  putchar(']');\n");
4fc7fc
+            elif s[0] == '%':
4fc7fc
+                f.write("  putchar('%');\n");
4fc7fc
+                f.write('  void (*fn_%s)(void) = dlsym (%s, "fn_%s");\n'
4fc7fc
+                         % (obj, obj, obj))
4fc7fc
+                put_fail_check("!fn_%s" % (obj),
4fc7fc
+                                "dlsym(fn_%s) from %s.so" % (obj, dso))
4fc7fc
+                f.write("  fn_%s ();\n" % (obj))
4fc7fc
+            elif s[0] == '@':
4fc7fc
+                f.write("  putchar('@');\n");
4fc7fc
+                f.write("  fn_%s ();\n" % (obj))
4fc7fc
+            f.write("  putchar(';');\n");
4fc7fc
+            i += 1
4fc7fc
+        f.write("  putchar('}');\n")
4fc7fc
+        f.write("  return 0;\n")
4fc7fc
+        f.write("}\n")
4fc7fc
+        f.close()
4fc7fc
+
4fc7fc
+        # --build option processing: build generated sources using 'build_gcc'
4fc7fc
+        if cmdlineargs.build:
4fc7fc
+            # Helper routine to run a shell command, for running GCC below
4fc7fc
+            def run_cmd(args):
4fc7fc
+                cmd = str.join(' ', args)
4fc7fc
+                if cmdlineargs.debug_output:
4fc7fc
+                    print(cmd)
4fc7fc
+                p = subprocess.Popen(args)
4fc7fc
+                p.wait()
4fc7fc
+                if p.returncode != 0:
4fc7fc
+                    error("error running command: %s" % (cmd))
4fc7fc
+
4fc7fc
+            # Compile individual .os files
4fc7fc
+            for obj in test_descr.objs:
4fc7fc
+                src_name = test_name + "-" + obj + ".c"
4fc7fc
+                obj_name = test_name + "-" + obj + ".os"
4fc7fc
+                run_cmd([build_gcc, "-c", "-fPIC", testpfx + src_name,
4fc7fc
+                          "-o", testpfx + obj_name])
4fc7fc
+
4fc7fc
+            obj_processed = {}
4fc7fc
+            fake_created = {}
4fc7fc
+            # Function to create <test_name>-<obj>.so
4fc7fc
+            def build_dso(obj):
4fc7fc
+                obj_name = test_name + "-" + obj + ".os"
4fc7fc
+                dso_name = test_name + "-" + obj + ".so"
4fc7fc
+                deps = []
4fc7fc
+                if obj in test_descr.deps:
4fc7fc
+                    for dep in test_descr.deps[obj]:
4fc7fc
+                        if dep in obj_processed:
4fc7fc
+                            deps.append(dep)
4fc7fc
+                        else:
4fc7fc
+                            deps.append(dep + ".FAKE")
4fc7fc
+                            if not dep in fake_created:
4fc7fc
+                                base_name = testpfx + test_name + "-" + dep
4fc7fc
+                                cmd = [build_gcc, "-Wl,--no-as-needed",
4fc7fc
+                                       ("-Wl,-soname=" + base_name + ".so"),
4fc7fc
+                                       "-shared", base_name + ".FAKE.c",
4fc7fc
+                                       "-o", base_name + ".FAKE.so"]
4fc7fc
+                                run_cmd(cmd)
4fc7fc
+                                fake_created[dep] = True
4fc7fc
+                dso_deps = map(lambda d: testpfx + test_name + "-" + d + ".so",
4fc7fc
+                               deps)
4fc7fc
+                cmd = [build_gcc, "-shared", "-o", testpfx + dso_name,
4fc7fc
+                       testpfx + obj_name, "-Wl,--no-as-needed"]
4fc7fc
+                if obj in test_descr.soname_map:
4fc7fc
+                    soname = ("-Wl,-soname=" + testpfx + test_name + "-"
4fc7fc
+                              + test_descr.soname_map[obj] + ".so")
4fc7fc
+                    cmd += [soname]
4fc7fc
+                cmd += list(dso_deps)
4fc7fc
+                run_cmd(cmd)
4fc7fc
+                obj_processed[obj] = True
4fc7fc
+
4fc7fc
+            # Build all DSOs, this needs to be in topological dependency order,
4fc7fc
+            # or link will fail
4fc7fc
+            dfs(test_descr, build_dso)
4fc7fc
+
4fc7fc
+            # Build main program
4fc7fc
+            deps = []
4fc7fc
+            if '#' in test_descr.deps:
4fc7fc
+                deps = test_descr.deps['#']
4fc7fc
+            main_deps = map(lambda d: testpfx + test_name + "-" + d + ".so",
4fc7fc
+                            deps)
4fc7fc
+            cmd = [build_gcc, "-Wl,--no-as-needed", "-o", testpfx + test_name,
4fc7fc
+                   testpfx + test_name + ".c", "-L%s" % (os.getcwd()),
4fc7fc
+                   "-Wl,-rpath-link=%s" % (os.getcwd())]
4fc7fc
+            if '#' in test_descr.soname_map:
4fc7fc
+                soname = ("-Wl,-soname=" + testpfx + test_name + "-"
4fc7fc
+                          + test_descr.soname_map['#'] + ".so")
4fc7fc
+                cmd += [soname]
4fc7fc
+            cmd += list(main_deps)
4fc7fc
+            run_cmd(cmd)
4fc7fc
+
4fc7fc
+    # Check if we need to enumerate permutations of dependencies
4fc7fc
+    need_permutation_processing = False
4fc7fc
+    if t.dep_permutations:
4fc7fc
+        # Adjust dep_permutations into map of object -> dependency permutations
4fc7fc
+        for r in t.dep_permutations.items():
4fc7fc
+            obj = r[0]
4fc7fc
+            if obj in t.deps and len(t.deps[obj]) > 1:
4fc7fc
+                deps = t.deps[obj]
4fc7fc
+                t.dep_permutations[obj] = list(itertools.permutations (deps))
4fc7fc
+                need_permutation_processing = True
4fc7fc
+
4fc7fc
+    def enum_permutations(t, perm_list):
4fc7fc
+        test_subindex = 1
4fc7fc
+        curr_perms = []
4fc7fc
+        def enum_permutations_rec(t, perm_list):
4fc7fc
+            nonlocal test_subindex, curr_perms
4fc7fc
+            if len(perm_list) >= 1:
4fc7fc
+                curr = perm_list[0]
4fc7fc
+                obj = curr[0]
4fc7fc
+                perms = curr[1]
4fc7fc
+                if not perms:
4fc7fc
+                    # This may be an empty list if no multiple dependencies to
4fc7fc
+                    # permute were found, skip to next in this case
4fc7fc
+                    enum_permutations_rec(t, perm_list[1:])
4fc7fc
+                else:
4fc7fc
+                    for deps in perms:
4fc7fc
+                        t.deps[obj] = deps
4fc7fc
+                        permstr = "" if obj == "#" else obj + "_"
4fc7fc
+                        permstr += str.join('', deps)
4fc7fc
+                        curr_perms.append(permstr)
4fc7fc
+                        enum_permutations_rec(t, perm_list[1:])
4fc7fc
+                        curr_perms = curr_perms[0:len(curr_perms)-1]
4fc7fc
+            else:
4fc7fc
+                # t.deps is now instantiated with one dependency order
4fc7fc
+                # permutation(across all objects that have multiple
4fc7fc
+                # permutations), now process a testcase
4fc7fc
+                generate_testcase(t, ("_" + str (test_subindex)
4fc7fc
+                                       + "-" + str.join('-', curr_perms)))
4fc7fc
+                test_subindex += 1
4fc7fc
+        enum_permutations_rec(t, perm_list)
4fc7fc
+
4fc7fc
+    # Create *.exp files with expected outputs
4fc7fc
+    for r in t.expected_outputs.items():
4fc7fc
+        sfx = ""
4fc7fc
+        if r[0] != "":
4fc7fc
+            sfx = "-" + r[0].replace("=","_")
4fc7fc
+        f = open(testpfx + t.test_name + sfx + ".exp", "w")
4fc7fc
+        (output, xfail) = r[1]
4fc7fc
+        f.write('%s' % output)
4fc7fc
+        f.close()
4fc7fc
+
4fc7fc
+    # Create header part of top-level testcase shell script, to wrap execution
4fc7fc
+    # and output comparison together.
4fc7fc
+    t.sh = open(testpfx + t.test_name + ".sh", "w")
4fc7fc
+    t.sh.write("#!/bin/sh\n")
4fc7fc
+    t.sh.write("# Test driver for %s, generated by "
4fc7fc
+                "dso-ordering-test.py\n" % (t.test_name))
4fc7fc
+    t.sh.write("common_objpfx=$1\n")
4fc7fc
+    t.sh.write("test_wrapper_env=$2\n")
4fc7fc
+    t.sh.write("run_program_env=$3\n")
4fc7fc
+    t.sh.write("something_failed=false\n")
4fc7fc
+
4fc7fc
+    # Starting part of Makefile fragment
4fc7fc
+    makefile.write("ifeq (yes,$(build-shared))\n")
4fc7fc
+
4fc7fc
+    if need_permutation_processing:
4fc7fc
+        enum_permutations(t, list (t.dep_permutations.items()))
4fc7fc
+    else:
4fc7fc
+        # We have no permutations to enumerate, just process testcase normally
4fc7fc
+        generate_testcase(t, "")
4fc7fc
+
4fc7fc
+    # If testcase is XFAIL, indicate so
4fc7fc
+    if t.xfail:
4fc7fc
+        makefile.write("test-xfail-%s = yes\n" % t.test_name)
4fc7fc
+
4fc7fc
+    # Output end part of Makefile fragment
4fc7fc
+    expected_output_files = ""
4fc7fc
+    for r in t.expected_outputs.items():
4fc7fc
+        sfx = ""
4fc7fc
+        if r[0] != "":
4fc7fc
+            sfx = "-" + r[0].replace("=","_")
4fc7fc
+        expected_output_files += " $(objpfx)%s/%s%s.exp" % (test_subdir,
4fc7fc
+                                                            t.test_name, sfx)
4fc7fc
+    makefile.write \
4fc7fc
+    ("$(objpfx)%s.out: $(objpfx)%s/%s.sh%s "
4fc7fc
+     "$(common-objpfx)support/test-run-command\n"
4fc7fc
+     % (t.test_name, test_subdir, t.test_name,
4fc7fc
+        expected_output_files))
4fc7fc
+    makefile.write("\t$(SHELL) $< $(common-objpfx) '$(test-wrapper-env)' "
4fc7fc
+                    "'$(run-program-env)' > $@; $(evaluate-test)\n")
4fc7fc
+    makefile.write("ifeq ($(run-built-tests),yes)\n")
4fc7fc
+    if t.xtest:
4fc7fc
+        makefile.write("xtests-special += $(objpfx)%s.out\n" % (t.test_name))
4fc7fc
+    else:
4fc7fc
+        makefile.write("tests-special += $(objpfx)%s.out\n" % (t.test_name))
4fc7fc
+    makefile.write("endif\n")
4fc7fc
+    makefile.write("endif\n")
4fc7fc
+
4fc7fc
+    # Write ending part of shell script generation
4fc7fc
+    t.sh.write("if $something_failed; then\n"
4fc7fc
+                "  exit 1\n"
4fc7fc
+                "else\n"
4fc7fc
+                "  echo '%sPASS: all tests for %s succeeded'\n"
4fc7fc
+                "  exit 0\n"
4fc7fc
+                "fi\n" % (("X" if t.xfail else ""),
4fc7fc
+                          t.test_name))
4fc7fc
+    t.sh.close()
4fc7fc
+
4fc7fc
+# Decription file parsing
4fc7fc
+def parse_description_file(filename):
4fc7fc
+    global default_tunable_options
4fc7fc
+    global current_input_lineno
4fc7fc
+    f = open(filename)
4fc7fc
+    if not f:
4fc7fc
+        error("cannot open description file %s" % (filename))
4fc7fc
+    descrfile_lines = f.readlines()
4fc7fc
+    t = None
4fc7fc
+    for line in descrfile_lines:
4fc7fc
+        p = re.compile(r"#.*$")
4fc7fc
+        line = p.sub("", line) # Filter out comments
4fc7fc
+        line = line.strip() # Remove excess whitespace
4fc7fc
+        current_input_lineno += 1
4fc7fc
+
4fc7fc
+        m = re.match(r"^tunable_option:\s*(.*)$", line)
4fc7fc
+        if m:
4fc7fc
+            if m.group(1) == "":
4fc7fc
+                error("tunable option cannot be empty")
4fc7fc
+            default_tunable_options.append(m.group (1))
4fc7fc
+            continue
4fc7fc
+
4fc7fc
+        m = re.match(r"^clear_tunables$", line)
4fc7fc
+        if m:
4fc7fc
+            default_tunable_options = []
4fc7fc
+            continue
4fc7fc
+
4fc7fc
+        m = re.match(r"^([^:]+):\s*(.*)$", line)
4fc7fc
+        if m:
4fc7fc
+            lhs = m.group(1)
4fc7fc
+            o = re.match(r"^output(.*)$", lhs)
4fc7fc
+            xfail = False
4fc7fc
+            if not o:
4fc7fc
+                o = re.match(r"^xfail_output(.*)$", lhs)
4fc7fc
+                if o:
4fc7fc
+                    xfail = True;
4fc7fc
+            if o:
4fc7fc
+                if not t:
4fc7fc
+                    error("output specification without testcase description")
4fc7fc
+                tsstr = ""
4fc7fc
+                if o.group(1):
4fc7fc
+                    ts = re.match(r"^\(([a-zA-Z0-9_.=]*)\)$", o.group (1))
4fc7fc
+                    if not ts:
4fc7fc
+                        error("tunable option malformed '%s'" % o.group(1))
4fc7fc
+                    tsstr = ts.group(1)
4fc7fc
+                t.expected_outputs[tsstr] = (m.group(2), xfail)
4fc7fc
+                # Any tunable option XFAILed means entire testcase
4fc7fc
+                # is XFAIL/XPASS
4fc7fc
+                t.xfail |= xfail
4fc7fc
+            else:
4fc7fc
+                if t:
4fc7fc
+                    # Starting a new test description, end and process
4fc7fc
+                    # current one.
4fc7fc
+                    process_testcase(t)
4fc7fc
+                t = TestDescr()
4fc7fc
+                x = re.match(r"^xtest\((.*)\)$", lhs)
4fc7fc
+                if x:
4fc7fc
+                    t.xtest = True
4fc7fc
+                    t.test_name = x.group(1)
4fc7fc
+                else:
4fc7fc
+                    t.test_name = lhs
4fc7fc
+                descr_string = m.group(2)
4fc7fc
+                parse_description_string(t, descr_string)
4fc7fc
+            continue
4fc7fc
+        else:
4fc7fc
+            if line:
4fc7fc
+                if not t:
4fc7fc
+                    error("no active testcase description")
4fc7fc
+                parse_description_string(t, line)
4fc7fc
+    # Process last completed test description
4fc7fc
+    if t:
4fc7fc
+        process_testcase(t)
4fc7fc
+
4fc7fc
+# Setup Makefile output to file or stdout as selected
4fc7fc
+if output_makefile:
4fc7fc
+    output_makefile_dir = os.path.dirname(output_makefile)
4fc7fc
+    if output_makefile_dir:
4fc7fc
+        os.makedirs(output_makefile_dir, exist_ok = True)
4fc7fc
+    makefile = open(output_makefile, "w")
4fc7fc
+else:
4fc7fc
+    makefile = open(sys.stdout.fileno (), "w")
4fc7fc
+
4fc7fc
+# Finally, the main top-level calling of above parsing routines.
4fc7fc
+if description_file:
4fc7fc
+    parse_description_file(description_file)
4fc7fc
+else:
4fc7fc
+    t = TestDescr()
4fc7fc
+    t.test_name = test_name
4fc7fc
+    parse_description_string(t, description)
4fc7fc
+    process_testcase(t)
4fc7fc
+
4fc7fc
+# Close Makefile fragment output
4fc7fc
+makefile.close()
4fc7fc
diff --git a/support/Depend b/support/Depend
4fc7fc
new file mode 100644
4fc7fc
index 0000000000000000..7e7d5dc67c13e669
4fc7fc
--- /dev/null
4fc7fc
+++ b/support/Depend
4fc7fc
@@ -0,0 +1 @@
4fc7fc
+elf
4fc7fc
diff --git a/support/Makefile b/support/Makefile
4fc7fc
index 7749ac24f1ac3622..636d69c4f8e7e139 100644
4fc7fc
--- a/support/Makefile
4fc7fc
+++ b/support/Makefile
4fc7fc
@@ -215,10 +215,16 @@ others-noinstall += shell-container echo-container true-container
4fc7fc
 others += $(LINKS_DSO_PROGRAM)
4fc7fc
 others-noinstall += $(LINKS_DSO_PROGRAM)
4fc7fc
 
4fc7fc
+others += test-run-command
4fc7fc
+others-static += test-run-command
4fc7fc
+others-noinstall += test-run-command
4fc7fc
+LDLIBS-test-run-command = $(libsupport)
4fc7fc
+
4fc7fc
 $(objpfx)test-container : $(libsupport)
4fc7fc
 $(objpfx)shell-container : $(libsupport)
4fc7fc
 $(objpfx)echo-container : $(libsupport)
4fc7fc
 $(objpfx)true-container : $(libsupport)
4fc7fc
+$(objpfx)test-run-command : $(libsupport) $(common-objpfx)elf/static-stubs.o
4fc7fc
 
4fc7fc
 tests = \
4fc7fc
   README-testing \
4fc7fc
diff --git a/support/support_test_main.c b/support/support_test_main.c
4fc7fc
index def84d803928176b..49e9d9c5baf776eb 100644
4fc7fc
--- a/support/support_test_main.c
4fc7fc
+++ b/support/support_test_main.c
4fc7fc
@@ -228,6 +228,18 @@ run_test_function (int argc, char **argv, const struct test_config *config)
4fc7fc
   while (wait_for_debugger)
4fc7fc
     usleep (1000);
4fc7fc
 
4fc7fc
+  if (config->run_command_mode)
4fc7fc
+    {
4fc7fc
+      /* In run-command-mode, the child process executes the command line
4fc7fc
+	 arguments as a new program.  */
4fc7fc
+      char **argv_ = xmalloc (sizeof (char *) * argc);
4fc7fc
+      memcpy (argv_, &argv[1], sizeof (char *) * (argc - 1));
4fc7fc
+      argv_[argc - 1] = NULL;
4fc7fc
+      execv (argv_[0], argv_);
4fc7fc
+      printf ("error: should not return here\n");
4fc7fc
+      exit (1);
4fc7fc
+    }
4fc7fc
+
4fc7fc
   if (config->test_function != NULL)
4fc7fc
     return config->test_function ();
4fc7fc
   else if (config->test_function_argv != NULL)
4fc7fc
diff --git a/support/test-driver.c b/support/test-driver.c
4fc7fc
index 9798f16227b9d467..93f25a99c1b9d2cb 100644
4fc7fc
--- a/support/test-driver.c
4fc7fc
+++ b/support/test-driver.c
4fc7fc
@@ -116,7 +116,9 @@ main (int argc, char **argv)
4fc7fc
 #if defined (TEST_FUNCTION) && defined (TEST_FUNCTON_ARGV)
4fc7fc
 # error TEST_FUNCTION and TEST_FUNCTION_ARGV cannot be defined at the same time
4fc7fc
 #endif
4fc7fc
-#if defined (TEST_FUNCTION)
4fc7fc
+#ifdef RUN_COMMAND_MODE
4fc7fc
+  test_config.run_command_mode = 1;
4fc7fc
+#elif defined (TEST_FUNCTION)
4fc7fc
   test_config.test_function = TEST_FUNCTION;
4fc7fc
 #elif defined (TEST_FUNCTION_ARGV)
4fc7fc
   test_config.test_function_argv = TEST_FUNCTION_ARGV;
4fc7fc
diff --git a/support/test-driver.h b/support/test-driver.h
4fc7fc
index 549179b254946390..818689ad1ae7fd8c 100644
4fc7fc
--- a/support/test-driver.h
4fc7fc
+++ b/support/test-driver.h
4fc7fc
@@ -36,6 +36,7 @@ struct test_config
4fc7fc
   int expected_signal;   /* If non-zero, expect termination by signal.  */
4fc7fc
   char no_mallopt;       /* Boolean flag to disable mallopt.  */
4fc7fc
   char no_setvbuf;       /* Boolean flag to disable setvbuf.  */
4fc7fc
+  char run_command_mode; /* Boolean flag to indicate run-command-mode.  */
4fc7fc
   const char *optstring; /* Short command line options.  */
4fc7fc
 };
4fc7fc
 
4fc7fc
diff --git a/support/test-run-command.c b/support/test-run-command.c
4fc7fc
new file mode 100644
4fc7fc
index 0000000000000000..61560d7bfb1686a8
4fc7fc
--- /dev/null
4fc7fc
+++ b/support/test-run-command.c
4fc7fc
@@ -0,0 +1,22 @@
4fc7fc
+/* Main program for test-run-command support utility.
4fc7fc
+   Copyright (C) 2021 Free Software Foundation, Inc.
4fc7fc
+   This file is part of the GNU C Library.
4fc7fc
+
4fc7fc
+   The GNU C Library is free software; you can redistribute it and/or
4fc7fc
+   modify it under the terms of the GNU Lesser General Public
4fc7fc
+   License as published by the Free Software Foundation; either
4fc7fc
+   version 2.1 of the License, or (at your option) any later version.
4fc7fc
+
4fc7fc
+   The GNU C Library is distributed in the hope that it will be useful,
4fc7fc
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
4fc7fc
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4fc7fc
+   Lesser General Public License for more details.
4fc7fc
+
4fc7fc
+   You should have received a copy of the GNU Lesser General Public
4fc7fc
+   License along with the GNU C Library; if not, see
4fc7fc
+   <https://www.gnu.org/licenses/>.  */
4fc7fc
+
4fc7fc
+/* This is basically a configuration of test-driver.c into a general
4fc7fc
+   command-line program runner.  */
4fc7fc
+#define RUN_COMMAND_MODE
4fc7fc
+#include <test-driver.c>