source: mainline/uspace/app/binutils/intrusive.sh@ 8a23fef

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8a23fef was fdf97f6, checked in by Vojtech Horky <vojtechhorky@…>, 12 years ago

Libposix functions are without posix_ prefix

Prior this commit, libposix headers declared all functions as posix_*
and used macros to rename e.g. strncpy to posix_strncpy in all (ported)
sources.

After this change, libposix headers look as normal POSIX compliant headers
(well, almost) and no renaming is done in the source codei (of the ported
applications). Instead, the renaming is done at object files level to
bypass weird problems that are bound to happen if you use macros.

The scheme is following. libposix headers use special macro to declare
the names. When included from outside, the functions have their normal
(standard) names. When included from the libposix sources, posix_ prefix
is added. Thus, when libposix is compiled and linked, it contains the
posix_* naming while compiling of ported software uses the normal
non-prefixed versions. This way the posix_* can use HelenOS libc without
any problem. Before linking, the posix_* prefix is removed from all
symbols and special prefix helenos_libc_ is added to all functions
that exists in our (HelenOS) libc and its name clashes with the POSIX
one.

The following happens, for example, to the open() function that exists in
both libposix and in libc.

  • Headers and sources of libc are left intact.
  • Copy of libc.a is made and to all clashing functions is added the helenos_libc prefix. This library is called libc4posix.a.
  • POSIX_DEF(open)(const char *) is used in libposix headers. This macro expands to plain open when included from the "outside world". But it expands to posix_open when included from libposix sources.
  • Libposix is compiled and linked, containing posix_open() that internally calls open() [the original one from libc].
  • Libposix is transformed - all open() are replaced with prefix variant: helenos_libc_open() and all posix_open() are replaced with open(). The transformed library is stored as libposixaslibc.a

Binutils and PCC are then linked with libc4posix and libposixaslibc
libraries instead of libc and libposix as was done previously.

WARNING: it looks that binutils, PCC and MSIM still works but not all
architectures were tested.

  • Property mode set to 100755
