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