File size: 9.1 KB
Line 
1#! /bin/bash
2
3#
4# Copyright (c) 2011 Petr Koupy
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10#
11# - Redistributions of source code must retain the above copyright
12# notice, this list of conditions and the following disclaimer.
13# - Redistributions in binary form must reproduce the above copyright
14# notice, this list of conditions and the following disclaimer in the
15# documentation and/or other materials provided with the distribution.
16# - The name of the author may not be used to endorse or promote products
17# derived from this software without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29#
30
31#
32# This shell script is reserved for intrusive patches (hacks) to binutils
33# that cannot be done in a clean and isolated way or for which doing so
34# would require too much complexity.
35#
36# List of patch descriptions:
37#
38# Patch 1
39# Even though binutils build process supports cross compilation where
40# build and host platforms are different, it is not easily applicable
41# to HelenOS. It would be difficult to satisfy binutils expectations
42# of host headers, libraries and tools on a build system (at least
43# until these are developed/ported). Another issue would be the
44# necessity to carry out time consuming full canadian cross compilation
45# (even in case when build, host and target hardware platforms are the
46# same). Instead of going into such trouble, it is easier to leverage
47# already built HelenOS toolchain as a first stage of canadian cross
48# and trick binutils scripts to do a simple cross compilation while
49# actually doing second stage of canadian cross. Because binutils
50# configure scripts try to compile and execute various testing code, it
51# have to be ensured that these tests are skipped. Such behaviour can
52# be acomplished by patching cross compilation flag while leaving host
53# and build parameters empty (i.e. configure script believes it is
54# not doing cross compilation while skipping some testing as in the case
55# of cross compilation).
56#
57# Patch 2
58# Enabled cross compilation flag brings along some anomalies which
59# have to be reverted.
60#
61# Patch 3
62# Binutils plugin support is dependent on libdl.so library.
63# By default, the plugin support is switched off for all
64# configure scripts of binutils. The only exception is configure
65# script of ld 2.21 (and possibly above), where plugin support
66# became mandatory (although not really needed).
67#
68# Patch 4
69# Whereas most systems maps pid_t to signed int, HelenOS maps it
70# to 64-bit unsigned integer (which is further masked by libposix to
71# 64-bit signed integer). Because libiberty blindly expects pid_t to be
72# signed int, there is some type incompatibility in libiberty
73# files related to executing a subprocess. Since both as and ld are
74# not runtime dependent on this functionality, the simplest solution is
75# to patch libiberty to avoid compiler warnings.
76#
77# Patch 5
78# When host and target system is equal, libbfd wants to compile a support
79# for core files, which is dependent on non-standard headers sys/param.h
80# and sys/user.h. Since we are cross compiling even when host and target
81# are equal, variables related to core file support must be cleared.
82#
83# Patch 6
84# There is a few occurences in binutils where POSIX function is declared
85# and called without first including the corresponding header. Such
86# declarations cause a problem to the linker, because all functions
87# from libposix are prefixed with the posix_ prefix.
88#
89# Patch 7
90# Implementation of fnmatch inside libiberty is not very friendly to the
91# non-GNU libc which implements its own native fnmatch. To resolve this
92# incompatibility, libiberty fnmatch has to be manually hidden.
93#
94# Patch 8
95# When building binutils for arm32 target, there is a conflict with
96# libposix function name redefinitons in one of the arm-specific files.
97#
98# Patch 9
99# Libiberty does not trust our strncmp that is provided in libposix.
100# That is because when cross-compiling, it cannot check how it behaves
101# and assumes the worst. But then it clashes when linking (due to
102# multiple definitions of ...) and this patch prevents compilation of
103# liberty strncmp.
104
105case "$1" in
106 "do")
107 # Backup original files.
108 cp -f "$2/configure" "$2/configure.backup"
109 cp -f "$2/bfd/configure" "$2/bfd/configure.backup"
110 cp -f "$2/gas/configure" "$2/gas/configure.backup"
111 cp -f "$2/gas/config/tc-arm.c" "$2/gas/config/tc-arm.c.backup"
112 cp -f "$2/intl/configure" "$2/intl/configure.backup"
113 cp -f "$2/ld/configure" "$2/ld/configure.backup"
114 cp -f "$2/libiberty/configure" "$2/libiberty/configure.backup"
115 cp -f "$2/libiberty/Makefile.in" "$2/libiberty/Makefile.in.backup"
116 cp -f "$2/include/fnmatch.h" "$2/include/fnmatch.h.backup"
117 cp -f "$2/libiberty/fnmatch.c" "$2/libiberty/fnmatch.c.backup"
118 cp -f "$2/libiberty/pex-common.h" "$2/libiberty/pex-common.h.backup"
119 cp -f "$2/libiberty/xstrerror.c" "$2/libiberty/xstrerror.c.backup"
120 cp -f "$2/opcodes/configure" "$2/opcodes/configure.backup"
121
122 # Patch main binutils configure script.
123 cat "$2/configure.backup" | \
124 # See Patch 1.
125 sed 's/^cross_compiling=no/cross_compiling=yes/g' \
126 > "$2/configure"
127
128 # Patch bfd configure script.
129 cat "$2/bfd/configure.backup" | \
130 # See Patch 1.
131 sed 's/^cross_compiling=no/cross_compiling=yes/g' | \
132 # See Patch 5.
133 sed 's/COREFILE=".*"/COREFILE='\'\''/g' | \
134 sed 's/COREFILE=[^ ]*/COREFILE='\'\''/g' \
135 > "$2/bfd/configure"
136
137 # Patch gas configure script.
138 cat "$2/gas/configure.backup" | \
139 # See Patch 1.
140 sed 's/^cross_compiling=no/cross_compiling=yes/g' \
141 > "$2/gas/configure"
142
143 # Patch gas tc-arm.c.
144 cat "$2/gas/config/tc-arm.c.backup" | \
145 # See Patch 8.
146 sed 's/\(#include "dwarf2dbg.h"\)/\1\n#undef div/g' \
147 > "$2/gas/config/tc-arm.c"
148
149 # Patch intl configure script.
150 cat "$2/intl/configure.backup" | \
151 # See Patch 1.
152 sed 's/^cross_compiling=no/cross_compiling=yes/g' \
153 > "$2/intl/configure"
154
155 # Patch ld configure script.
156 cat "$2/ld/configure.backup" | \
157 # See Patch 1.
158 sed 's/^cross_compiling=no/cross_compiling=yes/g' | \
159 # See Patch 3.
160 sed 's/^enable_plugins=yes/enable_plugins=no/g' \
161 > "$2/ld/configure"
162
163 # Patch libiberty configure script.
164 cat "$2/libiberty/configure.backup" | \
165 # See Patch 1 and 9.
166 sed -e 's/^cross_compiling=no/cross_compiling=yes/g' \
167 -e 's/ac_cv_func_strncmp_works=no/ac_cv_func_strncmp_works=yes/g' \
168 > "$2/libiberty/configure"
169
170 # Hide libiberty fnmatch implementation.
171 # See Patch 7.
172 mv -f "$2/include/fnmatch.h" "$2/include/fnmatch_hide.h"
173 (
174 # Avoid compiler warning for empty compilation unit.
175 echo 'char __fnmatch_hide(void);'
176 echo 'char __fnmatch_hide(void) { return 0; }'
177 echo '#define __GNU_LIBRARY__'
178 cat "$2/libiberty/fnmatch.c.backup"
179 ) > "$2/libiberty/fnmatch.c"
180 mv -f "$2/libiberty/fnmatch.c" "$2/libiberty/fnmatch_hide.c"
181 cat "$2/libiberty/Makefile.in.backup" | \
182 sed 's/fnmatch/fnmatch_hide/g' \
183 > "$2/libiberty/Makefile.in"
184
185 # Patch libiberty pex-common.h.
186 cat "$2/libiberty/pex-common.h.backup" | \
187 # See Patch 4.
188 sed 's/pid_t (\*wait)/int (*wait)/g' \
189 > "$2/libiberty/pex-common.h"
190
191 # Patch libiberty xstrerror.c.
192 # See Patch 6.
193 (
194 echo '#include <string.h>'
195 echo '#define DONT_DECLARE_STRERROR'
196 cat "$2/libiberty/xstrerror.c.backup"
197 ) > "$2/libiberty/xstrerror.c"
198
199 # Patch opcodes configure script.
200 cat "$2/opcodes/configure.backup" | \
201 # See Patch 1.
202 sed 's/^cross_compiling=no/cross_compiling=yes/g' | \
203 # See Patch 2.
204 sed 's/BUILD_LIBS=-liberty/BUILD_LIBS=..\/libiberty\/libiberty.a/g' \
205 > "$2/opcodes/configure"
206
207 ;;
208 "undo")
209 # Restore original files.
210 mv -f "$2/configure.backup" "$2/configure"
211 mv -f "$2/bfd/configure.backup" "$2/bfd/configure"
212 mv -f "$2/gas/configure.backup" "$2/gas/configure"
213 mv -f "$2/gas/config/tc-arm.c.backup" "$2/gas/config/tc-arm.c"
214 mv -f "$2/intl/configure.backup" "$2/intl/configure"
215 mv -f "$2/ld/configure.backup" "$2/ld/configure"
216 mv -f "$2/libiberty/configure.backup" "$2/libiberty/configure"
217 mv -f "$2/libiberty/Makefile.in.backup" "$2/libiberty/Makefile.in"
218 rm -f "$2/include/fnmatch_hide.h" "$2/libiberty/fnmatch_hide.c"
219 mv -f "$2/include/fnmatch.h.backup" "$2/include/fnmatch.h"
220 mv -f "$2/libiberty/fnmatch.c.backup" "$2/libiberty/fnmatch.c"
221 mv -f "$2/libiberty/pex-common.h.backup" "$2/libiberty/pex-common.h"
222 mv -f "$2/libiberty/xstrerror.c.backup" "$2/libiberty/xstrerror.c"
223 mv -f "$2/opcodes/configure.backup" "$2/opcodes/configure"
224 ;;
225 *)
226 ;;
227esac
228
Note: See TracBrowser for help on using the repository browser.