Commit f8ce1faf55955de62e0a12e330c6d9a526071f65

Authored by Linus Torvalds

Merge tag 'modules-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux

Pull mudule updates from Rusty Russell:
 "We get rid of the general module prefix confusion with a binary config
  option, fix a remove/insert race which Never Happens, and (my
  favorite) handle the case when we have too many modules for a single
  commandline.  Seriously, the kernel is full, please go away!"

* tag 'modules-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux:
  modpost: fix unwanted VMLINUX_SYMBOL_STR expansion
  X.509: Support parse long form of length octets in Authority Key Identifier
  module: don't unlink the module until we've removed all exposure.
  kernel: kallsyms: memory override issue, need check destination buffer length
  MODSIGN: do not send garbage to stderr when enabling modules signature
  modpost: handle huge numbers of modules.
  modpost: add -T option to read module names from file/stdin.
  modpost: minor cleanup.
  genksyms: pass symbol-prefix instead of arch
  module: fix symbol versioning with symbol prefixes
  CONFIG_SYMBOL_PREFIX: cleanup.

Showing 23 changed files Inline Diff

1 VERSION = 3 1 VERSION = 3
2 PATCHLEVEL = 9 2 PATCHLEVEL = 9
3 SUBLEVEL = 0 3 SUBLEVEL = 0
4 EXTRAVERSION = 4 EXTRAVERSION =
5 NAME = Unicycling Gorilla 5 NAME = Unicycling Gorilla
6 6
7 # *DOCUMENTATION* 7 # *DOCUMENTATION*
8 # To see a list of typical targets execute "make help" 8 # To see a list of typical targets execute "make help"
9 # More info can be located in ./README 9 # More info can be located in ./README
10 # Comments in this file are targeted only to the developer, do not 10 # Comments in this file are targeted only to the developer, do not
11 # expect to learn how to build the kernel reading this file. 11 # expect to learn how to build the kernel reading this file.
12 12
13 # Do not: 13 # Do not:
14 # o use make's built-in rules and variables 14 # o use make's built-in rules and variables
15 # (this increases performance and avoids hard-to-debug behaviour); 15 # (this increases performance and avoids hard-to-debug behaviour);
16 # o print "Entering directory ..."; 16 # o print "Entering directory ...";
17 MAKEFLAGS += -rR --no-print-directory 17 MAKEFLAGS += -rR --no-print-directory
18 18
19 # Avoid funny character set dependencies 19 # Avoid funny character set dependencies
20 unexport LC_ALL 20 unexport LC_ALL
21 LC_COLLATE=C 21 LC_COLLATE=C
22 LC_NUMERIC=C 22 LC_NUMERIC=C
23 export LC_COLLATE LC_NUMERIC 23 export LC_COLLATE LC_NUMERIC
24 24
25 # We are using a recursive build, so we need to do a little thinking 25 # We are using a recursive build, so we need to do a little thinking
26 # to get the ordering right. 26 # to get the ordering right.
27 # 27 #
28 # Most importantly: sub-Makefiles should only ever modify files in 28 # Most importantly: sub-Makefiles should only ever modify files in
29 # their own directory. If in some directory we have a dependency on 29 # their own directory. If in some directory we have a dependency on
30 # a file in another dir (which doesn't happen often, but it's often 30 # a file in another dir (which doesn't happen often, but it's often
31 # unavoidable when linking the built-in.o targets which finally 31 # unavoidable when linking the built-in.o targets which finally
32 # turn into vmlinux), we will call a sub make in that other dir, and 32 # turn into vmlinux), we will call a sub make in that other dir, and
33 # after that we are sure that everything which is in that other dir 33 # after that we are sure that everything which is in that other dir
34 # is now up to date. 34 # is now up to date.
35 # 35 #
36 # The only cases where we need to modify files which have global 36 # The only cases where we need to modify files which have global
37 # effects are thus separated out and done before the recursive 37 # effects are thus separated out and done before the recursive
38 # descending is started. They are now explicitly listed as the 38 # descending is started. They are now explicitly listed as the
39 # prepare rule. 39 # prepare rule.
40 40
41 # To put more focus on warnings, be less verbose as default 41 # To put more focus on warnings, be less verbose as default
42 # Use 'make V=1' to see the full commands 42 # Use 'make V=1' to see the full commands
43 43
44 ifeq ("$(origin V)", "command line") 44 ifeq ("$(origin V)", "command line")
45 KBUILD_VERBOSE = $(V) 45 KBUILD_VERBOSE = $(V)
46 endif 46 endif
47 ifndef KBUILD_VERBOSE 47 ifndef KBUILD_VERBOSE
48 KBUILD_VERBOSE = 0 48 KBUILD_VERBOSE = 0
49 endif 49 endif
50 50
51 # Call a source code checker (by default, "sparse") as part of the 51 # Call a source code checker (by default, "sparse") as part of the
52 # C compilation. 52 # C compilation.
53 # 53 #
54 # Use 'make C=1' to enable checking of only re-compiled files. 54 # Use 'make C=1' to enable checking of only re-compiled files.
55 # Use 'make C=2' to enable checking of *all* source files, regardless 55 # Use 'make C=2' to enable checking of *all* source files, regardless
56 # of whether they are re-compiled or not. 56 # of whether they are re-compiled or not.
57 # 57 #
58 # See the file "Documentation/sparse.txt" for more details, including 58 # See the file "Documentation/sparse.txt" for more details, including
59 # where to get the "sparse" utility. 59 # where to get the "sparse" utility.
60 60
61 ifeq ("$(origin C)", "command line") 61 ifeq ("$(origin C)", "command line")
62 KBUILD_CHECKSRC = $(C) 62 KBUILD_CHECKSRC = $(C)
63 endif 63 endif
64 ifndef KBUILD_CHECKSRC 64 ifndef KBUILD_CHECKSRC
65 KBUILD_CHECKSRC = 0 65 KBUILD_CHECKSRC = 0
66 endif 66 endif
67 67
68 # Use make M=dir to specify directory of external module to build 68 # Use make M=dir to specify directory of external module to build
69 # Old syntax make ... SUBDIRS=$PWD is still supported 69 # Old syntax make ... SUBDIRS=$PWD is still supported
70 # Setting the environment variable KBUILD_EXTMOD take precedence 70 # Setting the environment variable KBUILD_EXTMOD take precedence
71 ifdef SUBDIRS 71 ifdef SUBDIRS
72 KBUILD_EXTMOD ?= $(SUBDIRS) 72 KBUILD_EXTMOD ?= $(SUBDIRS)
73 endif 73 endif
74 74
75 ifeq ("$(origin M)", "command line") 75 ifeq ("$(origin M)", "command line")
76 KBUILD_EXTMOD := $(M) 76 KBUILD_EXTMOD := $(M)
77 endif 77 endif
78 78
79 # kbuild supports saving output files in a separate directory. 79 # kbuild supports saving output files in a separate directory.
80 # To locate output files in a separate directory two syntaxes are supported. 80 # To locate output files in a separate directory two syntaxes are supported.
81 # In both cases the working directory must be the root of the kernel src. 81 # In both cases the working directory must be the root of the kernel src.
82 # 1) O= 82 # 1) O=
83 # Use "make O=dir/to/store/output/files/" 83 # Use "make O=dir/to/store/output/files/"
84 # 84 #
85 # 2) Set KBUILD_OUTPUT 85 # 2) Set KBUILD_OUTPUT
86 # Set the environment variable KBUILD_OUTPUT to point to the directory 86 # Set the environment variable KBUILD_OUTPUT to point to the directory
87 # where the output files shall be placed. 87 # where the output files shall be placed.
88 # export KBUILD_OUTPUT=dir/to/store/output/files/ 88 # export KBUILD_OUTPUT=dir/to/store/output/files/
89 # make 89 # make
90 # 90 #
91 # The O= assignment takes precedence over the KBUILD_OUTPUT environment 91 # The O= assignment takes precedence over the KBUILD_OUTPUT environment
92 # variable. 92 # variable.
93 93
94 94
95 # KBUILD_SRC is set on invocation of make in OBJ directory 95 # KBUILD_SRC is set on invocation of make in OBJ directory
96 # KBUILD_SRC is not intended to be used by the regular user (for now) 96 # KBUILD_SRC is not intended to be used by the regular user (for now)
97 ifeq ($(KBUILD_SRC),) 97 ifeq ($(KBUILD_SRC),)
98 98
99 # OK, Make called in directory where kernel src resides 99 # OK, Make called in directory where kernel src resides
100 # Do we want to locate output files in a separate directory? 100 # Do we want to locate output files in a separate directory?
101 ifeq ("$(origin O)", "command line") 101 ifeq ("$(origin O)", "command line")
102 KBUILD_OUTPUT := $(O) 102 KBUILD_OUTPUT := $(O)
103 endif 103 endif
104 104
105 ifeq ("$(origin W)", "command line") 105 ifeq ("$(origin W)", "command line")
106 export KBUILD_ENABLE_EXTRA_GCC_CHECKS := $(W) 106 export KBUILD_ENABLE_EXTRA_GCC_CHECKS := $(W)
107 endif 107 endif
108 108
109 # That's our default target when none is given on the command line 109 # That's our default target when none is given on the command line
110 PHONY := _all 110 PHONY := _all
111 _all: 111 _all:
112 112
113 # Cancel implicit rules on top Makefile 113 # Cancel implicit rules on top Makefile
114 $(CURDIR)/Makefile Makefile: ; 114 $(CURDIR)/Makefile Makefile: ;
115 115
116 ifneq ($(KBUILD_OUTPUT),) 116 ifneq ($(KBUILD_OUTPUT),)
117 # Invoke a second make in the output directory, passing relevant variables 117 # Invoke a second make in the output directory, passing relevant variables
118 # check that the output directory actually exists 118 # check that the output directory actually exists
119 saved-output := $(KBUILD_OUTPUT) 119 saved-output := $(KBUILD_OUTPUT)
120 KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd) 120 KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
121 $(if $(KBUILD_OUTPUT),, \ 121 $(if $(KBUILD_OUTPUT),, \
122 $(error output directory "$(saved-output)" does not exist)) 122 $(error output directory "$(saved-output)" does not exist))
123 123
124 PHONY += $(MAKECMDGOALS) sub-make 124 PHONY += $(MAKECMDGOALS) sub-make
125 125
126 $(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make 126 $(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make
127 @: 127 @:
128 128
129 sub-make: FORCE 129 sub-make: FORCE
130 $(if $(KBUILD_VERBOSE:1=),@)$(MAKE) -C $(KBUILD_OUTPUT) \ 130 $(if $(KBUILD_VERBOSE:1=),@)$(MAKE) -C $(KBUILD_OUTPUT) \
131 KBUILD_SRC=$(CURDIR) \ 131 KBUILD_SRC=$(CURDIR) \
132 KBUILD_EXTMOD="$(KBUILD_EXTMOD)" -f $(CURDIR)/Makefile \ 132 KBUILD_EXTMOD="$(KBUILD_EXTMOD)" -f $(CURDIR)/Makefile \
133 $(filter-out _all sub-make,$(MAKECMDGOALS)) 133 $(filter-out _all sub-make,$(MAKECMDGOALS))
134 134
135 # Leave processing to above invocation of make 135 # Leave processing to above invocation of make
136 skip-makefile := 1 136 skip-makefile := 1
137 endif # ifneq ($(KBUILD_OUTPUT),) 137 endif # ifneq ($(KBUILD_OUTPUT),)
138 endif # ifeq ($(KBUILD_SRC),) 138 endif # ifeq ($(KBUILD_SRC),)
139 139
140 # We process the rest of the Makefile if this is the final invocation of make 140 # We process the rest of the Makefile if this is the final invocation of make
141 ifeq ($(skip-makefile),) 141 ifeq ($(skip-makefile),)
142 142
143 # If building an external module we do not care about the all: rule 143 # If building an external module we do not care about the all: rule
144 # but instead _all depend on modules 144 # but instead _all depend on modules
145 PHONY += all 145 PHONY += all
146 ifeq ($(KBUILD_EXTMOD),) 146 ifeq ($(KBUILD_EXTMOD),)
147 _all: all 147 _all: all
148 else 148 else
149 _all: modules 149 _all: modules
150 endif 150 endif
151 151
152 srctree := $(if $(KBUILD_SRC),$(KBUILD_SRC),$(CURDIR)) 152 srctree := $(if $(KBUILD_SRC),$(KBUILD_SRC),$(CURDIR))
153 objtree := $(CURDIR) 153 objtree := $(CURDIR)
154 src := $(srctree) 154 src := $(srctree)
155 obj := $(objtree) 155 obj := $(objtree)
156 156
157 VPATH := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD)) 157 VPATH := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
158 158
159 export srctree objtree VPATH 159 export srctree objtree VPATH
160 160
161 161
162 # SUBARCH tells the usermode build what the underlying arch is. That is set 162 # SUBARCH tells the usermode build what the underlying arch is. That is set
163 # first, and if a usermode build is happening, the "ARCH=um" on the command 163 # first, and if a usermode build is happening, the "ARCH=um" on the command
164 # line overrides the setting of ARCH below. If a native build is happening, 164 # line overrides the setting of ARCH below. If a native build is happening,
165 # then ARCH is assigned, getting whatever value it gets normally, and 165 # then ARCH is assigned, getting whatever value it gets normally, and
166 # SUBARCH is subsequently ignored. 166 # SUBARCH is subsequently ignored.
167 167
168 SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \ 168 SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
169 -e s/sun4u/sparc64/ \ 169 -e s/sun4u/sparc64/ \
170 -e s/arm.*/arm/ -e s/sa110/arm/ \ 170 -e s/arm.*/arm/ -e s/sa110/arm/ \
171 -e s/s390x/s390/ -e s/parisc64/parisc/ \ 171 -e s/s390x/s390/ -e s/parisc64/parisc/ \
172 -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \ 172 -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
173 -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ ) 173 -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )
174 174
175 # Cross compiling and selecting different set of gcc/bin-utils 175 # Cross compiling and selecting different set of gcc/bin-utils
176 # --------------------------------------------------------------------------- 176 # ---------------------------------------------------------------------------
177 # 177 #
178 # When performing cross compilation for other architectures ARCH shall be set 178 # When performing cross compilation for other architectures ARCH shall be set
179 # to the target architecture. (See arch/* for the possibilities). 179 # to the target architecture. (See arch/* for the possibilities).
180 # ARCH can be set during invocation of make: 180 # ARCH can be set during invocation of make:
181 # make ARCH=ia64 181 # make ARCH=ia64
182 # Another way is to have ARCH set in the environment. 182 # Another way is to have ARCH set in the environment.
183 # The default ARCH is the host where make is executed. 183 # The default ARCH is the host where make is executed.
184 184
185 # CROSS_COMPILE specify the prefix used for all executables used 185 # CROSS_COMPILE specify the prefix used for all executables used
186 # during compilation. Only gcc and related bin-utils executables 186 # during compilation. Only gcc and related bin-utils executables
187 # are prefixed with $(CROSS_COMPILE). 187 # are prefixed with $(CROSS_COMPILE).
188 # CROSS_COMPILE can be set on the command line 188 # CROSS_COMPILE can be set on the command line
189 # make CROSS_COMPILE=ia64-linux- 189 # make CROSS_COMPILE=ia64-linux-
190 # Alternatively CROSS_COMPILE can be set in the environment. 190 # Alternatively CROSS_COMPILE can be set in the environment.
191 # A third alternative is to store a setting in .config so that plain 191 # A third alternative is to store a setting in .config so that plain
192 # "make" in the configured kernel build directory always uses that. 192 # "make" in the configured kernel build directory always uses that.
193 # Default value for CROSS_COMPILE is not to prefix executables 193 # Default value for CROSS_COMPILE is not to prefix executables
194 # Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile 194 # Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
195 ARCH ?= $(SUBARCH) 195 ARCH ?= $(SUBARCH)
196 CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%) 196 CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%)
197 197
198 # Architecture as present in compile.h 198 # Architecture as present in compile.h
199 UTS_MACHINE := $(ARCH) 199 UTS_MACHINE := $(ARCH)
200 SRCARCH := $(ARCH) 200 SRCARCH := $(ARCH)
201 201
202 # Additional ARCH settings for x86 202 # Additional ARCH settings for x86
203 ifeq ($(ARCH),i386) 203 ifeq ($(ARCH),i386)
204 SRCARCH := x86 204 SRCARCH := x86
205 endif 205 endif
206 ifeq ($(ARCH),x86_64) 206 ifeq ($(ARCH),x86_64)
207 SRCARCH := x86 207 SRCARCH := x86
208 endif 208 endif
209 209
210 # Additional ARCH settings for sparc 210 # Additional ARCH settings for sparc
211 ifeq ($(ARCH),sparc32) 211 ifeq ($(ARCH),sparc32)
212 SRCARCH := sparc 212 SRCARCH := sparc
213 endif 213 endif
214 ifeq ($(ARCH),sparc64) 214 ifeq ($(ARCH),sparc64)
215 SRCARCH := sparc 215 SRCARCH := sparc
216 endif 216 endif
217 217
218 # Additional ARCH settings for sh 218 # Additional ARCH settings for sh
219 ifeq ($(ARCH),sh64) 219 ifeq ($(ARCH),sh64)
220 SRCARCH := sh 220 SRCARCH := sh
221 endif 221 endif
222 222
223 # Additional ARCH settings for tile 223 # Additional ARCH settings for tile
224 ifeq ($(ARCH),tilepro) 224 ifeq ($(ARCH),tilepro)
225 SRCARCH := tile 225 SRCARCH := tile
226 endif 226 endif
227 ifeq ($(ARCH),tilegx) 227 ifeq ($(ARCH),tilegx)
228 SRCARCH := tile 228 SRCARCH := tile
229 endif 229 endif
230 230
231 # Where to locate arch specific headers 231 # Where to locate arch specific headers
232 hdr-arch := $(SRCARCH) 232 hdr-arch := $(SRCARCH)
233 233
234 KCONFIG_CONFIG ?= .config 234 KCONFIG_CONFIG ?= .config
235 export KCONFIG_CONFIG 235 export KCONFIG_CONFIG
236 236
237 # SHELL used by kbuild 237 # SHELL used by kbuild
238 CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \ 238 CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
239 else if [ -x /bin/bash ]; then echo /bin/bash; \ 239 else if [ -x /bin/bash ]; then echo /bin/bash; \
240 else echo sh; fi ; fi) 240 else echo sh; fi ; fi)
241 241
242 HOSTCC = gcc 242 HOSTCC = gcc
243 HOSTCXX = g++ 243 HOSTCXX = g++
244 HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer 244 HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
245 HOSTCXXFLAGS = -O2 245 HOSTCXXFLAGS = -O2
246 246
247 # Decide whether to build built-in, modular, or both. 247 # Decide whether to build built-in, modular, or both.
248 # Normally, just do built-in. 248 # Normally, just do built-in.
249 249
250 KBUILD_MODULES := 250 KBUILD_MODULES :=
251 KBUILD_BUILTIN := 1 251 KBUILD_BUILTIN := 1
252 252
253 # If we have only "make modules", don't compile built-in objects. 253 # If we have only "make modules", don't compile built-in objects.
254 # When we're building modules with modversions, we need to consider 254 # When we're building modules with modversions, we need to consider
255 # the built-in objects during the descend as well, in order to 255 # the built-in objects during the descend as well, in order to
256 # make sure the checksums are up to date before we record them. 256 # make sure the checksums are up to date before we record them.
257 257
258 ifeq ($(MAKECMDGOALS),modules) 258 ifeq ($(MAKECMDGOALS),modules)
259 KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1) 259 KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
260 endif 260 endif
261 261
262 # If we have "make <whatever> modules", compile modules 262 # If we have "make <whatever> modules", compile modules
263 # in addition to whatever we do anyway. 263 # in addition to whatever we do anyway.
264 # Just "make" or "make all" shall build modules as well 264 # Just "make" or "make all" shall build modules as well
265 265
266 ifneq ($(filter all _all modules,$(MAKECMDGOALS)),) 266 ifneq ($(filter all _all modules,$(MAKECMDGOALS)),)
267 KBUILD_MODULES := 1 267 KBUILD_MODULES := 1
268 endif 268 endif
269 269
270 ifeq ($(MAKECMDGOALS),) 270 ifeq ($(MAKECMDGOALS),)
271 KBUILD_MODULES := 1 271 KBUILD_MODULES := 1
272 endif 272 endif
273 273
274 export KBUILD_MODULES KBUILD_BUILTIN 274 export KBUILD_MODULES KBUILD_BUILTIN
275 export KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD 275 export KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD
276 276
277 # Beautify output 277 # Beautify output
278 # --------------------------------------------------------------------------- 278 # ---------------------------------------------------------------------------
279 # 279 #
280 # Normally, we echo the whole command before executing it. By making 280 # Normally, we echo the whole command before executing it. By making
281 # that echo $($(quiet)$(cmd)), we now have the possibility to set 281 # that echo $($(quiet)$(cmd)), we now have the possibility to set
282 # $(quiet) to choose other forms of output instead, e.g. 282 # $(quiet) to choose other forms of output instead, e.g.
283 # 283 #
284 # quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@ 284 # quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
285 # cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< 285 # cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
286 # 286 #
287 # If $(quiet) is empty, the whole command will be printed. 287 # If $(quiet) is empty, the whole command will be printed.
288 # If it is set to "quiet_", only the short version will be printed. 288 # If it is set to "quiet_", only the short version will be printed.
289 # If it is set to "silent_", nothing will be printed at all, since 289 # If it is set to "silent_", nothing will be printed at all, since
290 # the variable $(silent_cmd_cc_o_c) doesn't exist. 290 # the variable $(silent_cmd_cc_o_c) doesn't exist.
291 # 291 #
292 # A simple variant is to prefix commands with $(Q) - that's useful 292 # A simple variant is to prefix commands with $(Q) - that's useful
293 # for commands that shall be hidden in non-verbose mode. 293 # for commands that shall be hidden in non-verbose mode.
294 # 294 #
295 # $(Q)ln $@ :< 295 # $(Q)ln $@ :<
296 # 296 #
297 # If KBUILD_VERBOSE equals 0 then the above command will be hidden. 297 # If KBUILD_VERBOSE equals 0 then the above command will be hidden.
298 # If KBUILD_VERBOSE equals 1 then the above command is displayed. 298 # If KBUILD_VERBOSE equals 1 then the above command is displayed.
299 299
300 ifeq ($(KBUILD_VERBOSE),1) 300 ifeq ($(KBUILD_VERBOSE),1)
301 quiet = 301 quiet =
302 Q = 302 Q =
303 else 303 else
304 quiet=quiet_ 304 quiet=quiet_
305 Q = @ 305 Q = @
306 endif 306 endif
307 307
308 # If the user is running make -s (silent mode), suppress echoing of 308 # If the user is running make -s (silent mode), suppress echoing of
309 # commands 309 # commands
310 310
311 ifneq ($(filter s% -s%,$(MAKEFLAGS)),) 311 ifneq ($(filter s% -s%,$(MAKEFLAGS)),)
312 quiet=silent_ 312 quiet=silent_
313 endif 313 endif
314 314
315 export quiet Q KBUILD_VERBOSE 315 export quiet Q KBUILD_VERBOSE
316 316
317 317
318 # Look for make include files relative to root of kernel src 318 # Look for make include files relative to root of kernel src
319 MAKEFLAGS += --include-dir=$(srctree) 319 MAKEFLAGS += --include-dir=$(srctree)
320 320
321 # We need some generic definitions (do not try to remake the file). 321 # We need some generic definitions (do not try to remake the file).
322 $(srctree)/scripts/Kbuild.include: ; 322 $(srctree)/scripts/Kbuild.include: ;
323 include $(srctree)/scripts/Kbuild.include 323 include $(srctree)/scripts/Kbuild.include
324 324
325 # Make variables (CC, etc...) 325 # Make variables (CC, etc...)
326 326
327 AS = $(CROSS_COMPILE)as 327 AS = $(CROSS_COMPILE)as
328 LD = $(CROSS_COMPILE)ld 328 LD = $(CROSS_COMPILE)ld
329 CC = $(CROSS_COMPILE)gcc 329 CC = $(CROSS_COMPILE)gcc
330 CPP = $(CC) -E 330 CPP = $(CC) -E
331 AR = $(CROSS_COMPILE)ar 331 AR = $(CROSS_COMPILE)ar
332 NM = $(CROSS_COMPILE)nm 332 NM = $(CROSS_COMPILE)nm
333 STRIP = $(CROSS_COMPILE)strip 333 STRIP = $(CROSS_COMPILE)strip
334 OBJCOPY = $(CROSS_COMPILE)objcopy 334 OBJCOPY = $(CROSS_COMPILE)objcopy
335 OBJDUMP = $(CROSS_COMPILE)objdump 335 OBJDUMP = $(CROSS_COMPILE)objdump
336 AWK = awk 336 AWK = awk
337 GENKSYMS = scripts/genksyms/genksyms 337 GENKSYMS = scripts/genksyms/genksyms
338 INSTALLKERNEL := installkernel 338 INSTALLKERNEL := installkernel
339 DEPMOD = /sbin/depmod 339 DEPMOD = /sbin/depmod
340 PERL = perl 340 PERL = perl
341 CHECK = sparse 341 CHECK = sparse
342 342
343 CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ 343 CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
344 -Wbitwise -Wno-return-void $(CF) 344 -Wbitwise -Wno-return-void $(CF)
345 CFLAGS_MODULE = 345 CFLAGS_MODULE =
346 AFLAGS_MODULE = 346 AFLAGS_MODULE =
347 LDFLAGS_MODULE = 347 LDFLAGS_MODULE =
348 CFLAGS_KERNEL = 348 CFLAGS_KERNEL =
349 AFLAGS_KERNEL = 349 AFLAGS_KERNEL =
350 CFLAGS_GCOV = -fprofile-arcs -ftest-coverage 350 CFLAGS_GCOV = -fprofile-arcs -ftest-coverage
351 351
352 352
353 # Use USERINCLUDE when you must reference the UAPI directories only. 353 # Use USERINCLUDE when you must reference the UAPI directories only.
354 USERINCLUDE := \ 354 USERINCLUDE := \
355 -I$(srctree)/arch/$(hdr-arch)/include/uapi \ 355 -I$(srctree)/arch/$(hdr-arch)/include/uapi \
356 -Iarch/$(hdr-arch)/include/generated/uapi \ 356 -Iarch/$(hdr-arch)/include/generated/uapi \
357 -I$(srctree)/include/uapi \ 357 -I$(srctree)/include/uapi \
358 -Iinclude/generated/uapi \ 358 -Iinclude/generated/uapi \
359 -include $(srctree)/include/linux/kconfig.h 359 -include $(srctree)/include/linux/kconfig.h
360 360
361 # Use LINUXINCLUDE when you must reference the include/ directory. 361 # Use LINUXINCLUDE when you must reference the include/ directory.
362 # Needed to be compatible with the O= option 362 # Needed to be compatible with the O= option
363 LINUXINCLUDE := \ 363 LINUXINCLUDE := \
364 -I$(srctree)/arch/$(hdr-arch)/include \ 364 -I$(srctree)/arch/$(hdr-arch)/include \
365 -Iarch/$(hdr-arch)/include/generated \ 365 -Iarch/$(hdr-arch)/include/generated \
366 $(if $(KBUILD_SRC), -I$(srctree)/include) \ 366 $(if $(KBUILD_SRC), -I$(srctree)/include) \
367 -Iinclude \ 367 -Iinclude \
368 $(USERINCLUDE) 368 $(USERINCLUDE)
369 369
370 KBUILD_CPPFLAGS := -D__KERNEL__ 370 KBUILD_CPPFLAGS := -D__KERNEL__
371 371
372 KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ 372 KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
373 -fno-strict-aliasing -fno-common \ 373 -fno-strict-aliasing -fno-common \
374 -Werror-implicit-function-declaration \ 374 -Werror-implicit-function-declaration \
375 -Wno-format-security \ 375 -Wno-format-security \
376 -fno-delete-null-pointer-checks 376 -fno-delete-null-pointer-checks
377 KBUILD_AFLAGS_KERNEL := 377 KBUILD_AFLAGS_KERNEL :=
378 KBUILD_CFLAGS_KERNEL := 378 KBUILD_CFLAGS_KERNEL :=
379 KBUILD_AFLAGS := -D__ASSEMBLY__ 379 KBUILD_AFLAGS := -D__ASSEMBLY__
380 KBUILD_AFLAGS_MODULE := -DMODULE 380 KBUILD_AFLAGS_MODULE := -DMODULE
381 KBUILD_CFLAGS_MODULE := -DMODULE 381 KBUILD_CFLAGS_MODULE := -DMODULE
382 KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds 382 KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds
383 383
384 # Read KERNELRELEASE from include/config/kernel.release (if it exists) 384 # Read KERNELRELEASE from include/config/kernel.release (if it exists)
385 KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null) 385 KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
386 KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION) 386 KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
387 387
388 export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION 388 export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
389 export ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC 389 export ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC
390 export CPP AR NM STRIP OBJCOPY OBJDUMP 390 export CPP AR NM STRIP OBJCOPY OBJDUMP
391 export MAKE AWK GENKSYMS INSTALLKERNEL PERL UTS_MACHINE 391 export MAKE AWK GENKSYMS INSTALLKERNEL PERL UTS_MACHINE
392 export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS 392 export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
393 393
394 export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS 394 export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
395 export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_GCOV 395 export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_GCOV
396 export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE 396 export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
397 export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE 397 export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
398 export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL 398 export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
399 export KBUILD_ARFLAGS 399 export KBUILD_ARFLAGS
400 400
401 # When compiling out-of-tree modules, put MODVERDIR in the module 401 # When compiling out-of-tree modules, put MODVERDIR in the module
402 # tree rather than in the kernel tree. The kernel tree might 402 # tree rather than in the kernel tree. The kernel tree might
403 # even be read-only. 403 # even be read-only.
404 export MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions 404 export MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions
405 405
406 # Files to ignore in find ... statements 406 # Files to ignore in find ... statements
407 407
408 RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o -name CVS \ 408 RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o -name CVS \
409 -o -name .pc -o -name .hg -o -name .git \) -prune -o 409 -o -name .pc -o -name .hg -o -name .git \) -prune -o
410 export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \ 410 export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
411 --exclude CVS --exclude .pc --exclude .hg --exclude .git 411 --exclude CVS --exclude .pc --exclude .hg --exclude .git
412 412
413 # =========================================================================== 413 # ===========================================================================
414 # Rules shared between *config targets and build targets 414 # Rules shared between *config targets and build targets
415 415
416 # Basic helpers built in scripts/ 416 # Basic helpers built in scripts/
417 PHONY += scripts_basic 417 PHONY += scripts_basic
418 scripts_basic: 418 scripts_basic:
419 $(Q)$(MAKE) $(build)=scripts/basic 419 $(Q)$(MAKE) $(build)=scripts/basic
420 $(Q)rm -f .tmp_quiet_recordmcount 420 $(Q)rm -f .tmp_quiet_recordmcount
421 421
422 # To avoid any implicit rule to kick in, define an empty command. 422 # To avoid any implicit rule to kick in, define an empty command.
423 scripts/basic/%: scripts_basic ; 423 scripts/basic/%: scripts_basic ;
424 424
425 PHONY += outputmakefile 425 PHONY += outputmakefile
426 # outputmakefile generates a Makefile in the output directory, if using a 426 # outputmakefile generates a Makefile in the output directory, if using a
427 # separate output directory. This allows convenient use of make in the 427 # separate output directory. This allows convenient use of make in the
428 # output directory. 428 # output directory.
429 outputmakefile: 429 outputmakefile:
430 ifneq ($(KBUILD_SRC),) 430 ifneq ($(KBUILD_SRC),)
431 $(Q)ln -fsn $(srctree) source 431 $(Q)ln -fsn $(srctree) source
432 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \ 432 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \
433 $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL) 433 $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
434 endif 434 endif
435 435
436 # Support for using generic headers in asm-generic 436 # Support for using generic headers in asm-generic
437 PHONY += asm-generic 437 PHONY += asm-generic
438 asm-generic: 438 asm-generic:
439 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.asm-generic \ 439 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.asm-generic \
440 src=asm obj=arch/$(SRCARCH)/include/generated/asm 440 src=asm obj=arch/$(SRCARCH)/include/generated/asm
441 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.asm-generic \ 441 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.asm-generic \
442 src=uapi/asm obj=arch/$(SRCARCH)/include/generated/uapi/asm 442 src=uapi/asm obj=arch/$(SRCARCH)/include/generated/uapi/asm
443 443
444 # To make sure we do not include .config for any of the *config targets 444 # To make sure we do not include .config for any of the *config targets
445 # catch them early, and hand them over to scripts/kconfig/Makefile 445 # catch them early, and hand them over to scripts/kconfig/Makefile
446 # It is allowed to specify more targets when calling make, including 446 # It is allowed to specify more targets when calling make, including
447 # mixing *config targets and build targets. 447 # mixing *config targets and build targets.
448 # For example 'make oldconfig all'. 448 # For example 'make oldconfig all'.
449 # Detect when mixed targets is specified, and make a second invocation 449 # Detect when mixed targets is specified, and make a second invocation
450 # of make so .config is not included in this case either (for *config). 450 # of make so .config is not included in this case either (for *config).
451 451
452 version_h := include/generated/uapi/linux/version.h 452 version_h := include/generated/uapi/linux/version.h
453 453
454 no-dot-config-targets := clean mrproper distclean \ 454 no-dot-config-targets := clean mrproper distclean \
455 cscope gtags TAGS tags help %docs check% coccicheck \ 455 cscope gtags TAGS tags help %docs check% coccicheck \
456 $(version_h) headers_% archheaders archscripts \ 456 $(version_h) headers_% archheaders archscripts \
457 kernelversion %src-pkg 457 kernelversion %src-pkg
458 458
459 config-targets := 0 459 config-targets := 0
460 mixed-targets := 0 460 mixed-targets := 0
461 dot-config := 1 461 dot-config := 1
462 462
463 ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),) 463 ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
464 ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),) 464 ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
465 dot-config := 0 465 dot-config := 0
466 endif 466 endif
467 endif 467 endif
468 468
469 ifeq ($(KBUILD_EXTMOD),) 469 ifeq ($(KBUILD_EXTMOD),)
470 ifneq ($(filter config %config,$(MAKECMDGOALS)),) 470 ifneq ($(filter config %config,$(MAKECMDGOALS)),)
471 config-targets := 1 471 config-targets := 1
472 ifneq ($(filter-out config %config,$(MAKECMDGOALS)),) 472 ifneq ($(filter-out config %config,$(MAKECMDGOALS)),)
473 mixed-targets := 1 473 mixed-targets := 1
474 endif 474 endif
475 endif 475 endif
476 endif 476 endif
477 477
478 ifeq ($(mixed-targets),1) 478 ifeq ($(mixed-targets),1)
479 # =========================================================================== 479 # ===========================================================================
480 # We're called with mixed targets (*config and build targets). 480 # We're called with mixed targets (*config and build targets).
481 # Handle them one by one. 481 # Handle them one by one.
482 482
483 %:: FORCE 483 %:: FORCE
484 $(Q)$(MAKE) -C $(srctree) KBUILD_SRC= $@ 484 $(Q)$(MAKE) -C $(srctree) KBUILD_SRC= $@
485 485
486 else 486 else
487 ifeq ($(config-targets),1) 487 ifeq ($(config-targets),1)
488 # =========================================================================== 488 # ===========================================================================
489 # *config targets only - make sure prerequisites are updated, and descend 489 # *config targets only - make sure prerequisites are updated, and descend
490 # in scripts/kconfig to make the *config target 490 # in scripts/kconfig to make the *config target
491 491
492 # Read arch specific Makefile to set KBUILD_DEFCONFIG as needed. 492 # Read arch specific Makefile to set KBUILD_DEFCONFIG as needed.
493 # KBUILD_DEFCONFIG may point out an alternative default configuration 493 # KBUILD_DEFCONFIG may point out an alternative default configuration
494 # used for 'make defconfig' 494 # used for 'make defconfig'
495 include $(srctree)/arch/$(SRCARCH)/Makefile 495 include $(srctree)/arch/$(SRCARCH)/Makefile
496 export KBUILD_DEFCONFIG KBUILD_KCONFIG 496 export KBUILD_DEFCONFIG KBUILD_KCONFIG
497 497
498 config: scripts_basic outputmakefile FORCE 498 config: scripts_basic outputmakefile FORCE
499 $(Q)mkdir -p include/linux include/config 499 $(Q)mkdir -p include/linux include/config
500 $(Q)$(MAKE) $(build)=scripts/kconfig $@ 500 $(Q)$(MAKE) $(build)=scripts/kconfig $@
501 501
502 %config: scripts_basic outputmakefile FORCE 502 %config: scripts_basic outputmakefile FORCE
503 $(Q)mkdir -p include/linux include/config 503 $(Q)mkdir -p include/linux include/config
504 $(Q)$(MAKE) $(build)=scripts/kconfig $@ 504 $(Q)$(MAKE) $(build)=scripts/kconfig $@
505 505
506 else 506 else
507 # =========================================================================== 507 # ===========================================================================
508 # Build targets only - this includes vmlinux, arch specific targets, clean 508 # Build targets only - this includes vmlinux, arch specific targets, clean
509 # targets and others. In general all targets except *config targets. 509 # targets and others. In general all targets except *config targets.
510 510
511 ifeq ($(KBUILD_EXTMOD),) 511 ifeq ($(KBUILD_EXTMOD),)
512 # Additional helpers built in scripts/ 512 # Additional helpers built in scripts/
513 # Carefully list dependencies so we do not try to build scripts twice 513 # Carefully list dependencies so we do not try to build scripts twice
514 # in parallel 514 # in parallel
515 PHONY += scripts 515 PHONY += scripts
516 scripts: scripts_basic include/config/auto.conf include/config/tristate.conf \ 516 scripts: scripts_basic include/config/auto.conf include/config/tristate.conf \
517 asm-generic 517 asm-generic
518 $(Q)$(MAKE) $(build)=$(@) 518 $(Q)$(MAKE) $(build)=$(@)
519 519
520 # Objects we will link into vmlinux / subdirs we need to visit 520 # Objects we will link into vmlinux / subdirs we need to visit
521 init-y := init/ 521 init-y := init/
522 drivers-y := drivers/ sound/ firmware/ 522 drivers-y := drivers/ sound/ firmware/
523 net-y := net/ 523 net-y := net/
524 libs-y := lib/ 524 libs-y := lib/
525 core-y := usr/ 525 core-y := usr/
526 endif # KBUILD_EXTMOD 526 endif # KBUILD_EXTMOD
527 527
528 ifeq ($(dot-config),1) 528 ifeq ($(dot-config),1)
529 # Read in config 529 # Read in config
530 -include include/config/auto.conf 530 -include include/config/auto.conf
531 531
532 ifeq ($(KBUILD_EXTMOD),) 532 ifeq ($(KBUILD_EXTMOD),)
533 # Read in dependencies to all Kconfig* files, make sure to run 533 # Read in dependencies to all Kconfig* files, make sure to run
534 # oldconfig if changes are detected. 534 # oldconfig if changes are detected.
535 -include include/config/auto.conf.cmd 535 -include include/config/auto.conf.cmd
536 536
537 # To avoid any implicit rule to kick in, define an empty command 537 # To avoid any implicit rule to kick in, define an empty command
538 $(KCONFIG_CONFIG) include/config/auto.conf.cmd: ; 538 $(KCONFIG_CONFIG) include/config/auto.conf.cmd: ;
539 539
540 # If .config is newer than include/config/auto.conf, someone tinkered 540 # If .config is newer than include/config/auto.conf, someone tinkered
541 # with it and forgot to run make oldconfig. 541 # with it and forgot to run make oldconfig.
542 # if auto.conf.cmd is missing then we are probably in a cleaned tree so 542 # if auto.conf.cmd is missing then we are probably in a cleaned tree so
543 # we execute the config step to be sure to catch updated Kconfig files 543 # we execute the config step to be sure to catch updated Kconfig files
544 include/config/%.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd 544 include/config/%.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
545 $(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig 545 $(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
546 else 546 else
547 # external modules needs include/generated/autoconf.h and include/config/auto.conf 547 # external modules needs include/generated/autoconf.h and include/config/auto.conf
548 # but do not care if they are up-to-date. Use auto.conf to trigger the test 548 # but do not care if they are up-to-date. Use auto.conf to trigger the test
549 PHONY += include/config/auto.conf 549 PHONY += include/config/auto.conf
550 550
551 include/config/auto.conf: 551 include/config/auto.conf:
552 $(Q)test -e include/generated/autoconf.h -a -e $@ || ( \ 552 $(Q)test -e include/generated/autoconf.h -a -e $@ || ( \
553 echo >&2; \ 553 echo >&2; \
554 echo >&2 " ERROR: Kernel configuration is invalid."; \ 554 echo >&2 " ERROR: Kernel configuration is invalid."; \
555 echo >&2 " include/generated/autoconf.h or $@ are missing.";\ 555 echo >&2 " include/generated/autoconf.h or $@ are missing.";\
556 echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \ 556 echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \
557 echo >&2 ; \ 557 echo >&2 ; \
558 /bin/false) 558 /bin/false)
559 559
560 endif # KBUILD_EXTMOD 560 endif # KBUILD_EXTMOD
561 561
562 else 562 else
563 # Dummy target needed, because used as prerequisite 563 # Dummy target needed, because used as prerequisite
564 include/config/auto.conf: ; 564 include/config/auto.conf: ;
565 endif # $(dot-config) 565 endif # $(dot-config)
566 566
567 # The all: target is the default when no target is given on the 567 # The all: target is the default when no target is given on the
568 # command line. 568 # command line.
569 # This allow a user to issue only 'make' to build a kernel including modules 569 # This allow a user to issue only 'make' to build a kernel including modules
570 # Defaults to vmlinux, but the arch makefile usually adds further targets 570 # Defaults to vmlinux, but the arch makefile usually adds further targets
571 all: vmlinux 571 all: vmlinux
572 572
573 ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE 573 ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
574 KBUILD_CFLAGS += -Os $(call cc-disable-warning,maybe-uninitialized,) 574 KBUILD_CFLAGS += -Os $(call cc-disable-warning,maybe-uninitialized,)
575 else 575 else
576 KBUILD_CFLAGS += -O2 576 KBUILD_CFLAGS += -O2
577 endif 577 endif
578 578
579 include $(srctree)/arch/$(SRCARCH)/Makefile 579 include $(srctree)/arch/$(SRCARCH)/Makefile
580 580
581 ifdef CONFIG_READABLE_ASM 581 ifdef CONFIG_READABLE_ASM
582 # Disable optimizations that make assembler listings hard to read. 582 # Disable optimizations that make assembler listings hard to read.
583 # reorder blocks reorders the control in the function 583 # reorder blocks reorders the control in the function
584 # ipa clone creates specialized cloned functions 584 # ipa clone creates specialized cloned functions
585 # partial inlining inlines only parts of functions 585 # partial inlining inlines only parts of functions
586 KBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks,) \ 586 KBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks,) \
587 $(call cc-option,-fno-ipa-cp-clone,) \ 587 $(call cc-option,-fno-ipa-cp-clone,) \
588 $(call cc-option,-fno-partial-inlining) 588 $(call cc-option,-fno-partial-inlining)
589 endif 589 endif
590 590
591 ifneq ($(CONFIG_FRAME_WARN),0) 591 ifneq ($(CONFIG_FRAME_WARN),0)
592 KBUILD_CFLAGS += $(call cc-option,-Wframe-larger-than=${CONFIG_FRAME_WARN}) 592 KBUILD_CFLAGS += $(call cc-option,-Wframe-larger-than=${CONFIG_FRAME_WARN})
593 endif 593 endif
594 594
595 # Force gcc to behave correct even for buggy distributions 595 # Force gcc to behave correct even for buggy distributions
596 ifndef CONFIG_CC_STACKPROTECTOR 596 ifndef CONFIG_CC_STACKPROTECTOR
597 KBUILD_CFLAGS += $(call cc-option, -fno-stack-protector) 597 KBUILD_CFLAGS += $(call cc-option, -fno-stack-protector)
598 endif 598 endif
599 599
600 # This warning generated too much noise in a regular build. 600 # This warning generated too much noise in a regular build.
601 # Use make W=1 to enable this warning (see scripts/Makefile.build) 601 # Use make W=1 to enable this warning (see scripts/Makefile.build)
602 KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) 602 KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
603 603
604 ifdef CONFIG_FRAME_POINTER 604 ifdef CONFIG_FRAME_POINTER
605 KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls 605 KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
606 else 606 else
607 # Some targets (ARM with Thumb2, for example), can't be built with frame 607 # Some targets (ARM with Thumb2, for example), can't be built with frame
608 # pointers. For those, we don't have FUNCTION_TRACER automatically 608 # pointers. For those, we don't have FUNCTION_TRACER automatically
609 # select FRAME_POINTER. However, FUNCTION_TRACER adds -pg, and this is 609 # select FRAME_POINTER. However, FUNCTION_TRACER adds -pg, and this is
610 # incompatible with -fomit-frame-pointer with current GCC, so we don't use 610 # incompatible with -fomit-frame-pointer with current GCC, so we don't use
611 # -fomit-frame-pointer with FUNCTION_TRACER. 611 # -fomit-frame-pointer with FUNCTION_TRACER.
612 ifndef CONFIG_FUNCTION_TRACER 612 ifndef CONFIG_FUNCTION_TRACER
613 KBUILD_CFLAGS += -fomit-frame-pointer 613 KBUILD_CFLAGS += -fomit-frame-pointer
614 endif 614 endif
615 endif 615 endif
616 616
617 ifdef CONFIG_DEBUG_INFO 617 ifdef CONFIG_DEBUG_INFO
618 KBUILD_CFLAGS += -g 618 KBUILD_CFLAGS += -g
619 KBUILD_AFLAGS += -gdwarf-2 619 KBUILD_AFLAGS += -gdwarf-2
620 endif 620 endif
621 621
622 ifdef CONFIG_DEBUG_INFO_REDUCED 622 ifdef CONFIG_DEBUG_INFO_REDUCED
623 KBUILD_CFLAGS += $(call cc-option, -femit-struct-debug-baseonly) \ 623 KBUILD_CFLAGS += $(call cc-option, -femit-struct-debug-baseonly) \
624 $(call cc-option,-fno-var-tracking) 624 $(call cc-option,-fno-var-tracking)
625 endif 625 endif
626 626
627 ifdef CONFIG_FUNCTION_TRACER 627 ifdef CONFIG_FUNCTION_TRACER
628 ifdef CONFIG_HAVE_FENTRY 628 ifdef CONFIG_HAVE_FENTRY
629 CC_USING_FENTRY := $(call cc-option, -mfentry -DCC_USING_FENTRY) 629 CC_USING_FENTRY := $(call cc-option, -mfentry -DCC_USING_FENTRY)
630 endif 630 endif
631 KBUILD_CFLAGS += -pg $(CC_USING_FENTRY) 631 KBUILD_CFLAGS += -pg $(CC_USING_FENTRY)
632 KBUILD_AFLAGS += $(CC_USING_FENTRY) 632 KBUILD_AFLAGS += $(CC_USING_FENTRY)
633 ifdef CONFIG_DYNAMIC_FTRACE 633 ifdef CONFIG_DYNAMIC_FTRACE
634 ifdef CONFIG_HAVE_C_RECORDMCOUNT 634 ifdef CONFIG_HAVE_C_RECORDMCOUNT
635 BUILD_C_RECORDMCOUNT := y 635 BUILD_C_RECORDMCOUNT := y
636 export BUILD_C_RECORDMCOUNT 636 export BUILD_C_RECORDMCOUNT
637 endif 637 endif
638 endif 638 endif
639 endif 639 endif
640 640
641 # We trigger additional mismatches with less inlining 641 # We trigger additional mismatches with less inlining
642 ifdef CONFIG_DEBUG_SECTION_MISMATCH 642 ifdef CONFIG_DEBUG_SECTION_MISMATCH
643 KBUILD_CFLAGS += $(call cc-option, -fno-inline-functions-called-once) 643 KBUILD_CFLAGS += $(call cc-option, -fno-inline-functions-called-once)
644 endif 644 endif
645 645
646 # arch Makefile may override CC so keep this after arch Makefile is included 646 # arch Makefile may override CC so keep this after arch Makefile is included
647 NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) 647 NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
648 CHECKFLAGS += $(NOSTDINC_FLAGS) 648 CHECKFLAGS += $(NOSTDINC_FLAGS)
649 649
650 # warn about C99 declaration after statement 650 # warn about C99 declaration after statement
651 KBUILD_CFLAGS += $(call cc-option,-Wdeclaration-after-statement,) 651 KBUILD_CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
652 652
653 # disable pointer signed / unsigned warnings in gcc 4.0 653 # disable pointer signed / unsigned warnings in gcc 4.0
654 KBUILD_CFLAGS += $(call cc-disable-warning, pointer-sign) 654 KBUILD_CFLAGS += $(call cc-disable-warning, pointer-sign)
655 655
656 # disable invalid "can't wrap" optimizations for signed / pointers 656 # disable invalid "can't wrap" optimizations for signed / pointers
657 KBUILD_CFLAGS += $(call cc-option,-fno-strict-overflow) 657 KBUILD_CFLAGS += $(call cc-option,-fno-strict-overflow)
658 658
659 # conserve stack if available 659 # conserve stack if available
660 KBUILD_CFLAGS += $(call cc-option,-fconserve-stack) 660 KBUILD_CFLAGS += $(call cc-option,-fconserve-stack)
661 661
662 # use the deterministic mode of AR if available 662 # use the deterministic mode of AR if available
663 KBUILD_ARFLAGS := $(call ar-option,D) 663 KBUILD_ARFLAGS := $(call ar-option,D)
664 664
665 # check for 'asm goto' 665 # check for 'asm goto'
666 ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC)), y) 666 ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC)), y)
667 KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO 667 KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO
668 endif 668 endif
669 669
670 # Add user supplied CPPFLAGS, AFLAGS and CFLAGS as the last assignments 670 # Add user supplied CPPFLAGS, AFLAGS and CFLAGS as the last assignments
671 KBUILD_CPPFLAGS += $(KCPPFLAGS) 671 KBUILD_CPPFLAGS += $(KCPPFLAGS)
672 KBUILD_AFLAGS += $(KAFLAGS) 672 KBUILD_AFLAGS += $(KAFLAGS)
673 KBUILD_CFLAGS += $(KCFLAGS) 673 KBUILD_CFLAGS += $(KCFLAGS)
674 674
675 # Use --build-id when available. 675 # Use --build-id when available.
676 LDFLAGS_BUILD_ID = $(patsubst -Wl$(comma)%,%,\ 676 LDFLAGS_BUILD_ID = $(patsubst -Wl$(comma)%,%,\
677 $(call cc-ldoption, -Wl$(comma)--build-id,)) 677 $(call cc-ldoption, -Wl$(comma)--build-id,))
678 KBUILD_LDFLAGS_MODULE += $(LDFLAGS_BUILD_ID) 678 KBUILD_LDFLAGS_MODULE += $(LDFLAGS_BUILD_ID)
679 LDFLAGS_vmlinux += $(LDFLAGS_BUILD_ID) 679 LDFLAGS_vmlinux += $(LDFLAGS_BUILD_ID)
680 680
681 ifeq ($(CONFIG_STRIP_ASM_SYMS),y) 681 ifeq ($(CONFIG_STRIP_ASM_SYMS),y)
682 LDFLAGS_vmlinux += $(call ld-option, -X,) 682 LDFLAGS_vmlinux += $(call ld-option, -X,)
683 endif 683 endif
684 684
685 # Default kernel image to build when no specific target is given. 685 # Default kernel image to build when no specific target is given.
686 # KBUILD_IMAGE may be overruled on the command line or 686 # KBUILD_IMAGE may be overruled on the command line or
687 # set in the environment 687 # set in the environment
688 # Also any assignments in arch/$(ARCH)/Makefile take precedence over 688 # Also any assignments in arch/$(ARCH)/Makefile take precedence over
689 # this default value 689 # this default value
690 export KBUILD_IMAGE ?= vmlinux 690 export KBUILD_IMAGE ?= vmlinux
691 691
692 # 692 #
693 # INSTALL_PATH specifies where to place the updated kernel and system map 693 # INSTALL_PATH specifies where to place the updated kernel and system map
694 # images. Default is /boot, but you can set it to other values 694 # images. Default is /boot, but you can set it to other values
695 export INSTALL_PATH ?= /boot 695 export INSTALL_PATH ?= /boot
696 696
697 # 697 #
698 # INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory 698 # INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
699 # relocations required by build roots. This is not defined in the 699 # relocations required by build roots. This is not defined in the
700 # makefile but the argument can be passed to make if needed. 700 # makefile but the argument can be passed to make if needed.
701 # 701 #
702 702
703 MODLIB = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE) 703 MODLIB = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
704 export MODLIB 704 export MODLIB
705 705
706 # 706 #
707 # INSTALL_MOD_STRIP, if defined, will cause modules to be 707 # INSTALL_MOD_STRIP, if defined, will cause modules to be
708 # stripped after they are installed. If INSTALL_MOD_STRIP is '1', then 708 # stripped after they are installed. If INSTALL_MOD_STRIP is '1', then
709 # the default option --strip-debug will be used. Otherwise, 709 # the default option --strip-debug will be used. Otherwise,
710 # INSTALL_MOD_STRIP value will be used as the options to the strip command. 710 # INSTALL_MOD_STRIP value will be used as the options to the strip command.
711 711
712 ifdef INSTALL_MOD_STRIP 712 ifdef INSTALL_MOD_STRIP
713 ifeq ($(INSTALL_MOD_STRIP),1) 713 ifeq ($(INSTALL_MOD_STRIP),1)
714 mod_strip_cmd = $(STRIP) --strip-debug 714 mod_strip_cmd = $(STRIP) --strip-debug
715 else 715 else
716 mod_strip_cmd = $(STRIP) $(INSTALL_MOD_STRIP) 716 mod_strip_cmd = $(STRIP) $(INSTALL_MOD_STRIP)
717 endif # INSTALL_MOD_STRIP=1 717 endif # INSTALL_MOD_STRIP=1
718 else 718 else
719 mod_strip_cmd = true 719 mod_strip_cmd = true
720 endif # INSTALL_MOD_STRIP 720 endif # INSTALL_MOD_STRIP
721 export mod_strip_cmd 721 export mod_strip_cmd
722 722
723 723
724 ifdef CONFIG_MODULE_SIG_ALL 724 ifdef CONFIG_MODULE_SIG_ALL
725 MODSECKEY = ./signing_key.priv 725 MODSECKEY = ./signing_key.priv
726 MODPUBKEY = ./signing_key.x509 726 MODPUBKEY = ./signing_key.x509
727 export MODPUBKEY 727 export MODPUBKEY
728 mod_sign_cmd = perl $(srctree)/scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(MODSECKEY) $(MODPUBKEY) 728 mod_sign_cmd = perl $(srctree)/scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(MODSECKEY) $(MODPUBKEY)
729 else 729 else
730 mod_sign_cmd = true 730 mod_sign_cmd = true
731 endif 731 endif
732 export mod_sign_cmd 732 export mod_sign_cmd
733 733
734 734
735 ifeq ($(KBUILD_EXTMOD),) 735 ifeq ($(KBUILD_EXTMOD),)
736 core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ 736 core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
737 737
738 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \ 738 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
739 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \ 739 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
740 $(net-y) $(net-m) $(libs-y) $(libs-m))) 740 $(net-y) $(net-m) $(libs-y) $(libs-m)))
741 741
742 vmlinux-alldirs := $(sort $(vmlinux-dirs) $(patsubst %/,%,$(filter %/, \ 742 vmlinux-alldirs := $(sort $(vmlinux-dirs) $(patsubst %/,%,$(filter %/, \
743 $(init-n) $(init-) \ 743 $(init-n) $(init-) \
744 $(core-n) $(core-) $(drivers-n) $(drivers-) \ 744 $(core-n) $(core-) $(drivers-n) $(drivers-) \
745 $(net-n) $(net-) $(libs-n) $(libs-)))) 745 $(net-n) $(net-) $(libs-n) $(libs-))))
746 746
747 init-y := $(patsubst %/, %/built-in.o, $(init-y)) 747 init-y := $(patsubst %/, %/built-in.o, $(init-y))
748 core-y := $(patsubst %/, %/built-in.o, $(core-y)) 748 core-y := $(patsubst %/, %/built-in.o, $(core-y))
749 drivers-y := $(patsubst %/, %/built-in.o, $(drivers-y)) 749 drivers-y := $(patsubst %/, %/built-in.o, $(drivers-y))
750 net-y := $(patsubst %/, %/built-in.o, $(net-y)) 750 net-y := $(patsubst %/, %/built-in.o, $(net-y))
751 libs-y1 := $(patsubst %/, %/lib.a, $(libs-y)) 751 libs-y1 := $(patsubst %/, %/lib.a, $(libs-y))
752 libs-y2 := $(patsubst %/, %/built-in.o, $(libs-y)) 752 libs-y2 := $(patsubst %/, %/built-in.o, $(libs-y))
753 libs-y := $(libs-y1) $(libs-y2) 753 libs-y := $(libs-y1) $(libs-y2)
754 754
755 # Externally visible symbols (used by link-vmlinux.sh) 755 # Externally visible symbols (used by link-vmlinux.sh)
756 export KBUILD_VMLINUX_INIT := $(head-y) $(init-y) 756 export KBUILD_VMLINUX_INIT := $(head-y) $(init-y)
757 export KBUILD_VMLINUX_MAIN := $(core-y) $(libs-y) $(drivers-y) $(net-y) 757 export KBUILD_VMLINUX_MAIN := $(core-y) $(libs-y) $(drivers-y) $(net-y)
758 export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds 758 export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds
759 export LDFLAGS_vmlinux 759 export LDFLAGS_vmlinux
760 760
761 vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_INIT) $(KBUILD_VMLINUX_MAIN) 761 vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_INIT) $(KBUILD_VMLINUX_MAIN)
762 762
763 # Final link of vmlinux 763 # Final link of vmlinux
764 cmd_link-vmlinux = $(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) 764 cmd_link-vmlinux = $(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux)
765 quiet_cmd_link-vmlinux = LINK $@ 765 quiet_cmd_link-vmlinux = LINK $@
766 766
767 # Include targets which we want to 767 # Include targets which we want to
768 # execute if the rest of the kernel build went well. 768 # execute if the rest of the kernel build went well.
769 vmlinux: scripts/link-vmlinux.sh $(vmlinux-deps) FORCE 769 vmlinux: scripts/link-vmlinux.sh $(vmlinux-deps) FORCE
770 ifdef CONFIG_HEADERS_CHECK 770 ifdef CONFIG_HEADERS_CHECK
771 $(Q)$(MAKE) -f $(srctree)/Makefile headers_check 771 $(Q)$(MAKE) -f $(srctree)/Makefile headers_check
772 endif 772 endif
773 ifdef CONFIG_SAMPLES 773 ifdef CONFIG_SAMPLES
774 $(Q)$(MAKE) $(build)=samples 774 $(Q)$(MAKE) $(build)=samples
775 endif 775 endif
776 ifdef CONFIG_BUILD_DOCSRC 776 ifdef CONFIG_BUILD_DOCSRC
777 $(Q)$(MAKE) $(build)=Documentation 777 $(Q)$(MAKE) $(build)=Documentation
778 endif 778 endif
779 +$(call if_changed,link-vmlinux) 779 +$(call if_changed,link-vmlinux)
780 780
781 # The actual objects are generated when descending, 781 # The actual objects are generated when descending,
782 # make sure no implicit rule kicks in 782 # make sure no implicit rule kicks in
783 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ; 783 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
784 784
785 # Handle descending into subdirectories listed in $(vmlinux-dirs) 785 # Handle descending into subdirectories listed in $(vmlinux-dirs)
786 # Preset locale variables to speed up the build process. Limit locale 786 # Preset locale variables to speed up the build process. Limit locale
787 # tweaks to this spot to avoid wrong language settings when running 787 # tweaks to this spot to avoid wrong language settings when running
788 # make menuconfig etc. 788 # make menuconfig etc.
789 # Error messages still appears in the original language 789 # Error messages still appears in the original language
790 790
791 PHONY += $(vmlinux-dirs) 791 PHONY += $(vmlinux-dirs)
792 $(vmlinux-dirs): prepare scripts 792 $(vmlinux-dirs): prepare scripts
793 $(Q)$(MAKE) $(build)=$@ 793 $(Q)$(MAKE) $(build)=$@
794 794
795 # Store (new) KERNELRELASE string in include/config/kernel.release 795 # Store (new) KERNELRELASE string in include/config/kernel.release
796 include/config/kernel.release: include/config/auto.conf FORCE 796 include/config/kernel.release: include/config/auto.conf FORCE
797 $(Q)rm -f $@ 797 $(Q)rm -f $@
798 $(Q)echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))" > $@ 798 $(Q)echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))" > $@
799 799
800 800
801 # Things we need to do before we recursively start building the kernel 801 # Things we need to do before we recursively start building the kernel
802 # or the modules are listed in "prepare". 802 # or the modules are listed in "prepare".
803 # A multi level approach is used. prepareN is processed before prepareN-1. 803 # A multi level approach is used. prepareN is processed before prepareN-1.
804 # archprepare is used in arch Makefiles and when processed asm symlink, 804 # archprepare is used in arch Makefiles and when processed asm symlink,
805 # version.h and scripts_basic is processed / created. 805 # version.h and scripts_basic is processed / created.
806 806
807 # Listed in dependency order 807 # Listed in dependency order
808 PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3 808 PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3
809 809
810 # prepare3 is used to check if we are building in a separate output directory, 810 # prepare3 is used to check if we are building in a separate output directory,
811 # and if so do: 811 # and if so do:
812 # 1) Check that make has not been executed in the kernel src $(srctree) 812 # 1) Check that make has not been executed in the kernel src $(srctree)
813 prepare3: include/config/kernel.release 813 prepare3: include/config/kernel.release
814 ifneq ($(KBUILD_SRC),) 814 ifneq ($(KBUILD_SRC),)
815 @$(kecho) ' Using $(srctree) as source for kernel' 815 @$(kecho) ' Using $(srctree) as source for kernel'
816 $(Q)if [ -f $(srctree)/.config -o -d $(srctree)/include/config ]; then \ 816 $(Q)if [ -f $(srctree)/.config -o -d $(srctree)/include/config ]; then \
817 echo >&2 " $(srctree) is not clean, please run 'make mrproper'"; \ 817 echo >&2 " $(srctree) is not clean, please run 'make mrproper'"; \
818 echo >&2 " in the '$(srctree)' directory.";\ 818 echo >&2 " in the '$(srctree)' directory.";\
819 /bin/false; \ 819 /bin/false; \
820 fi; 820 fi;
821 endif 821 endif
822 822
823 # prepare2 creates a makefile if using a separate output directory 823 # prepare2 creates a makefile if using a separate output directory
824 prepare2: prepare3 outputmakefile asm-generic 824 prepare2: prepare3 outputmakefile asm-generic
825 825
826 prepare1: prepare2 $(version_h) include/generated/utsrelease.h \ 826 prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
827 include/config/auto.conf 827 include/config/auto.conf
828 $(cmd_crmodverdir) 828 $(cmd_crmodverdir)
829 829
830 archprepare: archheaders archscripts prepare1 scripts_basic 830 archprepare: archheaders archscripts prepare1 scripts_basic
831 831
832 prepare0: archprepare FORCE 832 prepare0: archprepare FORCE
833 $(Q)$(MAKE) $(build)=. 833 $(Q)$(MAKE) $(build)=.
834 834
835 # All the preparing.. 835 # All the preparing..
836 prepare: prepare0 836 prepare: prepare0
837 837
838 # Generate some files 838 # Generate some files
839 # --------------------------------------------------------------------------- 839 # ---------------------------------------------------------------------------
840 840
841 # KERNELRELEASE can change from a few different places, meaning version.h 841 # KERNELRELEASE can change from a few different places, meaning version.h
842 # needs to be updated, so this check is forced on all builds 842 # needs to be updated, so this check is forced on all builds
843 843
844 uts_len := 64 844 uts_len := 64
845 define filechk_utsrelease.h 845 define filechk_utsrelease.h
846 if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \ 846 if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \
847 echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \ 847 echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \
848 exit 1; \ 848 exit 1; \
849 fi; \ 849 fi; \
850 (echo \#define UTS_RELEASE \"$(KERNELRELEASE)\";) 850 (echo \#define UTS_RELEASE \"$(KERNELRELEASE)\";)
851 endef 851 endef
852 852
853 define filechk_version.h 853 define filechk_version.h
854 (echo \#define LINUX_VERSION_CODE $(shell \ 854 (echo \#define LINUX_VERSION_CODE $(shell \
855 expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 0$(SUBLEVEL)); \ 855 expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 0$(SUBLEVEL)); \
856 echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))';) 856 echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))';)
857 endef 857 endef
858 858
859 $(version_h): $(srctree)/Makefile FORCE 859 $(version_h): $(srctree)/Makefile FORCE
860 $(call filechk,version.h) 860 $(call filechk,version.h)
861 861
862 include/generated/utsrelease.h: include/config/kernel.release FORCE 862 include/generated/utsrelease.h: include/config/kernel.release FORCE
863 $(call filechk,utsrelease.h) 863 $(call filechk,utsrelease.h)
864 864
865 PHONY += headerdep 865 PHONY += headerdep
866 headerdep: 866 headerdep:
867 $(Q)find $(srctree)/include/ -name '*.h' | xargs --max-args 1 \ 867 $(Q)find $(srctree)/include/ -name '*.h' | xargs --max-args 1 \
868 $(srctree)/scripts/headerdep.pl -I$(srctree)/include 868 $(srctree)/scripts/headerdep.pl -I$(srctree)/include
869 869
870 # --------------------------------------------------------------------------- 870 # ---------------------------------------------------------------------------
871 871
872 PHONY += depend dep 872 PHONY += depend dep
873 depend dep: 873 depend dep:
874 @echo '*** Warning: make $@ is unnecessary now.' 874 @echo '*** Warning: make $@ is unnecessary now.'
875 875
876 # --------------------------------------------------------------------------- 876 # ---------------------------------------------------------------------------
877 # Firmware install 877 # Firmware install
878 INSTALL_FW_PATH=$(INSTALL_MOD_PATH)/lib/firmware 878 INSTALL_FW_PATH=$(INSTALL_MOD_PATH)/lib/firmware
879 export INSTALL_FW_PATH 879 export INSTALL_FW_PATH
880 880
881 PHONY += firmware_install 881 PHONY += firmware_install
882 firmware_install: FORCE 882 firmware_install: FORCE
883 @mkdir -p $(objtree)/firmware 883 @mkdir -p $(objtree)/firmware
884 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.fwinst obj=firmware __fw_install 884 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.fwinst obj=firmware __fw_install
885 885
886 # --------------------------------------------------------------------------- 886 # ---------------------------------------------------------------------------
887 # Kernel headers 887 # Kernel headers
888 888
889 #Default location for installed headers 889 #Default location for installed headers
890 export INSTALL_HDR_PATH = $(objtree)/usr 890 export INSTALL_HDR_PATH = $(objtree)/usr
891 891
892 hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj 892 hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
893 893
894 # If we do an all arch process set dst to asm-$(hdr-arch) 894 # If we do an all arch process set dst to asm-$(hdr-arch)
895 hdr-dst = $(if $(KBUILD_HEADERS), dst=include/asm-$(hdr-arch), dst=include/asm) 895 hdr-dst = $(if $(KBUILD_HEADERS), dst=include/asm-$(hdr-arch), dst=include/asm)
896 896
897 PHONY += archheaders 897 PHONY += archheaders
898 archheaders: 898 archheaders:
899 899
900 PHONY += archscripts 900 PHONY += archscripts
901 archscripts: 901 archscripts:
902 902
903 PHONY += __headers 903 PHONY += __headers
904 __headers: $(version_h) scripts_basic asm-generic archheaders archscripts FORCE 904 __headers: $(version_h) scripts_basic asm-generic archheaders archscripts FORCE
905 $(Q)$(MAKE) $(build)=scripts build_unifdef 905 $(Q)$(MAKE) $(build)=scripts build_unifdef
906 906
907 PHONY += headers_install_all 907 PHONY += headers_install_all
908 headers_install_all: 908 headers_install_all:
909 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/headers.sh install 909 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/headers.sh install
910 910
911 PHONY += headers_install 911 PHONY += headers_install
912 headers_install: __headers 912 headers_install: __headers
913 $(if $(wildcard $(srctree)/arch/$(hdr-arch)/include/uapi/asm/Kbuild),, \ 913 $(if $(wildcard $(srctree)/arch/$(hdr-arch)/include/uapi/asm/Kbuild),, \
914 $(error Headers not exportable for the $(SRCARCH) architecture)) 914 $(error Headers not exportable for the $(SRCARCH) architecture))
915 $(Q)$(MAKE) $(hdr-inst)=include/uapi 915 $(Q)$(MAKE) $(hdr-inst)=include/uapi
916 $(Q)$(MAKE) $(hdr-inst)=arch/$(hdr-arch)/include/uapi/asm $(hdr-dst) 916 $(Q)$(MAKE) $(hdr-inst)=arch/$(hdr-arch)/include/uapi/asm $(hdr-dst)
917 917
918 PHONY += headers_check_all 918 PHONY += headers_check_all
919 headers_check_all: headers_install_all 919 headers_check_all: headers_install_all
920 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/headers.sh check 920 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/headers.sh check
921 921
922 PHONY += headers_check 922 PHONY += headers_check
923 headers_check: headers_install 923 headers_check: headers_install
924 $(Q)$(MAKE) $(hdr-inst)=include/uapi HDRCHECK=1 924 $(Q)$(MAKE) $(hdr-inst)=include/uapi HDRCHECK=1
925 $(Q)$(MAKE) $(hdr-inst)=arch/$(hdr-arch)/include/uapi/asm $(hdr-dst) HDRCHECK=1 925 $(Q)$(MAKE) $(hdr-inst)=arch/$(hdr-arch)/include/uapi/asm $(hdr-dst) HDRCHECK=1
926 926
927 # --------------------------------------------------------------------------- 927 # ---------------------------------------------------------------------------
928 # Modules 928 # Modules
929 929
930 ifdef CONFIG_MODULES 930 ifdef CONFIG_MODULES
931 931
932 # By default, build modules as well 932 # By default, build modules as well
933 933
934 all: modules 934 all: modules
935 935
936 # Build modules 936 # Build modules
937 # 937 #
938 # A module can be listed more than once in obj-m resulting in 938 # A module can be listed more than once in obj-m resulting in
939 # duplicate lines in modules.order files. Those are removed 939 # duplicate lines in modules.order files. Those are removed
940 # using awk while concatenating to the final file. 940 # using awk while concatenating to the final file.
941 941
942 PHONY += modules 942 PHONY += modules
943 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin 943 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
944 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order 944 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
945 @$(kecho) ' Building modules, stage 2.'; 945 @$(kecho) ' Building modules, stage 2.';
946 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost 946 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
947 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.fwinst obj=firmware __fw_modbuild 947 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.fwinst obj=firmware __fw_modbuild
948 948
949 modules.builtin: $(vmlinux-dirs:%=%/modules.builtin) 949 modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
950 $(Q)$(AWK) '!x[$$0]++' $^ > $(objtree)/modules.builtin 950 $(Q)$(AWK) '!x[$$0]++' $^ > $(objtree)/modules.builtin
951 951
952 %/modules.builtin: include/config/auto.conf 952 %/modules.builtin: include/config/auto.conf
953 $(Q)$(MAKE) $(modbuiltin)=$* 953 $(Q)$(MAKE) $(modbuiltin)=$*
954 954
955 955
956 # Target to prepare building external modules 956 # Target to prepare building external modules
957 PHONY += modules_prepare 957 PHONY += modules_prepare
958 modules_prepare: prepare scripts 958 modules_prepare: prepare scripts
959 959
960 # Target to install modules 960 # Target to install modules
961 PHONY += modules_install 961 PHONY += modules_install
962 modules_install: _modinst_ _modinst_post 962 modules_install: _modinst_ _modinst_post
963 963
964 PHONY += _modinst_ 964 PHONY += _modinst_
965 _modinst_: 965 _modinst_:
966 @rm -rf $(MODLIB)/kernel 966 @rm -rf $(MODLIB)/kernel
967 @rm -f $(MODLIB)/source 967 @rm -f $(MODLIB)/source
968 @mkdir -p $(MODLIB)/kernel 968 @mkdir -p $(MODLIB)/kernel
969 @ln -s $(srctree) $(MODLIB)/source 969 @ln -s $(srctree) $(MODLIB)/source
970 @if [ ! $(objtree) -ef $(MODLIB)/build ]; then \ 970 @if [ ! $(objtree) -ef $(MODLIB)/build ]; then \
971 rm -f $(MODLIB)/build ; \ 971 rm -f $(MODLIB)/build ; \
972 ln -s $(objtree) $(MODLIB)/build ; \ 972 ln -s $(objtree) $(MODLIB)/build ; \
973 fi 973 fi
974 @cp -f $(objtree)/modules.order $(MODLIB)/ 974 @cp -f $(objtree)/modules.order $(MODLIB)/
975 @cp -f $(objtree)/modules.builtin $(MODLIB)/ 975 @cp -f $(objtree)/modules.builtin $(MODLIB)/
976 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst 976 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
977 977
978 # This depmod is only for convenience to give the initial 978 # This depmod is only for convenience to give the initial
979 # boot a modules.dep even before / is mounted read-write. However the 979 # boot a modules.dep even before / is mounted read-write. However the
980 # boot script depmod is the master version. 980 # boot script depmod is the master version.
981 PHONY += _modinst_post 981 PHONY += _modinst_post
982 _modinst_post: _modinst_ 982 _modinst_post: _modinst_
983 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.fwinst obj=firmware __fw_modinst 983 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.fwinst obj=firmware __fw_modinst
984 $(call cmd,depmod) 984 $(call cmd,depmod)
985 985
986 ifeq ($(CONFIG_MODULE_SIG), y) 986 ifeq ($(CONFIG_MODULE_SIG), y)
987 PHONY += modules_sign 987 PHONY += modules_sign
988 modules_sign: 988 modules_sign:
989 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modsign 989 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modsign
990 endif 990 endif
991 991
992 else # CONFIG_MODULES 992 else # CONFIG_MODULES
993 993
994 # Modules not configured 994 # Modules not configured
995 # --------------------------------------------------------------------------- 995 # ---------------------------------------------------------------------------
996 996
997 modules modules_install: FORCE 997 modules modules_install: FORCE
998 @echo >&2 998 @echo >&2
999 @echo >&2 "The present kernel configuration has modules disabled." 999 @echo >&2 "The present kernel configuration has modules disabled."
1000 @echo >&2 "Type 'make config' and enable loadable module support." 1000 @echo >&2 "Type 'make config' and enable loadable module support."
1001 @echo >&2 "Then build a kernel with module support enabled." 1001 @echo >&2 "Then build a kernel with module support enabled."
1002 @echo >&2 1002 @echo >&2
1003 @exit 1 1003 @exit 1
1004 1004
1005 endif # CONFIG_MODULES 1005 endif # CONFIG_MODULES
1006 1006
1007 ### 1007 ###
1008 # Cleaning is done on three levels. 1008 # Cleaning is done on three levels.
1009 # make clean Delete most generated files 1009 # make clean Delete most generated files
1010 # Leave enough to build external modules 1010 # Leave enough to build external modules
1011 # make mrproper Delete the current configuration, and all generated files 1011 # make mrproper Delete the current configuration, and all generated files
1012 # make distclean Remove editor backup files, patch leftover files and the like 1012 # make distclean Remove editor backup files, patch leftover files and the like
1013 1013
1014 # Directories & files removed with 'make clean' 1014 # Directories & files removed with 'make clean'
1015 CLEAN_DIRS += $(MODVERDIR) 1015 CLEAN_DIRS += $(MODVERDIR)
1016 1016
1017 # Directories & files removed with 'make mrproper' 1017 # Directories & files removed with 'make mrproper'
1018 MRPROPER_DIRS += include/config usr/include include/generated \ 1018 MRPROPER_DIRS += include/config usr/include include/generated \
1019 arch/*/include/generated 1019 arch/*/include/generated
1020 MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \ 1020 MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
1021 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \ 1021 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
1022 signing_key.priv signing_key.x509 x509.genkey \ 1022 signing_key.priv signing_key.x509 x509.genkey \
1023 extra_certificates signing_key.x509.keyid \ 1023 extra_certificates signing_key.x509.keyid \
1024 signing_key.x509.signer 1024 signing_key.x509.signer
1025 1025
1026 # clean - Delete most, but leave enough to build external modules 1026 # clean - Delete most, but leave enough to build external modules
1027 # 1027 #
1028 clean: rm-dirs := $(CLEAN_DIRS) 1028 clean: rm-dirs := $(CLEAN_DIRS)
1029 clean: rm-files := $(CLEAN_FILES) 1029 clean: rm-files := $(CLEAN_FILES)
1030 clean-dirs := $(addprefix _clean_, . $(vmlinux-alldirs) Documentation samples) 1030 clean-dirs := $(addprefix _clean_, . $(vmlinux-alldirs) Documentation samples)
1031 1031
1032 PHONY += $(clean-dirs) clean archclean vmlinuxclean 1032 PHONY += $(clean-dirs) clean archclean vmlinuxclean
1033 $(clean-dirs): 1033 $(clean-dirs):
1034 $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@) 1034 $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
1035 1035
1036 vmlinuxclean: 1036 vmlinuxclean:
1037 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean 1037 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean
1038 1038
1039 clean: archclean vmlinuxclean 1039 clean: archclean vmlinuxclean
1040 1040
1041 # mrproper - Delete all generated files, including .config 1041 # mrproper - Delete all generated files, including .config
1042 # 1042 #
1043 mrproper: rm-dirs := $(wildcard $(MRPROPER_DIRS)) 1043 mrproper: rm-dirs := $(wildcard $(MRPROPER_DIRS))
1044 mrproper: rm-files := $(wildcard $(MRPROPER_FILES)) 1044 mrproper: rm-files := $(wildcard $(MRPROPER_FILES))
1045 mrproper-dirs := $(addprefix _mrproper_,Documentation/DocBook scripts) 1045 mrproper-dirs := $(addprefix _mrproper_,Documentation/DocBook scripts)
1046 1046
1047 PHONY += $(mrproper-dirs) mrproper archmrproper 1047 PHONY += $(mrproper-dirs) mrproper archmrproper
1048 $(mrproper-dirs): 1048 $(mrproper-dirs):
1049 $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@) 1049 $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)
1050 1050
1051 mrproper: clean archmrproper $(mrproper-dirs) 1051 mrproper: clean archmrproper $(mrproper-dirs)
1052 $(call cmd,rmdirs) 1052 $(call cmd,rmdirs)
1053 $(call cmd,rmfiles) 1053 $(call cmd,rmfiles)
1054 1054
1055 # distclean 1055 # distclean
1056 # 1056 #
1057 PHONY += distclean 1057 PHONY += distclean
1058 1058
1059 distclean: mrproper 1059 distclean: mrproper
1060 @find $(srctree) $(RCS_FIND_IGNORE) \ 1060 @find $(srctree) $(RCS_FIND_IGNORE) \
1061 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \ 1061 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
1062 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \ 1062 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
1063 -o -name '.*.rej' \ 1063 -o -name '.*.rej' \
1064 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \ 1064 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
1065 -type f -print | xargs rm -f 1065 -type f -print | xargs rm -f
1066 1066
1067 1067
1068 # Packaging of the kernel to various formats 1068 # Packaging of the kernel to various formats
1069 # --------------------------------------------------------------------------- 1069 # ---------------------------------------------------------------------------
1070 # rpm target kept for backward compatibility 1070 # rpm target kept for backward compatibility
1071 package-dir := $(srctree)/scripts/package 1071 package-dir := $(srctree)/scripts/package
1072 1072
1073 %src-pkg: FORCE 1073 %src-pkg: FORCE
1074 $(Q)$(MAKE) $(build)=$(package-dir) $@ 1074 $(Q)$(MAKE) $(build)=$(package-dir) $@
1075 %pkg: include/config/kernel.release FORCE 1075 %pkg: include/config/kernel.release FORCE
1076 $(Q)$(MAKE) $(build)=$(package-dir) $@ 1076 $(Q)$(MAKE) $(build)=$(package-dir) $@
1077 rpm: include/config/kernel.release FORCE 1077 rpm: include/config/kernel.release FORCE
1078 $(Q)$(MAKE) $(build)=$(package-dir) $@ 1078 $(Q)$(MAKE) $(build)=$(package-dir) $@
1079 1079
1080 1080
1081 # Brief documentation of the typical targets used 1081 # Brief documentation of the typical targets used
1082 # --------------------------------------------------------------------------- 1082 # ---------------------------------------------------------------------------
1083 1083
1084 boards := $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*_defconfig) 1084 boards := $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*_defconfig)
1085 boards := $(notdir $(boards)) 1085 boards := $(notdir $(boards))
1086 board-dirs := $(dir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*/*_defconfig)) 1086 board-dirs := $(dir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*/*_defconfig))
1087 board-dirs := $(sort $(notdir $(board-dirs:/=))) 1087 board-dirs := $(sort $(notdir $(board-dirs:/=)))
1088 1088
1089 help: 1089 help:
1090 @echo 'Cleaning targets:' 1090 @echo 'Cleaning targets:'
1091 @echo ' clean - Remove most generated files but keep the config and' 1091 @echo ' clean - Remove most generated files but keep the config and'
1092 @echo ' enough build support to build external modules' 1092 @echo ' enough build support to build external modules'
1093 @echo ' mrproper - Remove all generated files + config + various backup files' 1093 @echo ' mrproper - Remove all generated files + config + various backup files'
1094 @echo ' distclean - mrproper + remove editor backup and patch files' 1094 @echo ' distclean - mrproper + remove editor backup and patch files'
1095 @echo '' 1095 @echo ''
1096 @echo 'Configuration targets:' 1096 @echo 'Configuration targets:'
1097 @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help 1097 @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
1098 @echo '' 1098 @echo ''
1099 @echo 'Other generic targets:' 1099 @echo 'Other generic targets:'
1100 @echo ' all - Build all targets marked with [*]' 1100 @echo ' all - Build all targets marked with [*]'
1101 @echo '* vmlinux - Build the bare kernel' 1101 @echo '* vmlinux - Build the bare kernel'
1102 @echo '* modules - Build all modules' 1102 @echo '* modules - Build all modules'
1103 @echo ' modules_install - Install all modules to INSTALL_MOD_PATH (default: /)' 1103 @echo ' modules_install - Install all modules to INSTALL_MOD_PATH (default: /)'
1104 @echo ' firmware_install- Install all firmware to INSTALL_FW_PATH' 1104 @echo ' firmware_install- Install all firmware to INSTALL_FW_PATH'
1105 @echo ' (default: $$(INSTALL_MOD_PATH)/lib/firmware)' 1105 @echo ' (default: $$(INSTALL_MOD_PATH)/lib/firmware)'
1106 @echo ' dir/ - Build all files in dir and below' 1106 @echo ' dir/ - Build all files in dir and below'
1107 @echo ' dir/file.[oisS] - Build specified target only' 1107 @echo ' dir/file.[oisS] - Build specified target only'
1108 @echo ' dir/file.lst - Build specified mixed source/assembly target only' 1108 @echo ' dir/file.lst - Build specified mixed source/assembly target only'
1109 @echo ' (requires a recent binutils and recent build (System.map))' 1109 @echo ' (requires a recent binutils and recent build (System.map))'
1110 @echo ' dir/file.ko - Build module including final link' 1110 @echo ' dir/file.ko - Build module including final link'
1111 @echo ' modules_prepare - Set up for building external modules' 1111 @echo ' modules_prepare - Set up for building external modules'
1112 @echo ' tags/TAGS - Generate tags file for editors' 1112 @echo ' tags/TAGS - Generate tags file for editors'
1113 @echo ' cscope - Generate cscope index' 1113 @echo ' cscope - Generate cscope index'
1114 @echo ' gtags - Generate GNU GLOBAL index' 1114 @echo ' gtags - Generate GNU GLOBAL index'
1115 @echo ' kernelrelease - Output the release version string' 1115 @echo ' kernelrelease - Output the release version string'
1116 @echo ' kernelversion - Output the version stored in Makefile' 1116 @echo ' kernelversion - Output the version stored in Makefile'
1117 @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \ 1117 @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \
1118 echo ' (default: $(INSTALL_HDR_PATH))'; \ 1118 echo ' (default: $(INSTALL_HDR_PATH))'; \
1119 echo '' 1119 echo ''
1120 @echo 'Static analysers' 1120 @echo 'Static analysers'
1121 @echo ' checkstack - Generate a list of stack hogs' 1121 @echo ' checkstack - Generate a list of stack hogs'
1122 @echo ' namespacecheck - Name space analysis on compiled kernel' 1122 @echo ' namespacecheck - Name space analysis on compiled kernel'
1123 @echo ' versioncheck - Sanity check on version.h usage' 1123 @echo ' versioncheck - Sanity check on version.h usage'
1124 @echo ' includecheck - Check for duplicate included header files' 1124 @echo ' includecheck - Check for duplicate included header files'
1125 @echo ' export_report - List the usages of all exported symbols' 1125 @echo ' export_report - List the usages of all exported symbols'
1126 @echo ' headers_check - Sanity check on exported headers' 1126 @echo ' headers_check - Sanity check on exported headers'
1127 @echo ' headerdep - Detect inclusion cycles in headers' 1127 @echo ' headerdep - Detect inclusion cycles in headers'
1128 @$(MAKE) -f $(srctree)/scripts/Makefile.help checker-help 1128 @$(MAKE) -f $(srctree)/scripts/Makefile.help checker-help
1129 @echo '' 1129 @echo ''
1130 @echo 'Kernel packaging:' 1130 @echo 'Kernel packaging:'
1131 @$(MAKE) $(build)=$(package-dir) help 1131 @$(MAKE) $(build)=$(package-dir) help
1132 @echo '' 1132 @echo ''
1133 @echo 'Documentation targets:' 1133 @echo 'Documentation targets:'
1134 @$(MAKE) -f $(srctree)/Documentation/DocBook/Makefile dochelp 1134 @$(MAKE) -f $(srctree)/Documentation/DocBook/Makefile dochelp
1135 @echo '' 1135 @echo ''
1136 @echo 'Architecture specific targets ($(SRCARCH)):' 1136 @echo 'Architecture specific targets ($(SRCARCH)):'
1137 @$(if $(archhelp),$(archhelp),\ 1137 @$(if $(archhelp),$(archhelp),\
1138 echo ' No architecture specific help defined for $(SRCARCH)') 1138 echo ' No architecture specific help defined for $(SRCARCH)')
1139 @echo '' 1139 @echo ''
1140 @$(if $(boards), \ 1140 @$(if $(boards), \
1141 $(foreach b, $(boards), \ 1141 $(foreach b, $(boards), \
1142 printf " %-24s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \ 1142 printf " %-24s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
1143 echo '') 1143 echo '')
1144 @$(if $(board-dirs), \ 1144 @$(if $(board-dirs), \
1145 $(foreach b, $(board-dirs), \ 1145 $(foreach b, $(board-dirs), \
1146 printf " %-16s - Show %s-specific targets\\n" help-$(b) $(b);) \ 1146 printf " %-16s - Show %s-specific targets\\n" help-$(b) $(b);) \
1147 printf " %-16s - Show all of the above\\n" help-boards; \ 1147 printf " %-16s - Show all of the above\\n" help-boards; \
1148 echo '') 1148 echo '')
1149 1149
1150 @echo ' make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build' 1150 @echo ' make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build'
1151 @echo ' make V=2 [targets] 2 => give reason for rebuild of target' 1151 @echo ' make V=2 [targets] 2 => give reason for rebuild of target'
1152 @echo ' make O=dir [targets] Locate all output files in "dir", including .config' 1152 @echo ' make O=dir [targets] Locate all output files in "dir", including .config'
1153 @echo ' make C=1 [targets] Check all c source with $$CHECK (sparse by default)' 1153 @echo ' make C=1 [targets] Check all c source with $$CHECK (sparse by default)'
1154 @echo ' make C=2 [targets] Force check of all c source with $$CHECK' 1154 @echo ' make C=2 [targets] Force check of all c source with $$CHECK'
1155 @echo ' make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections' 1155 @echo ' make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections'
1156 @echo ' make W=n [targets] Enable extra gcc checks, n=1,2,3 where' 1156 @echo ' make W=n [targets] Enable extra gcc checks, n=1,2,3 where'
1157 @echo ' 1: warnings which may be relevant and do not occur too often' 1157 @echo ' 1: warnings which may be relevant and do not occur too often'
1158 @echo ' 2: warnings which occur quite often but may still be relevant' 1158 @echo ' 2: warnings which occur quite often but may still be relevant'
1159 @echo ' 3: more obscure warnings, can most likely be ignored' 1159 @echo ' 3: more obscure warnings, can most likely be ignored'
1160 @echo ' Multiple levels can be combined with W=12 or W=123' 1160 @echo ' Multiple levels can be combined with W=12 or W=123'
1161 @echo '' 1161 @echo ''
1162 @echo 'Execute "make" or "make all" to build all targets marked with [*] ' 1162 @echo 'Execute "make" or "make all" to build all targets marked with [*] '
1163 @echo 'For further info see the ./README file' 1163 @echo 'For further info see the ./README file'
1164 1164
1165 1165
1166 help-board-dirs := $(addprefix help-,$(board-dirs)) 1166 help-board-dirs := $(addprefix help-,$(board-dirs))
1167 1167
1168 help-boards: $(help-board-dirs) 1168 help-boards: $(help-board-dirs)
1169 1169
1170 boards-per-dir = $(notdir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/$*/*_defconfig)) 1170 boards-per-dir = $(notdir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/$*/*_defconfig))
1171 1171
1172 $(help-board-dirs): help-%: 1172 $(help-board-dirs): help-%:
1173 @echo 'Architecture specific targets ($(SRCARCH) $*):' 1173 @echo 'Architecture specific targets ($(SRCARCH) $*):'
1174 @$(if $(boards-per-dir), \ 1174 @$(if $(boards-per-dir), \
1175 $(foreach b, $(boards-per-dir), \ 1175 $(foreach b, $(boards-per-dir), \
1176 printf " %-24s - Build for %s\\n" $*/$(b) $(subst _defconfig,,$(b));) \ 1176 printf " %-24s - Build for %s\\n" $*/$(b) $(subst _defconfig,,$(b));) \
1177 echo '') 1177 echo '')
1178 1178
1179 1179
1180 # Documentation targets 1180 # Documentation targets
1181 # --------------------------------------------------------------------------- 1181 # ---------------------------------------------------------------------------
1182 %docs: scripts_basic FORCE 1182 %docs: scripts_basic FORCE
1183 $(Q)$(MAKE) $(build)=scripts build_docproc 1183 $(Q)$(MAKE) $(build)=scripts build_docproc
1184 $(Q)$(MAKE) $(build)=Documentation/DocBook $@ 1184 $(Q)$(MAKE) $(build)=Documentation/DocBook $@
1185 1185
1186 else # KBUILD_EXTMOD 1186 else # KBUILD_EXTMOD
1187 1187
1188 ### 1188 ###
1189 # External module support. 1189 # External module support.
1190 # When building external modules the kernel used as basis is considered 1190 # When building external modules the kernel used as basis is considered
1191 # read-only, and no consistency checks are made and the make 1191 # read-only, and no consistency checks are made and the make
1192 # system is not used on the basis kernel. If updates are required 1192 # system is not used on the basis kernel. If updates are required
1193 # in the basis kernel ordinary make commands (without M=...) must 1193 # in the basis kernel ordinary make commands (without M=...) must
1194 # be used. 1194 # be used.
1195 # 1195 #
1196 # The following are the only valid targets when building external 1196 # The following are the only valid targets when building external
1197 # modules. 1197 # modules.
1198 # make M=dir clean Delete all automatically generated files 1198 # make M=dir clean Delete all automatically generated files
1199 # make M=dir modules Make all modules in specified dir 1199 # make M=dir modules Make all modules in specified dir
1200 # make M=dir Same as 'make M=dir modules' 1200 # make M=dir Same as 'make M=dir modules'
1201 # make M=dir modules_install 1201 # make M=dir modules_install
1202 # Install the modules built in the module directory 1202 # Install the modules built in the module directory
1203 # Assumes install directory is already created 1203 # Assumes install directory is already created
1204 1204
1205 # We are always building modules 1205 # We are always building modules
1206 KBUILD_MODULES := 1 1206 KBUILD_MODULES := 1
1207 PHONY += crmodverdir 1207 PHONY += crmodverdir
1208 crmodverdir: 1208 crmodverdir:
1209 $(cmd_crmodverdir) 1209 $(cmd_crmodverdir)
1210 1210
1211 PHONY += $(objtree)/Module.symvers 1211 PHONY += $(objtree)/Module.symvers
1212 $(objtree)/Module.symvers: 1212 $(objtree)/Module.symvers:
1213 @test -e $(objtree)/Module.symvers || ( \ 1213 @test -e $(objtree)/Module.symvers || ( \
1214 echo; \ 1214 echo; \
1215 echo " WARNING: Symbol version dump $(objtree)/Module.symvers"; \ 1215 echo " WARNING: Symbol version dump $(objtree)/Module.symvers"; \
1216 echo " is missing; modules will have no dependencies and modversions."; \ 1216 echo " is missing; modules will have no dependencies and modversions."; \
1217 echo ) 1217 echo )
1218 1218
1219 module-dirs := $(addprefix _module_,$(KBUILD_EXTMOD)) 1219 module-dirs := $(addprefix _module_,$(KBUILD_EXTMOD))
1220 PHONY += $(module-dirs) modules 1220 PHONY += $(module-dirs) modules
1221 $(module-dirs): crmodverdir $(objtree)/Module.symvers 1221 $(module-dirs): crmodverdir $(objtree)/Module.symvers
1222 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@) 1222 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
1223 1223
1224 modules: $(module-dirs) 1224 modules: $(module-dirs)
1225 @$(kecho) ' Building modules, stage 2.'; 1225 @$(kecho) ' Building modules, stage 2.';
1226 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost 1226 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
1227 1227
1228 PHONY += modules_install 1228 PHONY += modules_install
1229 modules_install: _emodinst_ _emodinst_post 1229 modules_install: _emodinst_ _emodinst_post
1230 1230
1231 install-dir := $(if $(INSTALL_MOD_DIR),$(INSTALL_MOD_DIR),extra) 1231 install-dir := $(if $(INSTALL_MOD_DIR),$(INSTALL_MOD_DIR),extra)
1232 PHONY += _emodinst_ 1232 PHONY += _emodinst_
1233 _emodinst_: 1233 _emodinst_:
1234 $(Q)mkdir -p $(MODLIB)/$(install-dir) 1234 $(Q)mkdir -p $(MODLIB)/$(install-dir)
1235 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst 1235 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
1236 1236
1237 PHONY += _emodinst_post 1237 PHONY += _emodinst_post
1238 _emodinst_post: _emodinst_ 1238 _emodinst_post: _emodinst_
1239 $(call cmd,depmod) 1239 $(call cmd,depmod)
1240 1240
1241 clean-dirs := $(addprefix _clean_,$(KBUILD_EXTMOD)) 1241 clean-dirs := $(addprefix _clean_,$(KBUILD_EXTMOD))
1242 1242
1243 PHONY += $(clean-dirs) clean 1243 PHONY += $(clean-dirs) clean
1244 $(clean-dirs): 1244 $(clean-dirs):
1245 $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@) 1245 $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
1246 1246
1247 clean: rm-dirs := $(MODVERDIR) 1247 clean: rm-dirs := $(MODVERDIR)
1248 clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers 1248 clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers
1249 1249
1250 help: 1250 help:
1251 @echo ' Building external modules.' 1251 @echo ' Building external modules.'
1252 @echo ' Syntax: make -C path/to/kernel/src M=$$PWD target' 1252 @echo ' Syntax: make -C path/to/kernel/src M=$$PWD target'
1253 @echo '' 1253 @echo ''
1254 @echo ' modules - default target, build the module(s)' 1254 @echo ' modules - default target, build the module(s)'
1255 @echo ' modules_install - install the module' 1255 @echo ' modules_install - install the module'
1256 @echo ' clean - remove generated files in module directory only' 1256 @echo ' clean - remove generated files in module directory only'
1257 @echo '' 1257 @echo ''
1258 1258
1259 # Dummies... 1259 # Dummies...
1260 PHONY += prepare scripts 1260 PHONY += prepare scripts
1261 prepare: ; 1261 prepare: ;
1262 scripts: ; 1262 scripts: ;
1263 endif # KBUILD_EXTMOD 1263 endif # KBUILD_EXTMOD
1264 1264
1265 clean: $(clean-dirs) 1265 clean: $(clean-dirs)
1266 $(call cmd,rmdirs) 1266 $(call cmd,rmdirs)
1267 $(call cmd,rmfiles) 1267 $(call cmd,rmfiles)
1268 @find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \ 1268 @find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
1269 \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \ 1269 \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
1270 -o -name '*.ko.*' \ 1270 -o -name '*.ko.*' \
1271 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ 1271 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
1272 -o -name '*.symtypes' -o -name 'modules.order' \ 1272 -o -name '*.symtypes' -o -name 'modules.order' \
1273 -o -name modules.builtin -o -name '.tmp_*.o.*' \ 1273 -o -name modules.builtin -o -name '.tmp_*.o.*' \
1274 -o -name '*.gcno' \) -type f -print | xargs rm -f 1274 -o -name '*.gcno' \) -type f -print | xargs rm -f
1275 1275
1276 # Generate tags for editors 1276 # Generate tags for editors
1277 # --------------------------------------------------------------------------- 1277 # ---------------------------------------------------------------------------
1278 quiet_cmd_tags = GEN $@ 1278 quiet_cmd_tags = GEN $@
1279 cmd_tags = $(CONFIG_SHELL) $(srctree)/scripts/tags.sh $@ 1279 cmd_tags = $(CONFIG_SHELL) $(srctree)/scripts/tags.sh $@
1280 1280
1281 tags TAGS cscope gtags: FORCE 1281 tags TAGS cscope gtags: FORCE
1282 $(call cmd,tags) 1282 $(call cmd,tags)
1283 1283
1284 # Scripts to check various things for consistency 1284 # Scripts to check various things for consistency
1285 # --------------------------------------------------------------------------- 1285 # ---------------------------------------------------------------------------
1286 1286
1287 PHONY += includecheck versioncheck coccicheck namespacecheck export_report 1287 PHONY += includecheck versioncheck coccicheck namespacecheck export_report
1288 1288
1289 includecheck: 1289 includecheck:
1290 find $(srctree)/* $(RCS_FIND_IGNORE) \ 1290 find $(srctree)/* $(RCS_FIND_IGNORE) \
1291 -name '*.[hcS]' -type f -print | sort \ 1291 -name '*.[hcS]' -type f -print | sort \
1292 | xargs $(PERL) -w $(srctree)/scripts/checkincludes.pl 1292 | xargs $(PERL) -w $(srctree)/scripts/checkincludes.pl
1293 1293
1294 versioncheck: 1294 versioncheck:
1295 find $(srctree)/* $(RCS_FIND_IGNORE) \ 1295 find $(srctree)/* $(RCS_FIND_IGNORE) \
1296 -name '*.[hcS]' -type f -print | sort \ 1296 -name '*.[hcS]' -type f -print | sort \
1297 | xargs $(PERL) -w $(srctree)/scripts/checkversion.pl 1297 | xargs $(PERL) -w $(srctree)/scripts/checkversion.pl
1298 1298
1299 coccicheck: 1299 coccicheck:
1300 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/$@ 1300 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/$@
1301 1301
1302 namespacecheck: 1302 namespacecheck:
1303 $(PERL) $(srctree)/scripts/namespace.pl 1303 $(PERL) $(srctree)/scripts/namespace.pl
1304 1304
1305 export_report: 1305 export_report:
1306 $(PERL) $(srctree)/scripts/export_report.pl 1306 $(PERL) $(srctree)/scripts/export_report.pl
1307 1307
1308 endif #ifeq ($(config-targets),1) 1308 endif #ifeq ($(config-targets),1)
1309 endif #ifeq ($(mixed-targets),1) 1309 endif #ifeq ($(mixed-targets),1)
1310 1310
1311 PHONY += checkstack kernelrelease kernelversion 1311 PHONY += checkstack kernelrelease kernelversion
1312 1312
1313 # UML needs a little special treatment here. It wants to use the host 1313 # UML needs a little special treatment here. It wants to use the host
1314 # toolchain, so needs $(SUBARCH) passed to checkstack.pl. Everyone 1314 # toolchain, so needs $(SUBARCH) passed to checkstack.pl. Everyone
1315 # else wants $(ARCH), including people doing cross-builds, which means 1315 # else wants $(ARCH), including people doing cross-builds, which means
1316 # that $(SUBARCH) doesn't work here. 1316 # that $(SUBARCH) doesn't work here.
1317 ifeq ($(ARCH), um) 1317 ifeq ($(ARCH), um)
1318 CHECKSTACK_ARCH := $(SUBARCH) 1318 CHECKSTACK_ARCH := $(SUBARCH)
1319 else 1319 else
1320 CHECKSTACK_ARCH := $(ARCH) 1320 CHECKSTACK_ARCH := $(ARCH)
1321 endif 1321 endif
1322 checkstack: 1322 checkstack:
1323 $(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \ 1323 $(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \
1324 $(PERL) $(src)/scripts/checkstack.pl $(CHECKSTACK_ARCH) 1324 $(PERL) $(src)/scripts/checkstack.pl $(CHECKSTACK_ARCH)
1325 1325
1326 kernelrelease: 1326 kernelrelease:
1327 @echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))" 1327 @echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"
1328 1328
1329 kernelversion: 1329 kernelversion:
1330 @echo $(KERNELVERSION) 1330 @echo $(KERNELVERSION)
1331 1331
1332 # Clear a bunch of variables before executing the submake 1332 # Clear a bunch of variables before executing the submake
1333 tools/: FORCE 1333 tools/: FORCE
1334 $(Q)mkdir -p $(objtree)/tools 1334 $(Q)mkdir -p $(objtree)/tools
1335 $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(filter --j% -j,$(MAKEFLAGS))" O=$(objtree) subdir=tools -C $(src)/tools/ 1335 $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(filter --j% -j,$(MAKEFLAGS))" O=$(objtree) subdir=tools -C $(src)/tools/
1336 1336
1337 tools/%: FORCE 1337 tools/%: FORCE
1338 $(Q)mkdir -p $(objtree)/tools 1338 $(Q)mkdir -p $(objtree)/tools
1339 $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(filter --j% -j,$(MAKEFLAGS))" O=$(objtree) subdir=tools -C $(src)/tools/ $* 1339 $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(filter --j% -j,$(MAKEFLAGS))" O=$(objtree) subdir=tools -C $(src)/tools/ $*
1340 1340
1341 # Single targets 1341 # Single targets
1342 # --------------------------------------------------------------------------- 1342 # ---------------------------------------------------------------------------
1343 # Single targets are compatible with: 1343 # Single targets are compatible with:
1344 # - build with mixed source and output 1344 # - build with mixed source and output
1345 # - build with separate output dir 'make O=...' 1345 # - build with separate output dir 'make O=...'
1346 # - external modules 1346 # - external modules
1347 # 1347 #
1348 # target-dir => where to store outputfile 1348 # target-dir => where to store outputfile
1349 # build-dir => directory in kernel source tree to use 1349 # build-dir => directory in kernel source tree to use
1350 1350
1351 ifeq ($(KBUILD_EXTMOD),) 1351 ifeq ($(KBUILD_EXTMOD),)
1352 build-dir = $(patsubst %/,%,$(dir $@)) 1352 build-dir = $(patsubst %/,%,$(dir $@))
1353 target-dir = $(dir $@) 1353 target-dir = $(dir $@)
1354 else 1354 else
1355 zap-slash=$(filter-out .,$(patsubst %/,%,$(dir $@))) 1355 zap-slash=$(filter-out .,$(patsubst %/,%,$(dir $@)))
1356 build-dir = $(KBUILD_EXTMOD)$(if $(zap-slash),/$(zap-slash)) 1356 build-dir = $(KBUILD_EXTMOD)$(if $(zap-slash),/$(zap-slash))
1357 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@)) 1357 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
1358 endif 1358 endif
1359 1359
1360 %.s: %.c prepare scripts FORCE 1360 %.s: %.c prepare scripts FORCE
1361 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) 1361 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1362 %.i: %.c prepare scripts FORCE 1362 %.i: %.c prepare scripts FORCE
1363 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) 1363 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1364 %.o: %.c prepare scripts FORCE 1364 %.o: %.c prepare scripts FORCE
1365 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) 1365 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1366 %.lst: %.c prepare scripts FORCE 1366 %.lst: %.c prepare scripts FORCE
1367 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) 1367 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1368 %.s: %.S prepare scripts FORCE 1368 %.s: %.S prepare scripts FORCE
1369 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) 1369 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1370 %.o: %.S prepare scripts FORCE 1370 %.o: %.S prepare scripts FORCE
1371 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) 1371 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1372 %.symtypes: %.c prepare scripts FORCE 1372 %.symtypes: %.c prepare scripts FORCE
1373 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) 1373 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1374 1374
1375 # Modules 1375 # Modules
1376 /: prepare scripts FORCE 1376 /: prepare scripts FORCE
1377 $(cmd_crmodverdir) 1377 $(cmd_crmodverdir)
1378 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ 1378 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
1379 $(build)=$(build-dir) 1379 $(build)=$(build-dir)
1380 %/: prepare scripts FORCE 1380 %/: prepare scripts FORCE
1381 $(cmd_crmodverdir) 1381 $(cmd_crmodverdir)
1382 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ 1382 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
1383 $(build)=$(build-dir) 1383 $(build)=$(build-dir)
1384 %.ko: prepare scripts FORCE 1384 %.ko: prepare scripts FORCE
1385 $(cmd_crmodverdir) 1385 $(cmd_crmodverdir)
1386 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \ 1386 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
1387 $(build)=$(build-dir) $(@:.ko=.o) 1387 $(build)=$(build-dir) $(@:.ko=.o)
1388 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost 1388 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
1389 1389
1390 # FIXME Should go into a make.lib or something 1390 # FIXME Should go into a make.lib or something
1391 # =========================================================================== 1391 # ===========================================================================
1392 1392
1393 quiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN $(wildcard $(rm-dirs))) 1393 quiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN $(wildcard $(rm-dirs)))
1394 cmd_rmdirs = rm -rf $(rm-dirs) 1394 cmd_rmdirs = rm -rf $(rm-dirs)
1395 1395
1396 quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files))) 1396 quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files)))
1397 cmd_rmfiles = rm -f $(rm-files) 1397 cmd_rmfiles = rm -f $(rm-files)
1398 1398
1399 # Run depmod only if we have System.map and depmod is executable 1399 # Run depmod only if we have System.map and depmod is executable
1400 quiet_cmd_depmod = DEPMOD $(KERNELRELEASE) 1400 quiet_cmd_depmod = DEPMOD $(KERNELRELEASE)
1401 cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \ 1401 cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \
1402 $(KERNELRELEASE) "$(patsubst "%",%,$(CONFIG_SYMBOL_PREFIX))" 1402 $(KERNELRELEASE) "$(patsubst y,_,$(CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX))"
1403 1403
1404 # Create temporary dir for module support files 1404 # Create temporary dir for module support files
1405 # clean it up only when building all modules 1405 # clean it up only when building all modules
1406 cmd_crmodverdir = $(Q)mkdir -p $(MODVERDIR) \ 1406 cmd_crmodverdir = $(Q)mkdir -p $(MODVERDIR) \
1407 $(if $(KBUILD_MODULES),; rm -f $(MODVERDIR)/*) 1407 $(if $(KBUILD_MODULES),; rm -f $(MODVERDIR)/*)
1408 1408
1409 # read all saved command lines 1409 # read all saved command lines
1410 1410
1411 targets := $(wildcard $(sort $(targets))) 1411 targets := $(wildcard $(sort $(targets)))
1412 cmd_files := $(wildcard .*.cmd $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) 1412 cmd_files := $(wildcard .*.cmd $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
1413 1413
1414 ifneq ($(cmd_files),) 1414 ifneq ($(cmd_files),)
1415 $(cmd_files): ; # Do not try to update included dependency files 1415 $(cmd_files): ; # Do not try to update included dependency files
1416 include $(cmd_files) 1416 include $(cmd_files)
1417 endif 1417 endif
1418 1418
1419 # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=dir 1419 # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=dir
1420 # Usage: 1420 # Usage:
1421 # $(Q)$(MAKE) $(clean)=dir 1421 # $(Q)$(MAKE) $(clean)=dir
1422 clean := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.clean obj 1422 clean := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.clean obj
1423 1423
1424 endif # skip-makefile 1424 endif # skip-makefile
1425 1425
1426 PHONY += FORCE 1426 PHONY += FORCE
1427 FORCE: 1427 FORCE:
1428 1428
1429 # Declare the contents of the .PHONY variable as phony. We keep that 1429 # Declare the contents of the .PHONY variable as phony. We keep that
1430 # information in a variable so we can use it in if_changed and friends. 1430 # information in a variable so we can use it in if_changed and friends.
1431 .PHONY: $(PHONY) 1431 .PHONY: $(PHONY)
1432 1432
1 # 1 #
2 # General architecture dependent options 2 # General architecture dependent options
3 # 3 #
4 4
5 config OPROFILE 5 config OPROFILE
6 tristate "OProfile system profiling" 6 tristate "OProfile system profiling"
7 depends on PROFILING 7 depends on PROFILING
8 depends on HAVE_OPROFILE 8 depends on HAVE_OPROFILE
9 select RING_BUFFER 9 select RING_BUFFER
10 select RING_BUFFER_ALLOW_SWAP 10 select RING_BUFFER_ALLOW_SWAP
11 help 11 help
12 OProfile is a profiling system capable of profiling the 12 OProfile is a profiling system capable of profiling the
13 whole system, include the kernel, kernel modules, libraries, 13 whole system, include the kernel, kernel modules, libraries,
14 and applications. 14 and applications.
15 15
16 If unsure, say N. 16 If unsure, say N.
17 17
18 config OPROFILE_EVENT_MULTIPLEX 18 config OPROFILE_EVENT_MULTIPLEX
19 bool "OProfile multiplexing support (EXPERIMENTAL)" 19 bool "OProfile multiplexing support (EXPERIMENTAL)"
20 default n 20 default n
21 depends on OPROFILE && X86 21 depends on OPROFILE && X86
22 help 22 help
23 The number of hardware counters is limited. The multiplexing 23 The number of hardware counters is limited. The multiplexing
24 feature enables OProfile to gather more events than counters 24 feature enables OProfile to gather more events than counters
25 are provided by the hardware. This is realized by switching 25 are provided by the hardware. This is realized by switching
26 between events at an user specified time interval. 26 between events at an user specified time interval.
27 27
28 If unsure, say N. 28 If unsure, say N.
29 29
30 config HAVE_OPROFILE 30 config HAVE_OPROFILE
31 bool 31 bool
32 32
33 config OPROFILE_NMI_TIMER 33 config OPROFILE_NMI_TIMER
34 def_bool y 34 def_bool y
35 depends on PERF_EVENTS && HAVE_PERF_EVENTS_NMI 35 depends on PERF_EVENTS && HAVE_PERF_EVENTS_NMI
36 36
37 config KPROBES 37 config KPROBES
38 bool "Kprobes" 38 bool "Kprobes"
39 depends on MODULES 39 depends on MODULES
40 depends on HAVE_KPROBES 40 depends on HAVE_KPROBES
41 select KALLSYMS 41 select KALLSYMS
42 help 42 help
43 Kprobes allows you to trap at almost any kernel address and 43 Kprobes allows you to trap at almost any kernel address and
44 execute a callback function. register_kprobe() establishes 44 execute a callback function. register_kprobe() establishes
45 a probepoint and specifies the callback. Kprobes is useful 45 a probepoint and specifies the callback. Kprobes is useful
46 for kernel debugging, non-intrusive instrumentation and testing. 46 for kernel debugging, non-intrusive instrumentation and testing.
47 If in doubt, say "N". 47 If in doubt, say "N".
48 48
49 config JUMP_LABEL 49 config JUMP_LABEL
50 bool "Optimize very unlikely/likely branches" 50 bool "Optimize very unlikely/likely branches"
51 depends on HAVE_ARCH_JUMP_LABEL 51 depends on HAVE_ARCH_JUMP_LABEL
52 help 52 help
53 This option enables a transparent branch optimization that 53 This option enables a transparent branch optimization that
54 makes certain almost-always-true or almost-always-false branch 54 makes certain almost-always-true or almost-always-false branch
55 conditions even cheaper to execute within the kernel. 55 conditions even cheaper to execute within the kernel.
56 56
57 Certain performance-sensitive kernel code, such as trace points, 57 Certain performance-sensitive kernel code, such as trace points,
58 scheduler functionality, networking code and KVM have such 58 scheduler functionality, networking code and KVM have such
59 branches and include support for this optimization technique. 59 branches and include support for this optimization technique.
60 60
61 If it is detected that the compiler has support for "asm goto", 61 If it is detected that the compiler has support for "asm goto",
62 the kernel will compile such branches with just a nop 62 the kernel will compile such branches with just a nop
63 instruction. When the condition flag is toggled to true, the 63 instruction. When the condition flag is toggled to true, the
64 nop will be converted to a jump instruction to execute the 64 nop will be converted to a jump instruction to execute the
65 conditional block of instructions. 65 conditional block of instructions.
66 66
67 This technique lowers overhead and stress on the branch prediction 67 This technique lowers overhead and stress on the branch prediction
68 of the processor and generally makes the kernel faster. The update 68 of the processor and generally makes the kernel faster. The update
69 of the condition is slower, but those are always very rare. 69 of the condition is slower, but those are always very rare.
70 70
71 ( On 32-bit x86, the necessary options added to the compiler 71 ( On 32-bit x86, the necessary options added to the compiler
72 flags may increase the size of the kernel slightly. ) 72 flags may increase the size of the kernel slightly. )
73 73
74 config OPTPROBES 74 config OPTPROBES
75 def_bool y 75 def_bool y
76 depends on KPROBES && HAVE_OPTPROBES 76 depends on KPROBES && HAVE_OPTPROBES
77 depends on !PREEMPT 77 depends on !PREEMPT
78 78
79 config KPROBES_ON_FTRACE 79 config KPROBES_ON_FTRACE
80 def_bool y 80 def_bool y
81 depends on KPROBES && HAVE_KPROBES_ON_FTRACE 81 depends on KPROBES && HAVE_KPROBES_ON_FTRACE
82 depends on DYNAMIC_FTRACE_WITH_REGS 82 depends on DYNAMIC_FTRACE_WITH_REGS
83 help 83 help
84 If function tracer is enabled and the arch supports full 84 If function tracer is enabled and the arch supports full
85 passing of pt_regs to function tracing, then kprobes can 85 passing of pt_regs to function tracing, then kprobes can
86 optimize on top of function tracing. 86 optimize on top of function tracing.
87 87
88 config UPROBES 88 config UPROBES
89 bool "Transparent user-space probes (EXPERIMENTAL)" 89 bool "Transparent user-space probes (EXPERIMENTAL)"
90 depends on UPROBE_EVENT && PERF_EVENTS 90 depends on UPROBE_EVENT && PERF_EVENTS
91 default n 91 default n
92 select PERCPU_RWSEM 92 select PERCPU_RWSEM
93 help 93 help
94 Uprobes is the user-space counterpart to kprobes: they 94 Uprobes is the user-space counterpart to kprobes: they
95 enable instrumentation applications (such as 'perf probe') 95 enable instrumentation applications (such as 'perf probe')
96 to establish unintrusive probes in user-space binaries and 96 to establish unintrusive probes in user-space binaries and
97 libraries, by executing handler functions when the probes 97 libraries, by executing handler functions when the probes
98 are hit by user-space applications. 98 are hit by user-space applications.
99 99
100 ( These probes come in the form of single-byte breakpoints, 100 ( These probes come in the form of single-byte breakpoints,
101 managed by the kernel and kept transparent to the probed 101 managed by the kernel and kept transparent to the probed
102 application. ) 102 application. )
103 103
104 If in doubt, say "N". 104 If in doubt, say "N".
105 105
106 config HAVE_64BIT_ALIGNED_ACCESS 106 config HAVE_64BIT_ALIGNED_ACCESS
107 def_bool 64BIT && !HAVE_EFFICIENT_UNALIGNED_ACCESS 107 def_bool 64BIT && !HAVE_EFFICIENT_UNALIGNED_ACCESS
108 help 108 help
109 Some architectures require 64 bit accesses to be 64 bit 109 Some architectures require 64 bit accesses to be 64 bit
110 aligned, which also requires structs containing 64 bit values 110 aligned, which also requires structs containing 64 bit values
111 to be 64 bit aligned too. This includes some 32 bit 111 to be 64 bit aligned too. This includes some 32 bit
112 architectures which can do 64 bit accesses, as well as 64 bit 112 architectures which can do 64 bit accesses, as well as 64 bit
113 architectures without unaligned access. 113 architectures without unaligned access.
114 114
115 This symbol should be selected by an architecture if 64 bit 115 This symbol should be selected by an architecture if 64 bit
116 accesses are required to be 64 bit aligned in this way even 116 accesses are required to be 64 bit aligned in this way even
117 though it is not a 64 bit architecture. 117 though it is not a 64 bit architecture.
118 118
119 See Documentation/unaligned-memory-access.txt for more 119 See Documentation/unaligned-memory-access.txt for more
120 information on the topic of unaligned memory accesses. 120 information on the topic of unaligned memory accesses.
121 121
122 config HAVE_EFFICIENT_UNALIGNED_ACCESS 122 config HAVE_EFFICIENT_UNALIGNED_ACCESS
123 bool 123 bool
124 help 124 help
125 Some architectures are unable to perform unaligned accesses 125 Some architectures are unable to perform unaligned accesses
126 without the use of get_unaligned/put_unaligned. Others are 126 without the use of get_unaligned/put_unaligned. Others are
127 unable to perform such accesses efficiently (e.g. trap on 127 unable to perform such accesses efficiently (e.g. trap on
128 unaligned access and require fixing it up in the exception 128 unaligned access and require fixing it up in the exception
129 handler.) 129 handler.)
130 130
131 This symbol should be selected by an architecture if it can 131 This symbol should be selected by an architecture if it can
132 perform unaligned accesses efficiently to allow different 132 perform unaligned accesses efficiently to allow different
133 code paths to be selected for these cases. Some network 133 code paths to be selected for these cases. Some network
134 drivers, for example, could opt to not fix up alignment 134 drivers, for example, could opt to not fix up alignment
135 problems with received packets if doing so would not help 135 problems with received packets if doing so would not help
136 much. 136 much.
137 137
138 See Documentation/unaligned-memory-access.txt for more 138 See Documentation/unaligned-memory-access.txt for more
139 information on the topic of unaligned memory accesses. 139 information on the topic of unaligned memory accesses.
140 140
141 config ARCH_USE_BUILTIN_BSWAP 141 config ARCH_USE_BUILTIN_BSWAP
142 bool 142 bool
143 help 143 help
144 Modern versions of GCC (since 4.4) have builtin functions 144 Modern versions of GCC (since 4.4) have builtin functions
145 for handling byte-swapping. Using these, instead of the old 145 for handling byte-swapping. Using these, instead of the old
146 inline assembler that the architecture code provides in the 146 inline assembler that the architecture code provides in the
147 __arch_bswapXX() macros, allows the compiler to see what's 147 __arch_bswapXX() macros, allows the compiler to see what's
148 happening and offers more opportunity for optimisation. In 148 happening and offers more opportunity for optimisation. In
149 particular, the compiler will be able to combine the byteswap 149 particular, the compiler will be able to combine the byteswap
150 with a nearby load or store and use load-and-swap or 150 with a nearby load or store and use load-and-swap or
151 store-and-swap instructions if the architecture has them. It 151 store-and-swap instructions if the architecture has them. It
152 should almost *never* result in code which is worse than the 152 should almost *never* result in code which is worse than the
153 hand-coded assembler in <asm/swab.h>. But just in case it 153 hand-coded assembler in <asm/swab.h>. But just in case it
154 does, the use of the builtins is optional. 154 does, the use of the builtins is optional.
155 155
156 Any architecture with load-and-swap or store-and-swap 156 Any architecture with load-and-swap or store-and-swap
157 instructions should set this. And it shouldn't hurt to set it 157 instructions should set this. And it shouldn't hurt to set it
158 on architectures that don't have such instructions. 158 on architectures that don't have such instructions.
159 159
160 config KRETPROBES 160 config KRETPROBES
161 def_bool y 161 def_bool y
162 depends on KPROBES && HAVE_KRETPROBES 162 depends on KPROBES && HAVE_KRETPROBES
163 163
164 config USER_RETURN_NOTIFIER 164 config USER_RETURN_NOTIFIER
165 bool 165 bool
166 depends on HAVE_USER_RETURN_NOTIFIER 166 depends on HAVE_USER_RETURN_NOTIFIER
167 help 167 help
168 Provide a kernel-internal notification when a cpu is about to 168 Provide a kernel-internal notification when a cpu is about to
169 switch to user mode. 169 switch to user mode.
170 170
171 config HAVE_IOREMAP_PROT 171 config HAVE_IOREMAP_PROT
172 bool 172 bool
173 173
174 config HAVE_KPROBES 174 config HAVE_KPROBES
175 bool 175 bool
176 176
177 config HAVE_KRETPROBES 177 config HAVE_KRETPROBES
178 bool 178 bool
179 179
180 config HAVE_OPTPROBES 180 config HAVE_OPTPROBES
181 bool 181 bool
182 182
183 config HAVE_KPROBES_ON_FTRACE 183 config HAVE_KPROBES_ON_FTRACE
184 bool 184 bool
185 185
186 config HAVE_NMI_WATCHDOG 186 config HAVE_NMI_WATCHDOG
187 bool 187 bool
188 # 188 #
189 # An arch should select this if it provides all these things: 189 # An arch should select this if it provides all these things:
190 # 190 #
191 # task_pt_regs() in asm/processor.h or asm/ptrace.h 191 # task_pt_regs() in asm/processor.h or asm/ptrace.h
192 # arch_has_single_step() if there is hardware single-step support 192 # arch_has_single_step() if there is hardware single-step support
193 # arch_has_block_step() if there is hardware block-step support 193 # arch_has_block_step() if there is hardware block-step support
194 # asm/syscall.h supplying asm-generic/syscall.h interface 194 # asm/syscall.h supplying asm-generic/syscall.h interface
195 # linux/regset.h user_regset interfaces 195 # linux/regset.h user_regset interfaces
196 # CORE_DUMP_USE_REGSET #define'd in linux/elf.h 196 # CORE_DUMP_USE_REGSET #define'd in linux/elf.h
197 # TIF_SYSCALL_TRACE calls tracehook_report_syscall_{entry,exit} 197 # TIF_SYSCALL_TRACE calls tracehook_report_syscall_{entry,exit}
198 # TIF_NOTIFY_RESUME calls tracehook_notify_resume() 198 # TIF_NOTIFY_RESUME calls tracehook_notify_resume()
199 # signal delivery calls tracehook_signal_handler() 199 # signal delivery calls tracehook_signal_handler()
200 # 200 #
201 config HAVE_ARCH_TRACEHOOK 201 config HAVE_ARCH_TRACEHOOK
202 bool 202 bool
203 203
204 config HAVE_DMA_ATTRS 204 config HAVE_DMA_ATTRS
205 bool 205 bool
206 206
207 config HAVE_DMA_CONTIGUOUS 207 config HAVE_DMA_CONTIGUOUS
208 bool 208 bool
209 209
210 config USE_GENERIC_SMP_HELPERS 210 config USE_GENERIC_SMP_HELPERS
211 bool 211 bool
212 212
213 config GENERIC_SMP_IDLE_THREAD 213 config GENERIC_SMP_IDLE_THREAD
214 bool 214 bool
215 215
216 # Select if arch init_task initializer is different to init/init_task.c 216 # Select if arch init_task initializer is different to init/init_task.c
217 config ARCH_INIT_TASK 217 config ARCH_INIT_TASK
218 bool 218 bool
219 219
220 # Select if arch has its private alloc_task_struct() function 220 # Select if arch has its private alloc_task_struct() function
221 config ARCH_TASK_STRUCT_ALLOCATOR 221 config ARCH_TASK_STRUCT_ALLOCATOR
222 bool 222 bool
223 223
224 # Select if arch has its private alloc_thread_info() function 224 # Select if arch has its private alloc_thread_info() function
225 config ARCH_THREAD_INFO_ALLOCATOR 225 config ARCH_THREAD_INFO_ALLOCATOR
226 bool 226 bool
227 227
228 config HAVE_REGS_AND_STACK_ACCESS_API 228 config HAVE_REGS_AND_STACK_ACCESS_API
229 bool 229 bool
230 help 230 help
231 This symbol should be selected by an architecure if it supports 231 This symbol should be selected by an architecure if it supports
232 the API needed to access registers and stack entries from pt_regs, 232 the API needed to access registers and stack entries from pt_regs,
233 declared in asm/ptrace.h 233 declared in asm/ptrace.h
234 For example the kprobes-based event tracer needs this API. 234 For example the kprobes-based event tracer needs this API.
235 235
236 config HAVE_CLK 236 config HAVE_CLK
237 bool 237 bool
238 help 238 help
239 The <linux/clk.h> calls support software clock gating and 239 The <linux/clk.h> calls support software clock gating and
240 thus are a key power management tool on many systems. 240 thus are a key power management tool on many systems.
241 241
242 config HAVE_DMA_API_DEBUG 242 config HAVE_DMA_API_DEBUG
243 bool 243 bool
244 244
245 config HAVE_HW_BREAKPOINT 245 config HAVE_HW_BREAKPOINT
246 bool 246 bool
247 depends on PERF_EVENTS 247 depends on PERF_EVENTS
248 248
249 config HAVE_MIXED_BREAKPOINTS_REGS 249 config HAVE_MIXED_BREAKPOINTS_REGS
250 bool 250 bool
251 depends on HAVE_HW_BREAKPOINT 251 depends on HAVE_HW_BREAKPOINT
252 help 252 help
253 Depending on the arch implementation of hardware breakpoints, 253 Depending on the arch implementation of hardware breakpoints,
254 some of them have separate registers for data and instruction 254 some of them have separate registers for data and instruction
255 breakpoints addresses, others have mixed registers to store 255 breakpoints addresses, others have mixed registers to store
256 them but define the access type in a control register. 256 them but define the access type in a control register.
257 Select this option if your arch implements breakpoints under the 257 Select this option if your arch implements breakpoints under the
258 latter fashion. 258 latter fashion.
259 259
260 config HAVE_USER_RETURN_NOTIFIER 260 config HAVE_USER_RETURN_NOTIFIER
261 bool 261 bool
262 262
263 config HAVE_PERF_EVENTS_NMI 263 config HAVE_PERF_EVENTS_NMI
264 bool 264 bool
265 help 265 help
266 System hardware can generate an NMI using the perf event 266 System hardware can generate an NMI using the perf event
267 subsystem. Also has support for calculating CPU cycle events 267 subsystem. Also has support for calculating CPU cycle events
268 to determine how many clock cycles in a given period. 268 to determine how many clock cycles in a given period.
269 269
270 config HAVE_PERF_REGS 270 config HAVE_PERF_REGS
271 bool 271 bool
272 help 272 help
273 Support selective register dumps for perf events. This includes 273 Support selective register dumps for perf events. This includes
274 bit-mapping of each registers and a unique architecture id. 274 bit-mapping of each registers and a unique architecture id.
275 275
276 config HAVE_PERF_USER_STACK_DUMP 276 config HAVE_PERF_USER_STACK_DUMP
277 bool 277 bool
278 help 278 help
279 Support user stack dumps for perf event samples. This needs 279 Support user stack dumps for perf event samples. This needs
280 access to the user stack pointer which is not unified across 280 access to the user stack pointer which is not unified across
281 architectures. 281 architectures.
282 282
283 config HAVE_ARCH_JUMP_LABEL 283 config HAVE_ARCH_JUMP_LABEL
284 bool 284 bool
285 285
286 config HAVE_ARCH_MUTEX_CPU_RELAX 286 config HAVE_ARCH_MUTEX_CPU_RELAX
287 bool 287 bool
288 288
289 config HAVE_RCU_TABLE_FREE 289 config HAVE_RCU_TABLE_FREE
290 bool 290 bool
291 291
292 config ARCH_HAVE_NMI_SAFE_CMPXCHG 292 config ARCH_HAVE_NMI_SAFE_CMPXCHG
293 bool 293 bool
294 294
295 config HAVE_ALIGNED_STRUCT_PAGE 295 config HAVE_ALIGNED_STRUCT_PAGE
296 bool 296 bool
297 help 297 help
298 This makes sure that struct pages are double word aligned and that 298 This makes sure that struct pages are double word aligned and that
299 e.g. the SLUB allocator can perform double word atomic operations 299 e.g. the SLUB allocator can perform double word atomic operations
300 on a struct page for better performance. However selecting this 300 on a struct page for better performance. However selecting this
301 might increase the size of a struct page by a word. 301 might increase the size of a struct page by a word.
302 302
303 config HAVE_CMPXCHG_LOCAL 303 config HAVE_CMPXCHG_LOCAL
304 bool 304 bool
305 305
306 config HAVE_CMPXCHG_DOUBLE 306 config HAVE_CMPXCHG_DOUBLE
307 bool 307 bool
308 308
309 config ARCH_WANT_IPC_PARSE_VERSION 309 config ARCH_WANT_IPC_PARSE_VERSION
310 bool 310 bool
311 311
312 config ARCH_WANT_COMPAT_IPC_PARSE_VERSION 312 config ARCH_WANT_COMPAT_IPC_PARSE_VERSION
313 bool 313 bool
314 314
315 config ARCH_WANT_OLD_COMPAT_IPC 315 config ARCH_WANT_OLD_COMPAT_IPC
316 select ARCH_WANT_COMPAT_IPC_PARSE_VERSION 316 select ARCH_WANT_COMPAT_IPC_PARSE_VERSION
317 bool 317 bool
318 318
319 config HAVE_ARCH_SECCOMP_FILTER 319 config HAVE_ARCH_SECCOMP_FILTER
320 bool 320 bool
321 help 321 help
322 An arch should select this symbol if it provides all of these things: 322 An arch should select this symbol if it provides all of these things:
323 - syscall_get_arch() 323 - syscall_get_arch()
324 - syscall_get_arguments() 324 - syscall_get_arguments()
325 - syscall_rollback() 325 - syscall_rollback()
326 - syscall_set_return_value() 326 - syscall_set_return_value()
327 - SIGSYS siginfo_t support 327 - SIGSYS siginfo_t support
328 - secure_computing is called from a ptrace_event()-safe context 328 - secure_computing is called from a ptrace_event()-safe context
329 - secure_computing return value is checked and a return value of -1 329 - secure_computing return value is checked and a return value of -1
330 results in the system call being skipped immediately. 330 results in the system call being skipped immediately.
331 331
332 config SECCOMP_FILTER 332 config SECCOMP_FILTER
333 def_bool y 333 def_bool y
334 depends on HAVE_ARCH_SECCOMP_FILTER && SECCOMP && NET 334 depends on HAVE_ARCH_SECCOMP_FILTER && SECCOMP && NET
335 help 335 help
336 Enable tasks to build secure computing environments defined 336 Enable tasks to build secure computing environments defined
337 in terms of Berkeley Packet Filter programs which implement 337 in terms of Berkeley Packet Filter programs which implement
338 task-defined system call filtering polices. 338 task-defined system call filtering polices.
339 339
340 See Documentation/prctl/seccomp_filter.txt for details. 340 See Documentation/prctl/seccomp_filter.txt for details.
341 341
342 config HAVE_CONTEXT_TRACKING 342 config HAVE_CONTEXT_TRACKING
343 bool 343 bool
344 help 344 help
345 Provide kernel/user boundaries probes necessary for subsystems 345 Provide kernel/user boundaries probes necessary for subsystems
346 that need it, such as userspace RCU extended quiescent state. 346 that need it, such as userspace RCU extended quiescent state.
347 Syscalls need to be wrapped inside user_exit()-user_enter() through 347 Syscalls need to be wrapped inside user_exit()-user_enter() through
348 the slow path using TIF_NOHZ flag. Exceptions handlers must be 348 the slow path using TIF_NOHZ flag. Exceptions handlers must be
349 wrapped as well. Irqs are already protected inside 349 wrapped as well. Irqs are already protected inside
350 rcu_irq_enter/rcu_irq_exit() but preemption or signal handling on 350 rcu_irq_enter/rcu_irq_exit() but preemption or signal handling on
351 irq exit still need to be protected. 351 irq exit still need to be protected.
352 352
353 config HAVE_VIRT_CPU_ACCOUNTING 353 config HAVE_VIRT_CPU_ACCOUNTING
354 bool 354 bool
355 355
356 config HAVE_IRQ_TIME_ACCOUNTING 356 config HAVE_IRQ_TIME_ACCOUNTING
357 bool 357 bool
358 help 358 help
359 Archs need to ensure they use a high enough resolution clock to 359 Archs need to ensure they use a high enough resolution clock to
360 support irq time accounting and then call enable_sched_clock_irqtime(). 360 support irq time accounting and then call enable_sched_clock_irqtime().
361 361
362 config HAVE_ARCH_TRANSPARENT_HUGEPAGE 362 config HAVE_ARCH_TRANSPARENT_HUGEPAGE
363 bool 363 bool
364 364
365 config HAVE_MOD_ARCH_SPECIFIC 365 config HAVE_MOD_ARCH_SPECIFIC
366 bool 366 bool
367 help 367 help
368 The arch uses struct mod_arch_specific to store data. Many arches 368 The arch uses struct mod_arch_specific to store data. Many arches
369 just need a simple module loader without arch specific data - those 369 just need a simple module loader without arch specific data - those
370 should not enable this. 370 should not enable this.
371 371
372 config MODULES_USE_ELF_RELA 372 config MODULES_USE_ELF_RELA
373 bool 373 bool
374 help 374 help
375 Modules only use ELF RELA relocations. Modules with ELF REL 375 Modules only use ELF RELA relocations. Modules with ELF REL
376 relocations will give an error. 376 relocations will give an error.
377 377
378 config MODULES_USE_ELF_REL 378 config MODULES_USE_ELF_REL
379 bool 379 bool
380 help 380 help
381 Modules only use ELF REL relocations. Modules with ELF RELA 381 Modules only use ELF REL relocations. Modules with ELF RELA
382 relocations will give an error. 382 relocations will give an error.
383 383
384 config HAVE_UNDERSCORE_SYMBOL_PREFIX
385 bool
386 help
387 Some architectures generate an _ in front of C symbols; things like
388 module loading and assembly files need to know about this.
389
384 # 390 #
385 # ABI hall of shame 391 # ABI hall of shame
386 # 392 #
387 config CLONE_BACKWARDS 393 config CLONE_BACKWARDS
388 bool 394 bool
389 help 395 help
390 Architecture has tls passed as the 4th argument of clone(2), 396 Architecture has tls passed as the 4th argument of clone(2),
391 not the 5th one. 397 not the 5th one.
392 398
393 config CLONE_BACKWARDS2 399 config CLONE_BACKWARDS2
394 bool 400 bool
395 help 401 help
396 Architecture has the first two arguments of clone(2) swapped. 402 Architecture has the first two arguments of clone(2) swapped.
397 403
398 config ODD_RT_SIGACTION 404 config ODD_RT_SIGACTION
399 bool 405 bool
400 help 406 help
401 Architecture has unusual rt_sigaction(2) arguments 407 Architecture has unusual rt_sigaction(2) arguments
402 408
403 config OLD_SIGSUSPEND 409 config OLD_SIGSUSPEND
404 bool 410 bool
405 help 411 help
406 Architecture has old sigsuspend(2) syscall, of one-argument variety 412 Architecture has old sigsuspend(2) syscall, of one-argument variety
407 413
408 config OLD_SIGSUSPEND3 414 config OLD_SIGSUSPEND3
409 bool 415 bool
410 help 416 help
411 Even weirder antique ABI - three-argument sigsuspend(2) 417 Even weirder antique ABI - three-argument sigsuspend(2)
412 418
413 config OLD_SIGACTION 419 config OLD_SIGACTION
414 bool 420 bool
415 help 421 help
416 Architecture has old sigaction(2) syscall. Nope, not the same 422 Architecture has old sigaction(2) syscall. Nope, not the same
417 as OLD_SIGSUSPEND | OLD_SIGSUSPEND3 - alpha has sigsuspend(2), 423 as OLD_SIGSUSPEND | OLD_SIGSUSPEND3 - alpha has sigsuspend(2),
418 but fairly different variant of sigaction(2), thanks to OSF/1 424 but fairly different variant of sigaction(2), thanks to OSF/1
419 compatibility... 425 compatibility...
420 426
421 config COMPAT_OLD_SIGACTION 427 config COMPAT_OLD_SIGACTION
422 bool 428 bool
423 429
424 source "kernel/gcov/Kconfig" 430 source "kernel/gcov/Kconfig"
425 431
arch/blackfin/Kconfig
1 config SYMBOL_PREFIX
2 string
3 default "_"
4
5 config MMU 1 config MMU
6 def_bool n 2 def_bool n
7 3
8 config FPU 4 config FPU
9 def_bool n 5 def_bool n
10 6
11 config RWSEM_GENERIC_SPINLOCK 7 config RWSEM_GENERIC_SPINLOCK
12 def_bool y 8 def_bool y
13 9
14 config RWSEM_XCHGADD_ALGORITHM 10 config RWSEM_XCHGADD_ALGORITHM
15 def_bool n 11 def_bool n
16 12
17 config BLACKFIN 13 config BLACKFIN
18 def_bool y 14 def_bool y
19 select HAVE_ARCH_KGDB 15 select HAVE_ARCH_KGDB
20 select HAVE_ARCH_TRACEHOOK 16 select HAVE_ARCH_TRACEHOOK
21 select HAVE_DYNAMIC_FTRACE 17 select HAVE_DYNAMIC_FTRACE
22 select HAVE_FTRACE_MCOUNT_RECORD 18 select HAVE_FTRACE_MCOUNT_RECORD
23 select HAVE_FUNCTION_GRAPH_TRACER 19 select HAVE_FUNCTION_GRAPH_TRACER
24 select HAVE_FUNCTION_TRACER 20 select HAVE_FUNCTION_TRACER
25 select HAVE_FUNCTION_TRACE_MCOUNT_TEST 21 select HAVE_FUNCTION_TRACE_MCOUNT_TEST
26 select HAVE_IDE 22 select HAVE_IDE
27 select HAVE_KERNEL_GZIP if RAMKERNEL 23 select HAVE_KERNEL_GZIP if RAMKERNEL
28 select HAVE_KERNEL_BZIP2 if RAMKERNEL 24 select HAVE_KERNEL_BZIP2 if RAMKERNEL
29 select HAVE_KERNEL_LZMA if RAMKERNEL 25 select HAVE_KERNEL_LZMA if RAMKERNEL
30 select HAVE_KERNEL_LZO if RAMKERNEL 26 select HAVE_KERNEL_LZO if RAMKERNEL
31 select HAVE_OPROFILE 27 select HAVE_OPROFILE
32 select HAVE_PERF_EVENTS 28 select HAVE_PERF_EVENTS
33 select ARCH_HAVE_CUSTOM_GPIO_H 29 select ARCH_HAVE_CUSTOM_GPIO_H
34 select ARCH_WANT_OPTIONAL_GPIOLIB 30 select ARCH_WANT_OPTIONAL_GPIOLIB
35 select HAVE_UID16 31 select HAVE_UID16
32 select HAVE_UNDERSCORE_SYMBOL_PREFIX
36 select VIRT_TO_BUS 33 select VIRT_TO_BUS
37 select ARCH_WANT_IPC_PARSE_VERSION 34 select ARCH_WANT_IPC_PARSE_VERSION
38 select HAVE_GENERIC_HARDIRQS 35 select HAVE_GENERIC_HARDIRQS
39 select GENERIC_ATOMIC64 36 select GENERIC_ATOMIC64
40 select GENERIC_IRQ_PROBE 37 select GENERIC_IRQ_PROBE
41 select USE_GENERIC_SMP_HELPERS if SMP 38 select USE_GENERIC_SMP_HELPERS if SMP
42 select HAVE_NMI_WATCHDOG if NMI_WATCHDOG 39 select HAVE_NMI_WATCHDOG if NMI_WATCHDOG
43 select GENERIC_SMP_IDLE_THREAD 40 select GENERIC_SMP_IDLE_THREAD
44 select ARCH_USES_GETTIMEOFFSET if !GENERIC_CLOCKEVENTS 41 select ARCH_USES_GETTIMEOFFSET if !GENERIC_CLOCKEVENTS
45 select HAVE_MOD_ARCH_SPECIFIC 42 select HAVE_MOD_ARCH_SPECIFIC
46 select MODULES_USE_ELF_RELA 43 select MODULES_USE_ELF_RELA
47 44
48 config GENERIC_CSUM 45 config GENERIC_CSUM
49 def_bool y 46 def_bool y
50 47
51 config GENERIC_BUG 48 config GENERIC_BUG
52 def_bool y 49 def_bool y
53 depends on BUG 50 depends on BUG
54 51
55 config ZONE_DMA 52 config ZONE_DMA
56 def_bool y 53 def_bool y
57 54
58 config GENERIC_GPIO 55 config GENERIC_GPIO
59 def_bool y 56 def_bool y
60 57
61 config FORCE_MAX_ZONEORDER 58 config FORCE_MAX_ZONEORDER
62 int 59 int
63 default "14" 60 default "14"
64 61
65 config GENERIC_CALIBRATE_DELAY 62 config GENERIC_CALIBRATE_DELAY
66 def_bool y 63 def_bool y
67 64
68 config LOCKDEP_SUPPORT 65 config LOCKDEP_SUPPORT
69 def_bool y 66 def_bool y
70 67
71 config STACKTRACE_SUPPORT 68 config STACKTRACE_SUPPORT
72 def_bool y 69 def_bool y
73 70
74 config TRACE_IRQFLAGS_SUPPORT 71 config TRACE_IRQFLAGS_SUPPORT
75 def_bool y 72 def_bool y
76 73
77 source "init/Kconfig" 74 source "init/Kconfig"
78 75
79 source "kernel/Kconfig.preempt" 76 source "kernel/Kconfig.preempt"
80 77
81 source "kernel/Kconfig.freezer" 78 source "kernel/Kconfig.freezer"
82 79
83 menu "Blackfin Processor Options" 80 menu "Blackfin Processor Options"
84 81
85 comment "Processor and Board Settings" 82 comment "Processor and Board Settings"
86 83
87 choice 84 choice
88 prompt "CPU" 85 prompt "CPU"
89 default BF533 86 default BF533
90 87
91 config BF512 88 config BF512
92 bool "BF512" 89 bool "BF512"
93 help 90 help
94 BF512 Processor Support. 91 BF512 Processor Support.
95 92
96 config BF514 93 config BF514
97 bool "BF514" 94 bool "BF514"
98 help 95 help
99 BF514 Processor Support. 96 BF514 Processor Support.
100 97
101 config BF516 98 config BF516
102 bool "BF516" 99 bool "BF516"
103 help 100 help
104 BF516 Processor Support. 101 BF516 Processor Support.
105 102
106 config BF518 103 config BF518
107 bool "BF518" 104 bool "BF518"
108 help 105 help
109 BF518 Processor Support. 106 BF518 Processor Support.
110 107
111 config BF522 108 config BF522
112 bool "BF522" 109 bool "BF522"
113 help 110 help
114 BF522 Processor Support. 111 BF522 Processor Support.
115 112
116 config BF523 113 config BF523
117 bool "BF523" 114 bool "BF523"
118 help 115 help
119 BF523 Processor Support. 116 BF523 Processor Support.
120 117
121 config BF524 118 config BF524
122 bool "BF524" 119 bool "BF524"
123 help 120 help
124 BF524 Processor Support. 121 BF524 Processor Support.
125 122
126 config BF525 123 config BF525
127 bool "BF525" 124 bool "BF525"
128 help 125 help
129 BF525 Processor Support. 126 BF525 Processor Support.
130 127
131 config BF526 128 config BF526
132 bool "BF526" 129 bool "BF526"
133 help 130 help
134 BF526 Processor Support. 131 BF526 Processor Support.
135 132
136 config BF527 133 config BF527
137 bool "BF527" 134 bool "BF527"
138 help 135 help
139 BF527 Processor Support. 136 BF527 Processor Support.
140 137
141 config BF531 138 config BF531
142 bool "BF531" 139 bool "BF531"
143 help 140 help
144 BF531 Processor Support. 141 BF531 Processor Support.
145 142
146 config BF532 143 config BF532
147 bool "BF532" 144 bool "BF532"
148 help 145 help
149 BF532 Processor Support. 146 BF532 Processor Support.
150 147
151 config BF533 148 config BF533
152 bool "BF533" 149 bool "BF533"
153 help 150 help
154 BF533 Processor Support. 151 BF533 Processor Support.
155 152
156 config BF534 153 config BF534
157 bool "BF534" 154 bool "BF534"
158 help 155 help
159 BF534 Processor Support. 156 BF534 Processor Support.
160 157
161 config BF536 158 config BF536
162 bool "BF536" 159 bool "BF536"
163 help 160 help
164 BF536 Processor Support. 161 BF536 Processor Support.
165 162
166 config BF537 163 config BF537
167 bool "BF537" 164 bool "BF537"
168 help 165 help
169 BF537 Processor Support. 166 BF537 Processor Support.
170 167
171 config BF538 168 config BF538
172 bool "BF538" 169 bool "BF538"
173 help 170 help
174 BF538 Processor Support. 171 BF538 Processor Support.
175 172
176 config BF539 173 config BF539
177 bool "BF539" 174 bool "BF539"
178 help 175 help
179 BF539 Processor Support. 176 BF539 Processor Support.
180 177
181 config BF542_std 178 config BF542_std
182 bool "BF542" 179 bool "BF542"
183 help 180 help
184 BF542 Processor Support. 181 BF542 Processor Support.
185 182
186 config BF542M 183 config BF542M
187 bool "BF542m" 184 bool "BF542m"
188 help 185 help
189 BF542 Processor Support. 186 BF542 Processor Support.
190 187
191 config BF544_std 188 config BF544_std
192 bool "BF544" 189 bool "BF544"
193 help 190 help
194 BF544 Processor Support. 191 BF544 Processor Support.
195 192
196 config BF544M 193 config BF544M
197 bool "BF544m" 194 bool "BF544m"
198 help 195 help
199 BF544 Processor Support. 196 BF544 Processor Support.
200 197
201 config BF547_std 198 config BF547_std
202 bool "BF547" 199 bool "BF547"
203 help 200 help
204 BF547 Processor Support. 201 BF547 Processor Support.
205 202
206 config BF547M 203 config BF547M
207 bool "BF547m" 204 bool "BF547m"
208 help 205 help
209 BF547 Processor Support. 206 BF547 Processor Support.
210 207
211 config BF548_std 208 config BF548_std
212 bool "BF548" 209 bool "BF548"
213 help 210 help
214 BF548 Processor Support. 211 BF548 Processor Support.
215 212
216 config BF548M 213 config BF548M
217 bool "BF548m" 214 bool "BF548m"
218 help 215 help
219 BF548 Processor Support. 216 BF548 Processor Support.
220 217
221 config BF549_std 218 config BF549_std
222 bool "BF549" 219 bool "BF549"
223 help 220 help
224 BF549 Processor Support. 221 BF549 Processor Support.
225 222
226 config BF549M 223 config BF549M
227 bool "BF549m" 224 bool "BF549m"
228 help 225 help
229 BF549 Processor Support. 226 BF549 Processor Support.
230 227
231 config BF561 228 config BF561
232 bool "BF561" 229 bool "BF561"
233 help 230 help
234 BF561 Processor Support. 231 BF561 Processor Support.
235 232
236 config BF609 233 config BF609
237 bool "BF609" 234 bool "BF609"
238 select CLKDEV_LOOKUP 235 select CLKDEV_LOOKUP
239 help 236 help
240 BF609 Processor Support. 237 BF609 Processor Support.
241 238
242 endchoice 239 endchoice
243 240
244 config SMP 241 config SMP
245 depends on BF561 242 depends on BF561
246 select TICKSOURCE_CORETMR 243 select TICKSOURCE_CORETMR
247 bool "Symmetric multi-processing support" 244 bool "Symmetric multi-processing support"
248 ---help--- 245 ---help---
249 This enables support for systems with more than one CPU, 246 This enables support for systems with more than one CPU,
250 like the dual core BF561. If you have a system with only one 247 like the dual core BF561. If you have a system with only one
251 CPU, say N. If you have a system with more than one CPU, say Y. 248 CPU, say N. If you have a system with more than one CPU, say Y.
252 249
253 If you don't know what to do here, say N. 250 If you don't know what to do here, say N.
254 251
255 config NR_CPUS 252 config NR_CPUS
256 int 253 int
257 depends on SMP 254 depends on SMP
258 default 2 if BF561 255 default 2 if BF561
259 256
260 config HOTPLUG_CPU 257 config HOTPLUG_CPU
261 bool "Support for hot-pluggable CPUs" 258 bool "Support for hot-pluggable CPUs"
262 depends on SMP && HOTPLUG 259 depends on SMP && HOTPLUG
263 default y 260 default y
264 261
265 config BF_REV_MIN 262 config BF_REV_MIN
266 int 263 int
267 default 0 if (BF51x || BF52x || (BF54x && !BF54xM)) || BF60x 264 default 0 if (BF51x || BF52x || (BF54x && !BF54xM)) || BF60x
268 default 2 if (BF537 || BF536 || BF534) 265 default 2 if (BF537 || BF536 || BF534)
269 default 3 if (BF561 || BF533 || BF532 || BF531 || BF54xM) 266 default 3 if (BF561 || BF533 || BF532 || BF531 || BF54xM)
270 default 4 if (BF538 || BF539) 267 default 4 if (BF538 || BF539)
271 268
272 config BF_REV_MAX 269 config BF_REV_MAX
273 int 270 int
274 default 2 if (BF51x || BF52x || (BF54x && !BF54xM)) || BF60x 271 default 2 if (BF51x || BF52x || (BF54x && !BF54xM)) || BF60x
275 default 3 if (BF537 || BF536 || BF534 || BF54xM) 272 default 3 if (BF537 || BF536 || BF534 || BF54xM)
276 default 5 if (BF561 || BF538 || BF539) 273 default 5 if (BF561 || BF538 || BF539)
277 default 6 if (BF533 || BF532 || BF531) 274 default 6 if (BF533 || BF532 || BF531)
278 275
279 choice 276 choice
280 prompt "Silicon Rev" 277 prompt "Silicon Rev"
281 default BF_REV_0_0 if (BF51x || BF52x || BF60x) 278 default BF_REV_0_0 if (BF51x || BF52x || BF60x)
282 default BF_REV_0_2 if (BF534 || BF536 || BF537 || (BF54x && !BF54xM)) 279 default BF_REV_0_2 if (BF534 || BF536 || BF537 || (BF54x && !BF54xM))
283 default BF_REV_0_3 if (BF531 || BF532 || BF533 || BF54xM || BF561) 280 default BF_REV_0_3 if (BF531 || BF532 || BF533 || BF54xM || BF561)
284 281
285 config BF_REV_0_0 282 config BF_REV_0_0
286 bool "0.0" 283 bool "0.0"
287 depends on (BF51x || BF52x || (BF54x && !BF54xM) || BF60x) 284 depends on (BF51x || BF52x || (BF54x && !BF54xM) || BF60x)
288 285
289 config BF_REV_0_1 286 config BF_REV_0_1
290 bool "0.1" 287 bool "0.1"
291 depends on (BF51x || BF52x || (BF54x && !BF54xM)) 288 depends on (BF51x || BF52x || (BF54x && !BF54xM))
292 289
293 config BF_REV_0_2 290 config BF_REV_0_2
294 bool "0.2" 291 bool "0.2"
295 depends on (BF51x || BF52x || BF537 || BF536 || BF534 || (BF54x && !BF54xM)) 292 depends on (BF51x || BF52x || BF537 || BF536 || BF534 || (BF54x && !BF54xM))
296 293
297 config BF_REV_0_3 294 config BF_REV_0_3
298 bool "0.3" 295 bool "0.3"
299 depends on (BF54xM || BF561 || BF537 || BF536 || BF534 || BF533 || BF532 || BF531) 296 depends on (BF54xM || BF561 || BF537 || BF536 || BF534 || BF533 || BF532 || BF531)
300 297
301 config BF_REV_0_4 298 config BF_REV_0_4
302 bool "0.4" 299 bool "0.4"
303 depends on (BF561 || BF533 || BF532 || BF531 || BF538 || BF539 || BF54x) 300 depends on (BF561 || BF533 || BF532 || BF531 || BF538 || BF539 || BF54x)
304 301
305 config BF_REV_0_5 302 config BF_REV_0_5
306 bool "0.5" 303 bool "0.5"
307 depends on (BF561 || BF533 || BF532 || BF531 || BF538 || BF539) 304 depends on (BF561 || BF533 || BF532 || BF531 || BF538 || BF539)
308 305
309 config BF_REV_0_6 306 config BF_REV_0_6
310 bool "0.6" 307 bool "0.6"
311 depends on (BF533 || BF532 || BF531) 308 depends on (BF533 || BF532 || BF531)
312 309
313 config BF_REV_ANY 310 config BF_REV_ANY
314 bool "any" 311 bool "any"
315 312
316 config BF_REV_NONE 313 config BF_REV_NONE
317 bool "none" 314 bool "none"
318 315
319 endchoice 316 endchoice
320 317
321 config BF53x 318 config BF53x
322 bool 319 bool
323 depends on (BF531 || BF532 || BF533 || BF534 || BF536 || BF537) 320 depends on (BF531 || BF532 || BF533 || BF534 || BF536 || BF537)
324 default y 321 default y
325 322
326 config MEM_MT48LC64M4A2FB_7E 323 config MEM_MT48LC64M4A2FB_7E
327 bool 324 bool
328 depends on (BFIN533_STAMP) 325 depends on (BFIN533_STAMP)
329 default y 326 default y
330 327
331 config MEM_MT48LC16M16A2TG_75 328 config MEM_MT48LC16M16A2TG_75
332 bool 329 bool
333 depends on (BFIN533_EZKIT || BFIN561_EZKIT \ 330 depends on (BFIN533_EZKIT || BFIN561_EZKIT \
334 || BFIN533_BLUETECHNIX_CM || BFIN537_BLUETECHNIX_CM_E \ 331 || BFIN533_BLUETECHNIX_CM || BFIN537_BLUETECHNIX_CM_E \
335 || BFIN537_BLUETECHNIX_CM_U || H8606_HVSISTEMAS \ 332 || BFIN537_BLUETECHNIX_CM_U || H8606_HVSISTEMAS \
336 || BFIN527_BLUETECHNIX_CM) 333 || BFIN527_BLUETECHNIX_CM)
337 default y 334 default y
338 335
339 config MEM_MT48LC32M8A2_75 336 config MEM_MT48LC32M8A2_75
340 bool 337 bool
341 depends on (BFIN518F_EZBRD || BFIN537_STAMP || PNAV10 || BFIN538_EZKIT) 338 depends on (BFIN518F_EZBRD || BFIN537_STAMP || PNAV10 || BFIN538_EZKIT)
342 default y 339 default y
343 340
344 config MEM_MT48LC8M32B2B5_7 341 config MEM_MT48LC8M32B2B5_7
345 bool 342 bool
346 depends on (BFIN561_BLUETECHNIX_CM) 343 depends on (BFIN561_BLUETECHNIX_CM)
347 default y 344 default y
348 345
349 config MEM_MT48LC32M16A2TG_75 346 config MEM_MT48LC32M16A2TG_75
350 bool 347 bool
351 depends on (BFIN527_EZKIT || BFIN527_EZKIT_V2 || BFIN532_IP0X || BLACKSTAMP || BFIN527_AD7160EVAL) 348 depends on (BFIN527_EZKIT || BFIN527_EZKIT_V2 || BFIN532_IP0X || BLACKSTAMP || BFIN527_AD7160EVAL)
352 default y 349 default y
353 350
354 config MEM_MT48H32M16LFCJ_75 351 config MEM_MT48H32M16LFCJ_75
355 bool 352 bool
356 depends on (BFIN526_EZBRD) 353 depends on (BFIN526_EZBRD)
357 default y 354 default y
358 355
359 config MEM_MT47H64M16 356 config MEM_MT47H64M16
360 bool 357 bool
361 depends on (BFIN609_EZKIT) 358 depends on (BFIN609_EZKIT)
362 default y 359 default y
363 360
364 source "arch/blackfin/mach-bf518/Kconfig" 361 source "arch/blackfin/mach-bf518/Kconfig"
365 source "arch/blackfin/mach-bf527/Kconfig" 362 source "arch/blackfin/mach-bf527/Kconfig"
366 source "arch/blackfin/mach-bf533/Kconfig" 363 source "arch/blackfin/mach-bf533/Kconfig"
367 source "arch/blackfin/mach-bf561/Kconfig" 364 source "arch/blackfin/mach-bf561/Kconfig"
368 source "arch/blackfin/mach-bf537/Kconfig" 365 source "arch/blackfin/mach-bf537/Kconfig"
369 source "arch/blackfin/mach-bf538/Kconfig" 366 source "arch/blackfin/mach-bf538/Kconfig"
370 source "arch/blackfin/mach-bf548/Kconfig" 367 source "arch/blackfin/mach-bf548/Kconfig"
371 source "arch/blackfin/mach-bf609/Kconfig" 368 source "arch/blackfin/mach-bf609/Kconfig"
372 369
373 menu "Board customizations" 370 menu "Board customizations"
374 371
375 config CMDLINE_BOOL 372 config CMDLINE_BOOL
376 bool "Default bootloader kernel arguments" 373 bool "Default bootloader kernel arguments"
377 374
378 config CMDLINE 375 config CMDLINE
379 string "Initial kernel command string" 376 string "Initial kernel command string"
380 depends on CMDLINE_BOOL 377 depends on CMDLINE_BOOL
381 default "console=ttyBF0,57600" 378 default "console=ttyBF0,57600"
382 help 379 help
383 If you don't have a boot loader capable of passing a command line string 380 If you don't have a boot loader capable of passing a command line string
384 to the kernel, you may specify one here. As a minimum, you should specify 381 to the kernel, you may specify one here. As a minimum, you should specify
385 the memory size and the root device (e.g., mem=8M, root=/dev/nfs). 382 the memory size and the root device (e.g., mem=8M, root=/dev/nfs).
386 383
387 config BOOT_LOAD 384 config BOOT_LOAD
388 hex "Kernel load address for booting" 385 hex "Kernel load address for booting"
389 default "0x1000" 386 default "0x1000"
390 range 0x1000 0x20000000 387 range 0x1000 0x20000000
391 help 388 help
392 This option allows you to set the load address of the kernel. 389 This option allows you to set the load address of the kernel.
393 This can be useful if you are on a board which has a small amount 390 This can be useful if you are on a board which has a small amount
394 of memory or you wish to reserve some memory at the beginning of 391 of memory or you wish to reserve some memory at the beginning of
395 the address space. 392 the address space.
396 393
397 Note that you need to keep this value above 4k (0x1000) as this 394 Note that you need to keep this value above 4k (0x1000) as this
398 memory region is used to capture NULL pointer references as well 395 memory region is used to capture NULL pointer references as well
399 as some core kernel functions. 396 as some core kernel functions.
400 397
401 config PHY_RAM_BASE_ADDRESS 398 config PHY_RAM_BASE_ADDRESS
402 hex "Physical RAM Base" 399 hex "Physical RAM Base"
403 default 0x0 400 default 0x0
404 help 401 help
405 set BF609 FPGA physical SRAM base address 402 set BF609 FPGA physical SRAM base address
406 403
407 config ROM_BASE 404 config ROM_BASE
408 hex "Kernel ROM Base" 405 hex "Kernel ROM Base"
409 depends on ROMKERNEL 406 depends on ROMKERNEL
410 default "0x20040040" 407 default "0x20040040"
411 range 0x20000000 0x20400000 if !(BF54x || BF561 || BF60x) 408 range 0x20000000 0x20400000 if !(BF54x || BF561 || BF60x)
412 range 0x20000000 0x30000000 if (BF54x || BF561) 409 range 0x20000000 0x30000000 if (BF54x || BF561)
413 range 0xB0000000 0xC0000000 if (BF60x) 410 range 0xB0000000 0xC0000000 if (BF60x)
414 help 411 help
415 Make sure your ROM base does not include any file-header 412 Make sure your ROM base does not include any file-header
416 information that is prepended to the kernel. 413 information that is prepended to the kernel.
417 414
418 For example, the bootable U-Boot format (created with 415 For example, the bootable U-Boot format (created with
419 mkimage) has a 64 byte header (0x40). So while the image 416 mkimage) has a 64 byte header (0x40). So while the image
420 you write to flash might start at say 0x20080000, you have 417 you write to flash might start at say 0x20080000, you have
421 to add 0x40 to get the kernel's ROM base as it will come 418 to add 0x40 to get the kernel's ROM base as it will come
422 after the header. 419 after the header.
423 420
424 comment "Clock/PLL Setup" 421 comment "Clock/PLL Setup"
425 422
426 config CLKIN_HZ 423 config CLKIN_HZ
427 int "Frequency of the crystal on the board in Hz" 424 int "Frequency of the crystal on the board in Hz"
428 default "10000000" if BFIN532_IP0X 425 default "10000000" if BFIN532_IP0X
429 default "11059200" if BFIN533_STAMP 426 default "11059200" if BFIN533_STAMP
430 default "24576000" if PNAV10 427 default "24576000" if PNAV10
431 default "25000000" # most people use this 428 default "25000000" # most people use this
432 default "27000000" if BFIN533_EZKIT 429 default "27000000" if BFIN533_EZKIT
433 default "30000000" if BFIN561_EZKIT 430 default "30000000" if BFIN561_EZKIT
434 default "24000000" if BFIN527_AD7160EVAL 431 default "24000000" if BFIN527_AD7160EVAL
435 help 432 help
436 The frequency of CLKIN crystal oscillator on the board in Hz. 433 The frequency of CLKIN crystal oscillator on the board in Hz.
437 Warning: This value should match the crystal on the board. Otherwise, 434 Warning: This value should match the crystal on the board. Otherwise,
438 peripherals won't work properly. 435 peripherals won't work properly.
439 436
440 config BFIN_KERNEL_CLOCK 437 config BFIN_KERNEL_CLOCK
441 bool "Re-program Clocks while Kernel boots?" 438 bool "Re-program Clocks while Kernel boots?"
442 default n 439 default n
443 help 440 help
444 This option decides if kernel clocks are re-programed from the 441 This option decides if kernel clocks are re-programed from the
445 bootloader settings. If the clocks are not set, the SDRAM settings 442 bootloader settings. If the clocks are not set, the SDRAM settings
446 are also not changed, and the Bootloader does 100% of the hardware 443 are also not changed, and the Bootloader does 100% of the hardware
447 configuration. 444 configuration.
448 445
449 config PLL_BYPASS 446 config PLL_BYPASS
450 bool "Bypass PLL" 447 bool "Bypass PLL"
451 depends on BFIN_KERNEL_CLOCK && (!BF60x) 448 depends on BFIN_KERNEL_CLOCK && (!BF60x)
452 default n 449 default n
453 450
454 config CLKIN_HALF 451 config CLKIN_HALF
455 bool "Half Clock In" 452 bool "Half Clock In"
456 depends on BFIN_KERNEL_CLOCK && (! PLL_BYPASS) 453 depends on BFIN_KERNEL_CLOCK && (! PLL_BYPASS)
457 default n 454 default n
458 help 455 help
459 If this is set the clock will be divided by 2, before it goes to the PLL. 456 If this is set the clock will be divided by 2, before it goes to the PLL.
460 457
461 config VCO_MULT 458 config VCO_MULT
462 int "VCO Multiplier" 459 int "VCO Multiplier"
463 depends on BFIN_KERNEL_CLOCK && (! PLL_BYPASS) 460 depends on BFIN_KERNEL_CLOCK && (! PLL_BYPASS)
464 range 1 64 461 range 1 64
465 default "22" if BFIN533_EZKIT 462 default "22" if BFIN533_EZKIT
466 default "45" if BFIN533_STAMP 463 default "45" if BFIN533_STAMP
467 default "20" if (BFIN537_STAMP || BFIN527_EZKIT || BFIN527_EZKIT_V2 || BFIN548_EZKIT || BFIN548_BLUETECHNIX_CM || BFIN538_EZKIT) 464 default "20" if (BFIN537_STAMP || BFIN527_EZKIT || BFIN527_EZKIT_V2 || BFIN548_EZKIT || BFIN548_BLUETECHNIX_CM || BFIN538_EZKIT)
468 default "22" if BFIN533_BLUETECHNIX_CM 465 default "22" if BFIN533_BLUETECHNIX_CM
469 default "20" if (BFIN537_BLUETECHNIX_CM_E || BFIN537_BLUETECHNIX_CM_U || BFIN527_BLUETECHNIX_CM || BFIN561_BLUETECHNIX_CM) 466 default "20" if (BFIN537_BLUETECHNIX_CM_E || BFIN537_BLUETECHNIX_CM_U || BFIN527_BLUETECHNIX_CM || BFIN561_BLUETECHNIX_CM)
470 default "20" if (BFIN561_EZKIT || BF609) 467 default "20" if (BFIN561_EZKIT || BF609)
471 default "16" if (H8606_HVSISTEMAS || BLACKSTAMP || BFIN526_EZBRD || BFIN518F_EZBRD) 468 default "16" if (H8606_HVSISTEMAS || BLACKSTAMP || BFIN526_EZBRD || BFIN518F_EZBRD)
472 default "25" if BFIN527_AD7160EVAL 469 default "25" if BFIN527_AD7160EVAL
473 help 470 help
474 This controls the frequency of the on-chip PLL. This can be between 1 and 64. 471 This controls the frequency of the on-chip PLL. This can be between 1 and 64.
475 PLL Frequency = (Crystal Frequency) * (this setting) 472 PLL Frequency = (Crystal Frequency) * (this setting)
476 473
477 choice 474 choice
478 prompt "Core Clock Divider" 475 prompt "Core Clock Divider"
479 depends on BFIN_KERNEL_CLOCK 476 depends on BFIN_KERNEL_CLOCK
480 default CCLK_DIV_1 477 default CCLK_DIV_1
481 help 478 help
482 This sets the frequency of the core. It can be 1, 2, 4 or 8 479 This sets the frequency of the core. It can be 1, 2, 4 or 8
483 Core Frequency = (PLL frequency) / (this setting) 480 Core Frequency = (PLL frequency) / (this setting)
484 481
485 config CCLK_DIV_1 482 config CCLK_DIV_1
486 bool "1" 483 bool "1"
487 484
488 config CCLK_DIV_2 485 config CCLK_DIV_2
489 bool "2" 486 bool "2"
490 487
491 config CCLK_DIV_4 488 config CCLK_DIV_4
492 bool "4" 489 bool "4"
493 490
494 config CCLK_DIV_8 491 config CCLK_DIV_8
495 bool "8" 492 bool "8"
496 endchoice 493 endchoice
497 494
498 config SCLK_DIV 495 config SCLK_DIV
499 int "System Clock Divider" 496 int "System Clock Divider"
500 depends on BFIN_KERNEL_CLOCK 497 depends on BFIN_KERNEL_CLOCK
501 range 1 15 498 range 1 15
502 default 4 499 default 4
503 help 500 help
504 This sets the frequency of the system clock (including SDRAM or DDR) on 501 This sets the frequency of the system clock (including SDRAM or DDR) on
505 !BF60x else it set the clock for system buses and provides the 502 !BF60x else it set the clock for system buses and provides the
506 source from which SCLK0 and SCLK1 are derived. 503 source from which SCLK0 and SCLK1 are derived.
507 This can be between 1 and 15 504 This can be between 1 and 15
508 System Clock = (PLL frequency) / (this setting) 505 System Clock = (PLL frequency) / (this setting)
509 506
510 config SCLK0_DIV 507 config SCLK0_DIV
511 int "System Clock0 Divider" 508 int "System Clock0 Divider"
512 depends on BFIN_KERNEL_CLOCK && BF60x 509 depends on BFIN_KERNEL_CLOCK && BF60x
513 range 1 15 510 range 1 15
514 default 1 511 default 1
515 help 512 help
516 This sets the frequency of the system clock0 for PVP and all other 513 This sets the frequency of the system clock0 for PVP and all other
517 peripherals not clocked by SCLK1. 514 peripherals not clocked by SCLK1.
518 This can be between 1 and 15 515 This can be between 1 and 15
519 System Clock0 = (System Clock) / (this setting) 516 System Clock0 = (System Clock) / (this setting)
520 517
521 config SCLK1_DIV 518 config SCLK1_DIV
522 int "System Clock1 Divider" 519 int "System Clock1 Divider"
523 depends on BFIN_KERNEL_CLOCK && BF60x 520 depends on BFIN_KERNEL_CLOCK && BF60x
524 range 1 15 521 range 1 15
525 default 1 522 default 1
526 help 523 help
527 This sets the frequency of the system clock1 (including SPORT, SPI and ACM). 524 This sets the frequency of the system clock1 (including SPORT, SPI and ACM).
528 This can be between 1 and 15 525 This can be between 1 and 15
529 System Clock1 = (System Clock) / (this setting) 526 System Clock1 = (System Clock) / (this setting)
530 527
531 config DCLK_DIV 528 config DCLK_DIV
532 int "DDR Clock Divider" 529 int "DDR Clock Divider"
533 depends on BFIN_KERNEL_CLOCK && BF60x 530 depends on BFIN_KERNEL_CLOCK && BF60x
534 range 1 15 531 range 1 15
535 default 2 532 default 2
536 help 533 help
537 This sets the frequency of the DDR memory. 534 This sets the frequency of the DDR memory.
538 This can be between 1 and 15 535 This can be between 1 and 15
539 DDR Clock = (PLL frequency) / (this setting) 536 DDR Clock = (PLL frequency) / (this setting)
540 537
541 choice 538 choice
542 prompt "DDR SDRAM Chip Type" 539 prompt "DDR SDRAM Chip Type"
543 depends on BFIN_KERNEL_CLOCK 540 depends on BFIN_KERNEL_CLOCK
544 depends on BF54x 541 depends on BF54x
545 default MEM_MT46V32M16_5B 542 default MEM_MT46V32M16_5B
546 543
547 config MEM_MT46V32M16_6T 544 config MEM_MT46V32M16_6T
548 bool "MT46V32M16_6T" 545 bool "MT46V32M16_6T"
549 546
550 config MEM_MT46V32M16_5B 547 config MEM_MT46V32M16_5B
551 bool "MT46V32M16_5B" 548 bool "MT46V32M16_5B"
552 endchoice 549 endchoice
553 550
554 choice 551 choice
555 prompt "DDR/SDRAM Timing" 552 prompt "DDR/SDRAM Timing"
556 depends on BFIN_KERNEL_CLOCK && !BF60x 553 depends on BFIN_KERNEL_CLOCK && !BF60x
557 default BFIN_KERNEL_CLOCK_MEMINIT_CALC 554 default BFIN_KERNEL_CLOCK_MEMINIT_CALC
558 help 555 help
559 This option allows you to specify Blackfin SDRAM/DDR Timing parameters 556 This option allows you to specify Blackfin SDRAM/DDR Timing parameters
560 The calculated SDRAM timing parameters may not be 100% 557 The calculated SDRAM timing parameters may not be 100%
561 accurate - This option is therefore marked experimental. 558 accurate - This option is therefore marked experimental.
562 559
563 config BFIN_KERNEL_CLOCK_MEMINIT_CALC 560 config BFIN_KERNEL_CLOCK_MEMINIT_CALC
564 bool "Calculate Timings" 561 bool "Calculate Timings"
565 562
566 config BFIN_KERNEL_CLOCK_MEMINIT_SPEC 563 config BFIN_KERNEL_CLOCK_MEMINIT_SPEC
567 bool "Provide accurate Timings based on target SCLK" 564 bool "Provide accurate Timings based on target SCLK"
568 help 565 help
569 Please consult the Blackfin Hardware Reference Manuals as well 566 Please consult the Blackfin Hardware Reference Manuals as well
570 as the memory device datasheet. 567 as the memory device datasheet.
571 http://docs.blackfin.uclinux.org/doku.php?id=bfin:sdram 568 http://docs.blackfin.uclinux.org/doku.php?id=bfin:sdram
572 endchoice 569 endchoice
573 570
574 menu "Memory Init Control" 571 menu "Memory Init Control"
575 depends on BFIN_KERNEL_CLOCK_MEMINIT_SPEC 572 depends on BFIN_KERNEL_CLOCK_MEMINIT_SPEC
576 573
577 config MEM_DDRCTL0 574 config MEM_DDRCTL0
578 depends on BF54x 575 depends on BF54x
579 hex "DDRCTL0" 576 hex "DDRCTL0"
580 default 0x0 577 default 0x0
581 578
582 config MEM_DDRCTL1 579 config MEM_DDRCTL1
583 depends on BF54x 580 depends on BF54x
584 hex "DDRCTL1" 581 hex "DDRCTL1"
585 default 0x0 582 default 0x0
586 583
587 config MEM_DDRCTL2 584 config MEM_DDRCTL2
588 depends on BF54x 585 depends on BF54x
589 hex "DDRCTL2" 586 hex "DDRCTL2"
590 default 0x0 587 default 0x0
591 588
592 config MEM_EBIU_DDRQUE 589 config MEM_EBIU_DDRQUE
593 depends on BF54x 590 depends on BF54x
594 hex "DDRQUE" 591 hex "DDRQUE"
595 default 0x0 592 default 0x0
596 593
597 config MEM_SDRRC 594 config MEM_SDRRC
598 depends on !BF54x 595 depends on !BF54x
599 hex "SDRRC" 596 hex "SDRRC"
600 default 0x0 597 default 0x0
601 598
602 config MEM_SDGCTL 599 config MEM_SDGCTL
603 depends on !BF54x 600 depends on !BF54x
604 hex "SDGCTL" 601 hex "SDGCTL"
605 default 0x0 602 default 0x0
606 endmenu 603 endmenu
607 604
608 # 605 #
609 # Max & Min Speeds for various Chips 606 # Max & Min Speeds for various Chips
610 # 607 #
611 config MAX_VCO_HZ 608 config MAX_VCO_HZ
612 int 609 int
613 default 400000000 if BF512 610 default 400000000 if BF512
614 default 400000000 if BF514 611 default 400000000 if BF514
615 default 400000000 if BF516 612 default 400000000 if BF516
616 default 400000000 if BF518 613 default 400000000 if BF518
617 default 400000000 if BF522 614 default 400000000 if BF522
618 default 600000000 if BF523 615 default 600000000 if BF523
619 default 400000000 if BF524 616 default 400000000 if BF524
620 default 600000000 if BF525 617 default 600000000 if BF525
621 default 400000000 if BF526 618 default 400000000 if BF526
622 default 600000000 if BF527 619 default 600000000 if BF527
623 default 400000000 if BF531 620 default 400000000 if BF531
624 default 400000000 if BF532 621 default 400000000 if BF532
625 default 750000000 if BF533 622 default 750000000 if BF533
626 default 500000000 if BF534 623 default 500000000 if BF534
627 default 400000000 if BF536 624 default 400000000 if BF536
628 default 600000000 if BF537 625 default 600000000 if BF537
629 default 533333333 if BF538 626 default 533333333 if BF538
630 default 533333333 if BF539 627 default 533333333 if BF539
631 default 600000000 if BF542 628 default 600000000 if BF542
632 default 533333333 if BF544 629 default 533333333 if BF544
633 default 600000000 if BF547 630 default 600000000 if BF547
634 default 600000000 if BF548 631 default 600000000 if BF548
635 default 533333333 if BF549 632 default 533333333 if BF549
636 default 600000000 if BF561 633 default 600000000 if BF561
637 default 800000000 if BF609 634 default 800000000 if BF609
638 635
639 config MIN_VCO_HZ 636 config MIN_VCO_HZ
640 int 637 int
641 default 50000000 638 default 50000000
642 639
643 config MAX_SCLK_HZ 640 config MAX_SCLK_HZ
644 int 641 int
645 default 200000000 if BF609 642 default 200000000 if BF609
646 default 133333333 643 default 133333333
647 644
648 config MIN_SCLK_HZ 645 config MIN_SCLK_HZ
649 int 646 int
650 default 27000000 647 default 27000000
651 648
652 comment "Kernel Timer/Scheduler" 649 comment "Kernel Timer/Scheduler"
653 650
654 source kernel/Kconfig.hz 651 source kernel/Kconfig.hz
655 652
656 config SET_GENERIC_CLOCKEVENTS 653 config SET_GENERIC_CLOCKEVENTS
657 bool "Generic clock events" 654 bool "Generic clock events"
658 default y 655 default y
659 select GENERIC_CLOCKEVENTS 656 select GENERIC_CLOCKEVENTS
660 657
661 menu "Clock event device" 658 menu "Clock event device"
662 depends on GENERIC_CLOCKEVENTS 659 depends on GENERIC_CLOCKEVENTS
663 config TICKSOURCE_GPTMR0 660 config TICKSOURCE_GPTMR0
664 bool "GPTimer0" 661 bool "GPTimer0"
665 depends on !SMP 662 depends on !SMP
666 select BFIN_GPTIMERS 663 select BFIN_GPTIMERS
667 664
668 config TICKSOURCE_CORETMR 665 config TICKSOURCE_CORETMR
669 bool "Core timer" 666 bool "Core timer"
670 default y 667 default y
671 endmenu 668 endmenu
672 669
673 menu "Clock souce" 670 menu "Clock souce"
674 depends on GENERIC_CLOCKEVENTS 671 depends on GENERIC_CLOCKEVENTS
675 config CYCLES_CLOCKSOURCE 672 config CYCLES_CLOCKSOURCE
676 bool "CYCLES" 673 bool "CYCLES"
677 default y 674 default y
678 depends on !BFIN_SCRATCH_REG_CYCLES 675 depends on !BFIN_SCRATCH_REG_CYCLES
679 depends on !SMP 676 depends on !SMP
680 help 677 help
681 If you say Y here, you will enable support for using the 'cycles' 678 If you say Y here, you will enable support for using the 'cycles'
682 registers as a clock source. Doing so means you will be unable to 679 registers as a clock source. Doing so means you will be unable to
683 safely write to the 'cycles' register during runtime. You will 680 safely write to the 'cycles' register during runtime. You will
684 still be able to read it (such as for performance monitoring), but 681 still be able to read it (such as for performance monitoring), but
685 writing the registers will most likely crash the kernel. 682 writing the registers will most likely crash the kernel.
686 683
687 config GPTMR0_CLOCKSOURCE 684 config GPTMR0_CLOCKSOURCE
688 bool "GPTimer0" 685 bool "GPTimer0"
689 select BFIN_GPTIMERS 686 select BFIN_GPTIMERS
690 depends on !TICKSOURCE_GPTMR0 687 depends on !TICKSOURCE_GPTMR0
691 endmenu 688 endmenu
692 689
693 comment "Misc" 690 comment "Misc"
694 691
695 choice 692 choice
696 prompt "Blackfin Exception Scratch Register" 693 prompt "Blackfin Exception Scratch Register"
697 default BFIN_SCRATCH_REG_RETN 694 default BFIN_SCRATCH_REG_RETN
698 help 695 help
699 Select the resource to reserve for the Exception handler: 696 Select the resource to reserve for the Exception handler:
700 - RETN: Non-Maskable Interrupt (NMI) 697 - RETN: Non-Maskable Interrupt (NMI)
701 - RETE: Exception Return (JTAG/ICE) 698 - RETE: Exception Return (JTAG/ICE)
702 - CYCLES: Performance counter 699 - CYCLES: Performance counter
703 700
704 If you are unsure, please select "RETN". 701 If you are unsure, please select "RETN".
705 702
706 config BFIN_SCRATCH_REG_RETN 703 config BFIN_SCRATCH_REG_RETN
707 bool "RETN" 704 bool "RETN"
708 help 705 help
709 Use the RETN register in the Blackfin exception handler 706 Use the RETN register in the Blackfin exception handler
710 as a stack scratch register. This means you cannot 707 as a stack scratch register. This means you cannot
711 safely use NMI on the Blackfin while running Linux, but 708 safely use NMI on the Blackfin while running Linux, but
712 you can debug the system with a JTAG ICE and use the 709 you can debug the system with a JTAG ICE and use the
713 CYCLES performance registers. 710 CYCLES performance registers.
714 711
715 If you are unsure, please select "RETN". 712 If you are unsure, please select "RETN".
716 713
717 config BFIN_SCRATCH_REG_RETE 714 config BFIN_SCRATCH_REG_RETE
718 bool "RETE" 715 bool "RETE"
719 help 716 help
720 Use the RETE register in the Blackfin exception handler 717 Use the RETE register in the Blackfin exception handler
721 as a stack scratch register. This means you cannot 718 as a stack scratch register. This means you cannot
722 safely use a JTAG ICE while debugging a Blackfin board, 719 safely use a JTAG ICE while debugging a Blackfin board,
723 but you can safely use the CYCLES performance registers 720 but you can safely use the CYCLES performance registers
724 and the NMI. 721 and the NMI.
725 722
726 If you are unsure, please select "RETN". 723 If you are unsure, please select "RETN".
727 724
728 config BFIN_SCRATCH_REG_CYCLES 725 config BFIN_SCRATCH_REG_CYCLES
729 bool "CYCLES" 726 bool "CYCLES"
730 help 727 help
731 Use the CYCLES register in the Blackfin exception handler 728 Use the CYCLES register in the Blackfin exception handler
732 as a stack scratch register. This means you cannot 729 as a stack scratch register. This means you cannot
733 safely use the CYCLES performance registers on a Blackfin 730 safely use the CYCLES performance registers on a Blackfin
734 board at anytime, but you can debug the system with a JTAG 731 board at anytime, but you can debug the system with a JTAG
735 ICE and use the NMI. 732 ICE and use the NMI.
736 733
737 If you are unsure, please select "RETN". 734 If you are unsure, please select "RETN".
738 735
739 endchoice 736 endchoice
740 737
741 endmenu 738 endmenu
742 739
743 740
744 menu "Blackfin Kernel Optimizations" 741 menu "Blackfin Kernel Optimizations"
745 742
746 comment "Memory Optimizations" 743 comment "Memory Optimizations"
747 744
748 config I_ENTRY_L1 745 config I_ENTRY_L1
749 bool "Locate interrupt entry code in L1 Memory" 746 bool "Locate interrupt entry code in L1 Memory"
750 default y 747 default y
751 depends on !SMP 748 depends on !SMP
752 help 749 help
753 If enabled, interrupt entry code (STORE/RESTORE CONTEXT) is linked 750 If enabled, interrupt entry code (STORE/RESTORE CONTEXT) is linked
754 into L1 instruction memory. (less latency) 751 into L1 instruction memory. (less latency)
755 752
756 config EXCPT_IRQ_SYSC_L1 753 config EXCPT_IRQ_SYSC_L1
757 bool "Locate entire ASM lowlevel exception / interrupt - Syscall and CPLB handler code in L1 Memory" 754 bool "Locate entire ASM lowlevel exception / interrupt - Syscall and CPLB handler code in L1 Memory"
758 default y 755 default y
759 depends on !SMP 756 depends on !SMP
760 help 757 help
761 If enabled, the entire ASM lowlevel exception and interrupt entry code 758 If enabled, the entire ASM lowlevel exception and interrupt entry code
762 (STORE/RESTORE CONTEXT) is linked into L1 instruction memory. 759 (STORE/RESTORE CONTEXT) is linked into L1 instruction memory.
763 (less latency) 760 (less latency)
764 761
765 config DO_IRQ_L1 762 config DO_IRQ_L1
766 bool "Locate frequently called do_irq dispatcher function in L1 Memory" 763 bool "Locate frequently called do_irq dispatcher function in L1 Memory"
767 default y 764 default y
768 depends on !SMP 765 depends on !SMP
769 help 766 help
770 If enabled, the frequently called do_irq dispatcher function is linked 767 If enabled, the frequently called do_irq dispatcher function is linked
771 into L1 instruction memory. (less latency) 768 into L1 instruction memory. (less latency)
772 769
773 config CORE_TIMER_IRQ_L1 770 config CORE_TIMER_IRQ_L1
774 bool "Locate frequently called timer_interrupt() function in L1 Memory" 771 bool "Locate frequently called timer_interrupt() function in L1 Memory"
775 default y 772 default y
776 depends on !SMP 773 depends on !SMP
777 help 774 help
778 If enabled, the frequently called timer_interrupt() function is linked 775 If enabled, the frequently called timer_interrupt() function is linked
779 into L1 instruction memory. (less latency) 776 into L1 instruction memory. (less latency)
780 777
781 config IDLE_L1 778 config IDLE_L1
782 bool "Locate frequently idle function in L1 Memory" 779 bool "Locate frequently idle function in L1 Memory"
783 default y 780 default y
784 depends on !SMP 781 depends on !SMP
785 help 782 help
786 If enabled, the frequently called idle function is linked 783 If enabled, the frequently called idle function is linked
787 into L1 instruction memory. (less latency) 784 into L1 instruction memory. (less latency)
788 785
789 config SCHEDULE_L1 786 config SCHEDULE_L1
790 bool "Locate kernel schedule function in L1 Memory" 787 bool "Locate kernel schedule function in L1 Memory"
791 default y 788 default y
792 depends on !SMP 789 depends on !SMP
793 help 790 help
794 If enabled, the frequently called kernel schedule is linked 791 If enabled, the frequently called kernel schedule is linked
795 into L1 instruction memory. (less latency) 792 into L1 instruction memory. (less latency)
796 793
797 config ARITHMETIC_OPS_L1 794 config ARITHMETIC_OPS_L1
798 bool "Locate kernel owned arithmetic functions in L1 Memory" 795 bool "Locate kernel owned arithmetic functions in L1 Memory"
799 default y 796 default y
800 depends on !SMP 797 depends on !SMP
801 help 798 help
802 If enabled, arithmetic functions are linked 799 If enabled, arithmetic functions are linked
803 into L1 instruction memory. (less latency) 800 into L1 instruction memory. (less latency)
804 801
805 config ACCESS_OK_L1 802 config ACCESS_OK_L1
806 bool "Locate access_ok function in L1 Memory" 803 bool "Locate access_ok function in L1 Memory"
807 default y 804 default y
808 depends on !SMP 805 depends on !SMP
809 help 806 help
810 If enabled, the access_ok function is linked 807 If enabled, the access_ok function is linked
811 into L1 instruction memory. (less latency) 808 into L1 instruction memory. (less latency)
812 809
813 config MEMSET_L1 810 config MEMSET_L1
814 bool "Locate memset function in L1 Memory" 811 bool "Locate memset function in L1 Memory"
815 default y 812 default y
816 depends on !SMP 813 depends on !SMP
817 help 814 help
818 If enabled, the memset function is linked 815 If enabled, the memset function is linked
819 into L1 instruction memory. (less latency) 816 into L1 instruction memory. (less latency)
820 817
821 config MEMCPY_L1 818 config MEMCPY_L1
822 bool "Locate memcpy function in L1 Memory" 819 bool "Locate memcpy function in L1 Memory"
823 default y 820 default y
824 depends on !SMP 821 depends on !SMP
825 help 822 help
826 If enabled, the memcpy function is linked 823 If enabled, the memcpy function is linked
827 into L1 instruction memory. (less latency) 824 into L1 instruction memory. (less latency)
828 825
829 config STRCMP_L1 826 config STRCMP_L1
830 bool "locate strcmp function in L1 Memory" 827 bool "locate strcmp function in L1 Memory"
831 default y 828 default y
832 depends on !SMP 829 depends on !SMP
833 help 830 help
834 If enabled, the strcmp function is linked 831 If enabled, the strcmp function is linked
835 into L1 instruction memory (less latency). 832 into L1 instruction memory (less latency).
836 833
837 config STRNCMP_L1 834 config STRNCMP_L1
838 bool "locate strncmp function in L1 Memory" 835 bool "locate strncmp function in L1 Memory"
839 default y 836 default y
840 depends on !SMP 837 depends on !SMP
841 help 838 help
842 If enabled, the strncmp function is linked 839 If enabled, the strncmp function is linked
843 into L1 instruction memory (less latency). 840 into L1 instruction memory (less latency).
844 841
845 config STRCPY_L1 842 config STRCPY_L1
846 bool "locate strcpy function in L1 Memory" 843 bool "locate strcpy function in L1 Memory"
847 default y 844 default y
848 depends on !SMP 845 depends on !SMP
849 help 846 help
850 If enabled, the strcpy function is linked 847 If enabled, the strcpy function is linked
851 into L1 instruction memory (less latency). 848 into L1 instruction memory (less latency).
852 849
853 config STRNCPY_L1 850 config STRNCPY_L1
854 bool "locate strncpy function in L1 Memory" 851 bool "locate strncpy function in L1 Memory"
855 default y 852 default y
856 depends on !SMP 853 depends on !SMP
857 help 854 help
858 If enabled, the strncpy function is linked 855 If enabled, the strncpy function is linked
859 into L1 instruction memory (less latency). 856 into L1 instruction memory (less latency).
860 857
861 config SYS_BFIN_SPINLOCK_L1 858 config SYS_BFIN_SPINLOCK_L1
862 bool "Locate sys_bfin_spinlock function in L1 Memory" 859 bool "Locate sys_bfin_spinlock function in L1 Memory"
863 default y 860 default y
864 depends on !SMP 861 depends on !SMP
865 help 862 help
866 If enabled, sys_bfin_spinlock function is linked 863 If enabled, sys_bfin_spinlock function is linked
867 into L1 instruction memory. (less latency) 864 into L1 instruction memory. (less latency)
868 865
869 config IP_CHECKSUM_L1 866 config IP_CHECKSUM_L1
870 bool "Locate IP Checksum function in L1 Memory" 867 bool "Locate IP Checksum function in L1 Memory"
871 default n 868 default n
872 depends on !SMP 869 depends on !SMP
873 help 870 help
874 If enabled, the IP Checksum function is linked 871 If enabled, the IP Checksum function is linked
875 into L1 instruction memory. (less latency) 872 into L1 instruction memory. (less latency)
876 873
877 config CACHELINE_ALIGNED_L1 874 config CACHELINE_ALIGNED_L1
878 bool "Locate cacheline_aligned data to L1 Data Memory" 875 bool "Locate cacheline_aligned data to L1 Data Memory"
879 default y if !BF54x 876 default y if !BF54x
880 default n if BF54x 877 default n if BF54x
881 depends on !SMP && !BF531 && !CRC32 878 depends on !SMP && !BF531 && !CRC32
882 help 879 help
883 If enabled, cacheline_aligned data is linked 880 If enabled, cacheline_aligned data is linked
884 into L1 data memory. (less latency) 881 into L1 data memory. (less latency)
885 882
886 config SYSCALL_TAB_L1 883 config SYSCALL_TAB_L1
887 bool "Locate Syscall Table L1 Data Memory" 884 bool "Locate Syscall Table L1 Data Memory"
888 default n 885 default n
889 depends on !SMP && !BF531 886 depends on !SMP && !BF531
890 help 887 help
891 If enabled, the Syscall LUT is linked 888 If enabled, the Syscall LUT is linked
892 into L1 data memory. (less latency) 889 into L1 data memory. (less latency)
893 890
894 config CPLB_SWITCH_TAB_L1 891 config CPLB_SWITCH_TAB_L1
895 bool "Locate CPLB Switch Tables L1 Data Memory" 892 bool "Locate CPLB Switch Tables L1 Data Memory"
896 default n 893 default n
897 depends on !SMP && !BF531 894 depends on !SMP && !BF531
898 help 895 help
899 If enabled, the CPLB Switch Tables are linked 896 If enabled, the CPLB Switch Tables are linked
900 into L1 data memory. (less latency) 897 into L1 data memory. (less latency)
901 898
902 config ICACHE_FLUSH_L1 899 config ICACHE_FLUSH_L1
903 bool "Locate icache flush funcs in L1 Inst Memory" 900 bool "Locate icache flush funcs in L1 Inst Memory"
904 default y 901 default y
905 help 902 help
906 If enabled, the Blackfin icache flushing functions are linked 903 If enabled, the Blackfin icache flushing functions are linked
907 into L1 instruction memory. 904 into L1 instruction memory.
908 905
909 Note that this might be required to address anomalies, but 906 Note that this might be required to address anomalies, but
910 these functions are pretty small, so it shouldn't be too bad. 907 these functions are pretty small, so it shouldn't be too bad.
911 If you are using a processor affected by an anomaly, the build 908 If you are using a processor affected by an anomaly, the build
912 system will double check for you and prevent it. 909 system will double check for you and prevent it.
913 910
914 config DCACHE_FLUSH_L1 911 config DCACHE_FLUSH_L1
915 bool "Locate dcache flush funcs in L1 Inst Memory" 912 bool "Locate dcache flush funcs in L1 Inst Memory"
916 default y 913 default y
917 depends on !SMP 914 depends on !SMP
918 help 915 help
919 If enabled, the Blackfin dcache flushing functions are linked 916 If enabled, the Blackfin dcache flushing functions are linked
920 into L1 instruction memory. 917 into L1 instruction memory.
921 918
922 config APP_STACK_L1 919 config APP_STACK_L1
923 bool "Support locating application stack in L1 Scratch Memory" 920 bool "Support locating application stack in L1 Scratch Memory"
924 default y 921 default y
925 depends on !SMP 922 depends on !SMP
926 help 923 help
927 If enabled the application stack can be located in L1 924 If enabled the application stack can be located in L1
928 scratch memory (less latency). 925 scratch memory (less latency).
929 926
930 Currently only works with FLAT binaries. 927 Currently only works with FLAT binaries.
931 928
932 config EXCEPTION_L1_SCRATCH 929 config EXCEPTION_L1_SCRATCH
933 bool "Locate exception stack in L1 Scratch Memory" 930 bool "Locate exception stack in L1 Scratch Memory"
934 default n 931 default n
935 depends on !SMP && !APP_STACK_L1 932 depends on !SMP && !APP_STACK_L1
936 help 933 help
937 Whenever an exception occurs, use the L1 Scratch memory for 934 Whenever an exception occurs, use the L1 Scratch memory for
938 stack storage. You cannot place the stacks of FLAT binaries 935 stack storage. You cannot place the stacks of FLAT binaries
939 in L1 when using this option. 936 in L1 when using this option.
940 937
941 If you don't use L1 Scratch, then you should say Y here. 938 If you don't use L1 Scratch, then you should say Y here.
942 939
943 comment "Speed Optimizations" 940 comment "Speed Optimizations"
944 config BFIN_INS_LOWOVERHEAD 941 config BFIN_INS_LOWOVERHEAD
945 bool "ins[bwl] low overhead, higher interrupt latency" 942 bool "ins[bwl] low overhead, higher interrupt latency"
946 default y 943 default y
947 depends on !SMP 944 depends on !SMP
948 help 945 help
949 Reads on the Blackfin are speculative. In Blackfin terms, this means 946 Reads on the Blackfin are speculative. In Blackfin terms, this means
950 they can be interrupted at any time (even after they have been issued 947 they can be interrupted at any time (even after they have been issued
951 on to the external bus), and re-issued after the interrupt occurs. 948 on to the external bus), and re-issued after the interrupt occurs.
952 For memory - this is not a big deal, since memory does not change if 949 For memory - this is not a big deal, since memory does not change if
953 it sees a read. 950 it sees a read.
954 951
955 If a FIFO is sitting on the end of the read, it will see two reads, 952 If a FIFO is sitting on the end of the read, it will see two reads,
956 when the core only sees one since the FIFO receives both the read 953 when the core only sees one since the FIFO receives both the read
957 which is cancelled (and not delivered to the core) and the one which 954 which is cancelled (and not delivered to the core) and the one which
958 is re-issued (which is delivered to the core). 955 is re-issued (which is delivered to the core).
959 956
960 To solve this, interrupts are turned off before reads occur to 957 To solve this, interrupts are turned off before reads occur to
961 I/O space. This option controls which the overhead/latency of 958 I/O space. This option controls which the overhead/latency of
962 controlling interrupts during this time 959 controlling interrupts during this time
963 "n" turns interrupts off every read 960 "n" turns interrupts off every read
964 (higher overhead, but lower interrupt latency) 961 (higher overhead, but lower interrupt latency)
965 "y" turns interrupts off every loop 962 "y" turns interrupts off every loop
966 (low overhead, but longer interrupt latency) 963 (low overhead, but longer interrupt latency)
967 964
968 default behavior is to leave this set to on (type "Y"). If you are experiencing 965 default behavior is to leave this set to on (type "Y"). If you are experiencing
969 interrupt latency issues, it is safe and OK to turn this off. 966 interrupt latency issues, it is safe and OK to turn this off.
970 967
971 endmenu 968 endmenu
972 969
973 choice 970 choice
974 prompt "Kernel executes from" 971 prompt "Kernel executes from"
975 help 972 help
976 Choose the memory type that the kernel will be running in. 973 Choose the memory type that the kernel will be running in.
977 974
978 config RAMKERNEL 975 config RAMKERNEL
979 bool "RAM" 976 bool "RAM"
980 help 977 help
981 The kernel will be resident in RAM when running. 978 The kernel will be resident in RAM when running.
982 979
983 config ROMKERNEL 980 config ROMKERNEL
984 bool "ROM" 981 bool "ROM"
985 help 982 help
986 The kernel will be resident in FLASH/ROM when running. 983 The kernel will be resident in FLASH/ROM when running.
987 984
988 endchoice 985 endchoice
989 986
990 # Common code uses "ROMKERNEL" or "XIP_KERNEL", so define both 987 # Common code uses "ROMKERNEL" or "XIP_KERNEL", so define both
991 config XIP_KERNEL 988 config XIP_KERNEL
992 bool 989 bool
993 default y 990 default y
994 depends on ROMKERNEL 991 depends on ROMKERNEL
995 992
996 source "mm/Kconfig" 993 source "mm/Kconfig"
997 994
998 config BFIN_GPTIMERS 995 config BFIN_GPTIMERS
999 tristate "Enable Blackfin General Purpose Timers API" 996 tristate "Enable Blackfin General Purpose Timers API"
1000 default n 997 default n
1001 help 998 help
1002 Enable support for the General Purpose Timers API. If you 999 Enable support for the General Purpose Timers API. If you
1003 are unsure, say N. 1000 are unsure, say N.
1004 1001
1005 To compile this driver as a module, choose M here: the module 1002 To compile this driver as a module, choose M here: the module
1006 will be called gptimers. 1003 will be called gptimers.
1007 1004
1008 choice 1005 choice
1009 prompt "Uncached DMA region" 1006 prompt "Uncached DMA region"
1010 default DMA_UNCACHED_1M 1007 default DMA_UNCACHED_1M
1011 config DMA_UNCACHED_32M 1008 config DMA_UNCACHED_32M
1012 bool "Enable 32M DMA region" 1009 bool "Enable 32M DMA region"
1013 config DMA_UNCACHED_16M 1010 config DMA_UNCACHED_16M
1014 bool "Enable 16M DMA region" 1011 bool "Enable 16M DMA region"
1015 config DMA_UNCACHED_8M 1012 config DMA_UNCACHED_8M
1016 bool "Enable 8M DMA region" 1013 bool "Enable 8M DMA region"
1017 config DMA_UNCACHED_4M 1014 config DMA_UNCACHED_4M
1018 bool "Enable 4M DMA region" 1015 bool "Enable 4M DMA region"
1019 config DMA_UNCACHED_2M 1016 config DMA_UNCACHED_2M
1020 bool "Enable 2M DMA region" 1017 bool "Enable 2M DMA region"
1021 config DMA_UNCACHED_1M 1018 config DMA_UNCACHED_1M
1022 bool "Enable 1M DMA region" 1019 bool "Enable 1M DMA region"
1023 config DMA_UNCACHED_512K 1020 config DMA_UNCACHED_512K
1024 bool "Enable 512K DMA region" 1021 bool "Enable 512K DMA region"
1025 config DMA_UNCACHED_256K 1022 config DMA_UNCACHED_256K
1026 bool "Enable 256K DMA region" 1023 bool "Enable 256K DMA region"
1027 config DMA_UNCACHED_128K 1024 config DMA_UNCACHED_128K
1028 bool "Enable 128K DMA region" 1025 bool "Enable 128K DMA region"
1029 config DMA_UNCACHED_NONE 1026 config DMA_UNCACHED_NONE
1030 bool "Disable DMA region" 1027 bool "Disable DMA region"
1031 endchoice 1028 endchoice
1032 1029
1033 1030
1034 comment "Cache Support" 1031 comment "Cache Support"
1035 1032
1036 config BFIN_ICACHE 1033 config BFIN_ICACHE
1037 bool "Enable ICACHE" 1034 bool "Enable ICACHE"
1038 default y 1035 default y
1039 config BFIN_EXTMEM_ICACHEABLE 1036 config BFIN_EXTMEM_ICACHEABLE
1040 bool "Enable ICACHE for external memory" 1037 bool "Enable ICACHE for external memory"
1041 depends on BFIN_ICACHE 1038 depends on BFIN_ICACHE
1042 default y 1039 default y
1043 config BFIN_L2_ICACHEABLE 1040 config BFIN_L2_ICACHEABLE
1044 bool "Enable ICACHE for L2 SRAM" 1041 bool "Enable ICACHE for L2 SRAM"
1045 depends on BFIN_ICACHE 1042 depends on BFIN_ICACHE
1046 depends on (BF54x || BF561 || BF60x) && !SMP 1043 depends on (BF54x || BF561 || BF60x) && !SMP
1047 default n 1044 default n
1048 1045
1049 config BFIN_DCACHE 1046 config BFIN_DCACHE
1050 bool "Enable DCACHE" 1047 bool "Enable DCACHE"
1051 default y 1048 default y
1052 config BFIN_DCACHE_BANKA 1049 config BFIN_DCACHE_BANKA
1053 bool "Enable only 16k BankA DCACHE - BankB is SRAM" 1050 bool "Enable only 16k BankA DCACHE - BankB is SRAM"
1054 depends on BFIN_DCACHE && !BF531 1051 depends on BFIN_DCACHE && !BF531
1055 default n 1052 default n
1056 config BFIN_EXTMEM_DCACHEABLE 1053 config BFIN_EXTMEM_DCACHEABLE
1057 bool "Enable DCACHE for external memory" 1054 bool "Enable DCACHE for external memory"
1058 depends on BFIN_DCACHE 1055 depends on BFIN_DCACHE
1059 default y 1056 default y
1060 choice 1057 choice
1061 prompt "External memory DCACHE policy" 1058 prompt "External memory DCACHE policy"
1062 depends on BFIN_EXTMEM_DCACHEABLE 1059 depends on BFIN_EXTMEM_DCACHEABLE
1063 default BFIN_EXTMEM_WRITEBACK if !SMP 1060 default BFIN_EXTMEM_WRITEBACK if !SMP
1064 default BFIN_EXTMEM_WRITETHROUGH if SMP 1061 default BFIN_EXTMEM_WRITETHROUGH if SMP
1065 config BFIN_EXTMEM_WRITEBACK 1062 config BFIN_EXTMEM_WRITEBACK
1066 bool "Write back" 1063 bool "Write back"
1067 depends on !SMP 1064 depends on !SMP
1068 help 1065 help
1069 Write Back Policy: 1066 Write Back Policy:
1070 Cached data will be written back to SDRAM only when needed. 1067 Cached data will be written back to SDRAM only when needed.
1071 This can give a nice increase in performance, but beware of 1068 This can give a nice increase in performance, but beware of
1072 broken drivers that do not properly invalidate/flush their 1069 broken drivers that do not properly invalidate/flush their
1073 cache. 1070 cache.
1074 1071
1075 Write Through Policy: 1072 Write Through Policy:
1076 Cached data will always be written back to SDRAM when the 1073 Cached data will always be written back to SDRAM when the
1077 cache is updated. This is a completely safe setting, but 1074 cache is updated. This is a completely safe setting, but
1078 performance is worse than Write Back. 1075 performance is worse than Write Back.
1079 1076
1080 If you are unsure of the options and you want to be safe, 1077 If you are unsure of the options and you want to be safe,
1081 then go with Write Through. 1078 then go with Write Through.
1082 1079
1083 config BFIN_EXTMEM_WRITETHROUGH 1080 config BFIN_EXTMEM_WRITETHROUGH
1084 bool "Write through" 1081 bool "Write through"
1085 help 1082 help
1086 Write Back Policy: 1083 Write Back Policy:
1087 Cached data will be written back to SDRAM only when needed. 1084 Cached data will be written back to SDRAM only when needed.
1088 This can give a nice increase in performance, but beware of 1085 This can give a nice increase in performance, but beware of
1089 broken drivers that do not properly invalidate/flush their 1086 broken drivers that do not properly invalidate/flush their
1090 cache. 1087 cache.
1091 1088
1092 Write Through Policy: 1089 Write Through Policy:
1093 Cached data will always be written back to SDRAM when the 1090 Cached data will always be written back to SDRAM when the
1094 cache is updated. This is a completely safe setting, but 1091 cache is updated. This is a completely safe setting, but
1095 performance is worse than Write Back. 1092 performance is worse than Write Back.
1096 1093
1097 If you are unsure of the options and you want to be safe, 1094 If you are unsure of the options and you want to be safe,
1098 then go with Write Through. 1095 then go with Write Through.
1099 1096
1100 endchoice 1097 endchoice
1101 1098
1102 config BFIN_L2_DCACHEABLE 1099 config BFIN_L2_DCACHEABLE
1103 bool "Enable DCACHE for L2 SRAM" 1100 bool "Enable DCACHE for L2 SRAM"
1104 depends on BFIN_DCACHE 1101 depends on BFIN_DCACHE
1105 depends on (BF54x || BF561 || BF60x) && !SMP 1102 depends on (BF54x || BF561 || BF60x) && !SMP
1106 default n 1103 default n
1107 choice 1104 choice
1108 prompt "L2 SRAM DCACHE policy" 1105 prompt "L2 SRAM DCACHE policy"
1109 depends on BFIN_L2_DCACHEABLE 1106 depends on BFIN_L2_DCACHEABLE
1110 default BFIN_L2_WRITEBACK 1107 default BFIN_L2_WRITEBACK
1111 config BFIN_L2_WRITEBACK 1108 config BFIN_L2_WRITEBACK
1112 bool "Write back" 1109 bool "Write back"
1113 1110
1114 config BFIN_L2_WRITETHROUGH 1111 config BFIN_L2_WRITETHROUGH
1115 bool "Write through" 1112 bool "Write through"
1116 endchoice 1113 endchoice
1117 1114
1118 1115
1119 comment "Memory Protection Unit" 1116 comment "Memory Protection Unit"
1120 config MPU 1117 config MPU
1121 bool "Enable the memory protection unit" 1118 bool "Enable the memory protection unit"
1122 default n 1119 default n
1123 help 1120 help
1124 Use the processor's MPU to protect applications from accessing 1121 Use the processor's MPU to protect applications from accessing
1125 memory they do not own. This comes at a performance penalty 1122 memory they do not own. This comes at a performance penalty
1126 and is recommended only for debugging. 1123 and is recommended only for debugging.
1127 1124
1128 comment "Asynchronous Memory Configuration" 1125 comment "Asynchronous Memory Configuration"
1129 1126
1130 menu "EBIU_AMGCTL Global Control" 1127 menu "EBIU_AMGCTL Global Control"
1131 depends on !BF60x 1128 depends on !BF60x
1132 config C_AMCKEN 1129 config C_AMCKEN
1133 bool "Enable CLKOUT" 1130 bool "Enable CLKOUT"
1134 default y 1131 default y
1135 1132
1136 config C_CDPRIO 1133 config C_CDPRIO
1137 bool "DMA has priority over core for ext. accesses" 1134 bool "DMA has priority over core for ext. accesses"
1138 default n 1135 default n
1139 1136
1140 config C_B0PEN 1137 config C_B0PEN
1141 depends on BF561 1138 depends on BF561
1142 bool "Bank 0 16 bit packing enable" 1139 bool "Bank 0 16 bit packing enable"
1143 default y 1140 default y
1144 1141
1145 config C_B1PEN 1142 config C_B1PEN
1146 depends on BF561 1143 depends on BF561
1147 bool "Bank 1 16 bit packing enable" 1144 bool "Bank 1 16 bit packing enable"
1148 default y 1145 default y
1149 1146
1150 config C_B2PEN 1147 config C_B2PEN
1151 depends on BF561 1148 depends on BF561
1152 bool "Bank 2 16 bit packing enable" 1149 bool "Bank 2 16 bit packing enable"
1153 default y 1150 default y
1154 1151
1155 config C_B3PEN 1152 config C_B3PEN
1156 depends on BF561 1153 depends on BF561
1157 bool "Bank 3 16 bit packing enable" 1154 bool "Bank 3 16 bit packing enable"
1158 default n 1155 default n
1159 1156
1160 choice 1157 choice
1161 prompt "Enable Asynchronous Memory Banks" 1158 prompt "Enable Asynchronous Memory Banks"
1162 default C_AMBEN_ALL 1159 default C_AMBEN_ALL
1163 1160
1164 config C_AMBEN 1161 config C_AMBEN
1165 bool "Disable All Banks" 1162 bool "Disable All Banks"
1166 1163
1167 config C_AMBEN_B0 1164 config C_AMBEN_B0
1168 bool "Enable Bank 0" 1165 bool "Enable Bank 0"
1169 1166
1170 config C_AMBEN_B0_B1 1167 config C_AMBEN_B0_B1
1171 bool "Enable Bank 0 & 1" 1168 bool "Enable Bank 0 & 1"
1172 1169
1173 config C_AMBEN_B0_B1_B2 1170 config C_AMBEN_B0_B1_B2
1174 bool "Enable Bank 0 & 1 & 2" 1171 bool "Enable Bank 0 & 1 & 2"
1175 1172
1176 config C_AMBEN_ALL 1173 config C_AMBEN_ALL
1177 bool "Enable All Banks" 1174 bool "Enable All Banks"
1178 endchoice 1175 endchoice
1179 endmenu 1176 endmenu
1180 1177
1181 menu "EBIU_AMBCTL Control" 1178 menu "EBIU_AMBCTL Control"
1182 depends on !BF60x 1179 depends on !BF60x
1183 config BANK_0 1180 config BANK_0
1184 hex "Bank 0 (AMBCTL0.L)" 1181 hex "Bank 0 (AMBCTL0.L)"
1185 default 0x7BB0 1182 default 0x7BB0
1186 help 1183 help
1187 These are the low 16 bits of the EBIU_AMBCTL0 MMR which are 1184 These are the low 16 bits of the EBIU_AMBCTL0 MMR which are
1188 used to control the Asynchronous Memory Bank 0 settings. 1185 used to control the Asynchronous Memory Bank 0 settings.
1189 1186
1190 config BANK_1 1187 config BANK_1
1191 hex "Bank 1 (AMBCTL0.H)" 1188 hex "Bank 1 (AMBCTL0.H)"
1192 default 0x7BB0 1189 default 0x7BB0
1193 default 0x5558 if BF54x 1190 default 0x5558 if BF54x
1194 help 1191 help
1195 These are the high 16 bits of the EBIU_AMBCTL0 MMR which are 1192 These are the high 16 bits of the EBIU_AMBCTL0 MMR which are
1196 used to control the Asynchronous Memory Bank 1 settings. 1193 used to control the Asynchronous Memory Bank 1 settings.
1197 1194
1198 config BANK_2 1195 config BANK_2
1199 hex "Bank 2 (AMBCTL1.L)" 1196 hex "Bank 2 (AMBCTL1.L)"
1200 default 0x7BB0 1197 default 0x7BB0
1201 help 1198 help
1202 These are the low 16 bits of the EBIU_AMBCTL1 MMR which are 1199 These are the low 16 bits of the EBIU_AMBCTL1 MMR which are
1203 used to control the Asynchronous Memory Bank 2 settings. 1200 used to control the Asynchronous Memory Bank 2 settings.
1204 1201
1205 config BANK_3 1202 config BANK_3
1206 hex "Bank 3 (AMBCTL1.H)" 1203 hex "Bank 3 (AMBCTL1.H)"
1207 default 0x99B3 1204 default 0x99B3
1208 help 1205 help
1209 These are the high 16 bits of the EBIU_AMBCTL1 MMR which are 1206 These are the high 16 bits of the EBIU_AMBCTL1 MMR which are
1210 used to control the Asynchronous Memory Bank 3 settings. 1207 used to control the Asynchronous Memory Bank 3 settings.
1211 1208
1212 endmenu 1209 endmenu
1213 1210
1214 config EBIU_MBSCTLVAL 1211 config EBIU_MBSCTLVAL
1215 hex "EBIU Bank Select Control Register" 1212 hex "EBIU Bank Select Control Register"
1216 depends on BF54x 1213 depends on BF54x
1217 default 0 1214 default 0
1218 1215
1219 config EBIU_MODEVAL 1216 config EBIU_MODEVAL
1220 hex "Flash Memory Mode Control Register" 1217 hex "Flash Memory Mode Control Register"
1221 depends on BF54x 1218 depends on BF54x
1222 default 1 1219 default 1
1223 1220
1224 config EBIU_FCTLVAL 1221 config EBIU_FCTLVAL
1225 hex "Flash Memory Bank Control Register" 1222 hex "Flash Memory Bank Control Register"
1226 depends on BF54x 1223 depends on BF54x
1227 default 6 1224 default 6
1228 endmenu 1225 endmenu
1229 1226
1230 ############################################################################# 1227 #############################################################################
1231 menu "Bus options (PCI, PCMCIA, EISA, MCA, ISA)" 1228 menu "Bus options (PCI, PCMCIA, EISA, MCA, ISA)"
1232 1229
1233 config PCI 1230 config PCI
1234 bool "PCI support" 1231 bool "PCI support"
1235 depends on BROKEN 1232 depends on BROKEN
1236 help 1233 help
1237 Support for PCI bus. 1234 Support for PCI bus.
1238 1235
1239 source "drivers/pci/Kconfig" 1236 source "drivers/pci/Kconfig"
1240 1237
1241 source "drivers/pcmcia/Kconfig" 1238 source "drivers/pcmcia/Kconfig"
1242 1239
1243 source "drivers/pci/hotplug/Kconfig" 1240 source "drivers/pci/hotplug/Kconfig"
1244 1241
1245 endmenu 1242 endmenu
1246 1243
1247 menu "Executable file formats" 1244 menu "Executable file formats"
1248 1245
1249 source "fs/Kconfig.binfmt" 1246 source "fs/Kconfig.binfmt"
1250 1247
1251 endmenu 1248 endmenu
1252 1249
1253 menu "Power management options" 1250 menu "Power management options"
1254 1251
1255 source "kernel/power/Kconfig" 1252 source "kernel/power/Kconfig"
1256 1253
1257 config ARCH_SUSPEND_POSSIBLE 1254 config ARCH_SUSPEND_POSSIBLE
1258 def_bool y 1255 def_bool y
1259 1256
1260 choice 1257 choice
1261 prompt "Standby Power Saving Mode" 1258 prompt "Standby Power Saving Mode"
1262 depends on PM && !BF60x 1259 depends on PM && !BF60x
1263 default PM_BFIN_SLEEP_DEEPER 1260 default PM_BFIN_SLEEP_DEEPER
1264 config PM_BFIN_SLEEP_DEEPER 1261 config PM_BFIN_SLEEP_DEEPER
1265 bool "Sleep Deeper" 1262 bool "Sleep Deeper"
1266 help 1263 help
1267 Sleep "Deeper" Mode (High Power Savings) - This mode reduces dynamic 1264 Sleep "Deeper" Mode (High Power Savings) - This mode reduces dynamic
1268 power dissipation by disabling the clock to the processor core (CCLK). 1265 power dissipation by disabling the clock to the processor core (CCLK).
1269 Furthermore, Standby sets the internal power supply voltage (VDDINT) 1266 Furthermore, Standby sets the internal power supply voltage (VDDINT)
1270 to 0.85 V to provide the greatest power savings, while preserving the 1267 to 0.85 V to provide the greatest power savings, while preserving the
1271 processor state. 1268 processor state.
1272 The PLL and system clock (SCLK) continue to operate at a very low 1269 The PLL and system clock (SCLK) continue to operate at a very low
1273 frequency of about 3.3 MHz. To preserve data integrity in the SDRAM, 1270 frequency of about 3.3 MHz. To preserve data integrity in the SDRAM,
1274 the SDRAM is put into Self Refresh Mode. Typically an external event 1271 the SDRAM is put into Self Refresh Mode. Typically an external event
1275 such as GPIO interrupt or RTC activity wakes up the processor. 1272 such as GPIO interrupt or RTC activity wakes up the processor.
1276 Various Peripherals such as UART, SPORT, PPI may not function as 1273 Various Peripherals such as UART, SPORT, PPI may not function as
1277 normal during Sleep Deeper, due to the reduced SCLK frequency. 1274 normal during Sleep Deeper, due to the reduced SCLK frequency.
1278 When in the sleep mode, system DMA access to L1 memory is not supported. 1275 When in the sleep mode, system DMA access to L1 memory is not supported.
1279 1276
1280 If unsure, select "Sleep Deeper". 1277 If unsure, select "Sleep Deeper".
1281 1278
1282 config PM_BFIN_SLEEP 1279 config PM_BFIN_SLEEP
1283 bool "Sleep" 1280 bool "Sleep"
1284 help 1281 help
1285 Sleep Mode (High Power Savings) - The sleep mode reduces power 1282 Sleep Mode (High Power Savings) - The sleep mode reduces power
1286 dissipation by disabling the clock to the processor core (CCLK). 1283 dissipation by disabling the clock to the processor core (CCLK).
1287 The PLL and system clock (SCLK), however, continue to operate in 1284 The PLL and system clock (SCLK), however, continue to operate in
1288 this mode. Typically an external event or RTC activity will wake 1285 this mode. Typically an external event or RTC activity will wake
1289 up the processor. When in the sleep mode, system DMA access to L1 1286 up the processor. When in the sleep mode, system DMA access to L1
1290 memory is not supported. 1287 memory is not supported.
1291 1288
1292 If unsure, select "Sleep Deeper". 1289 If unsure, select "Sleep Deeper".
1293 endchoice 1290 endchoice
1294 1291
1295 comment "Possible Suspend Mem / Hibernate Wake-Up Sources" 1292 comment "Possible Suspend Mem / Hibernate Wake-Up Sources"
1296 depends on PM 1293 depends on PM
1297 1294
1298 config PM_BFIN_WAKE_PH6 1295 config PM_BFIN_WAKE_PH6
1299 bool "Allow Wake-Up from on-chip PHY or PH6 GP" 1296 bool "Allow Wake-Up from on-chip PHY or PH6 GP"
1300 depends on PM && (BF51x || BF52x || BF534 || BF536 || BF537) 1297 depends on PM && (BF51x || BF52x || BF534 || BF536 || BF537)
1301 default n 1298 default n
1302 help 1299 help
1303 Enable PHY and PH6 GP Wake-Up (Voltage Regulator Power-Up) 1300 Enable PHY and PH6 GP Wake-Up (Voltage Regulator Power-Up)
1304 1301
1305 config PM_BFIN_WAKE_GP 1302 config PM_BFIN_WAKE_GP
1306 bool "Allow Wake-Up from GPIOs" 1303 bool "Allow Wake-Up from GPIOs"
1307 depends on PM && BF54x 1304 depends on PM && BF54x
1308 default n 1305 default n
1309 help 1306 help
1310 Enable General-Purpose Wake-Up (Voltage Regulator Power-Up) 1307 Enable General-Purpose Wake-Up (Voltage Regulator Power-Up)
1311 (all processors, except ADSP-BF549). This option sets 1308 (all processors, except ADSP-BF549). This option sets
1312 the general-purpose wake-up enable (GPWE) control bit to enable 1309 the general-purpose wake-up enable (GPWE) control bit to enable
1313 wake-up upon detection of an active low signal on the /GPW (PH7) pin. 1310 wake-up upon detection of an active low signal on the /GPW (PH7) pin.
1314 On ADSP-BF549 this option enables the same functionality on the 1311 On ADSP-BF549 this option enables the same functionality on the
1315 /MRXON pin also PH7. 1312 /MRXON pin also PH7.
1316 1313
1317 config PM_BFIN_WAKE_PA15 1314 config PM_BFIN_WAKE_PA15
1318 bool "Allow Wake-Up from PA15" 1315 bool "Allow Wake-Up from PA15"
1319 depends on PM && BF60x 1316 depends on PM && BF60x
1320 default n 1317 default n
1321 help 1318 help
1322 Enable PA15 Wake-Up 1319 Enable PA15 Wake-Up
1323 1320
1324 config PM_BFIN_WAKE_PA15_POL 1321 config PM_BFIN_WAKE_PA15_POL
1325 int "Wake-up priority" 1322 int "Wake-up priority"
1326 depends on PM_BFIN_WAKE_PA15 1323 depends on PM_BFIN_WAKE_PA15
1327 default 0 1324 default 0
1328 help 1325 help
1329 Wake-Up priority 0(low) 1(high) 1326 Wake-Up priority 0(low) 1(high)
1330 1327
1331 config PM_BFIN_WAKE_PB15 1328 config PM_BFIN_WAKE_PB15
1332 bool "Allow Wake-Up from PB15" 1329 bool "Allow Wake-Up from PB15"
1333 depends on PM && BF60x 1330 depends on PM && BF60x
1334 default n 1331 default n
1335 help 1332 help
1336 Enable PB15 Wake-Up 1333 Enable PB15 Wake-Up
1337 1334
1338 config PM_BFIN_WAKE_PB15_POL 1335 config PM_BFIN_WAKE_PB15_POL
1339 int "Wake-up priority" 1336 int "Wake-up priority"
1340 depends on PM_BFIN_WAKE_PB15 1337 depends on PM_BFIN_WAKE_PB15
1341 default 0 1338 default 0
1342 help 1339 help
1343 Wake-Up priority 0(low) 1(high) 1340 Wake-Up priority 0(low) 1(high)
1344 1341
1345 config PM_BFIN_WAKE_PC15 1342 config PM_BFIN_WAKE_PC15
1346 bool "Allow Wake-Up from PC15" 1343 bool "Allow Wake-Up from PC15"
1347 depends on PM && BF60x 1344 depends on PM && BF60x
1348 default n 1345 default n
1349 help 1346 help
1350 Enable PC15 Wake-Up 1347 Enable PC15 Wake-Up
1351 1348
1352 config PM_BFIN_WAKE_PC15_POL 1349 config PM_BFIN_WAKE_PC15_POL
1353 int "Wake-up priority" 1350 int "Wake-up priority"
1354 depends on PM_BFIN_WAKE_PC15 1351 depends on PM_BFIN_WAKE_PC15
1355 default 0 1352 default 0
1356 help 1353 help
1357 Wake-Up priority 0(low) 1(high) 1354 Wake-Up priority 0(low) 1(high)
1358 1355
1359 config PM_BFIN_WAKE_PD06 1356 config PM_BFIN_WAKE_PD06
1360 bool "Allow Wake-Up from PD06(ETH0_PHYINT)" 1357 bool "Allow Wake-Up from PD06(ETH0_PHYINT)"
1361 depends on PM && BF60x 1358 depends on PM && BF60x
1362 default n 1359 default n
1363 help 1360 help
1364 Enable PD06(ETH0_PHYINT) Wake-up 1361 Enable PD06(ETH0_PHYINT) Wake-up
1365 1362
1366 config PM_BFIN_WAKE_PD06_POL 1363 config PM_BFIN_WAKE_PD06_POL
1367 int "Wake-up priority" 1364 int "Wake-up priority"
1368 depends on PM_BFIN_WAKE_PD06 1365 depends on PM_BFIN_WAKE_PD06
1369 default 0 1366 default 0
1370 help 1367 help
1371 Wake-Up priority 0(low) 1(high) 1368 Wake-Up priority 0(low) 1(high)
1372 1369
1373 config PM_BFIN_WAKE_PE12 1370 config PM_BFIN_WAKE_PE12
1374 bool "Allow Wake-Up from PE12(ETH1_PHYINT, PUSH BUTTON)" 1371 bool "Allow Wake-Up from PE12(ETH1_PHYINT, PUSH BUTTON)"
1375 depends on PM && BF60x 1372 depends on PM && BF60x
1376 default n 1373 default n
1377 help 1374 help
1378 Enable PE12(ETH1_PHYINT, PUSH BUTTON) Wake-up 1375 Enable PE12(ETH1_PHYINT, PUSH BUTTON) Wake-up
1379 1376
1380 config PM_BFIN_WAKE_PE12_POL 1377 config PM_BFIN_WAKE_PE12_POL
1381 int "Wake-up priority" 1378 int "Wake-up priority"
1382 depends on PM_BFIN_WAKE_PE12 1379 depends on PM_BFIN_WAKE_PE12
1383 default 0 1380 default 0
1384 help 1381 help
1385 Wake-Up priority 0(low) 1(high) 1382 Wake-Up priority 0(low) 1(high)
1386 1383
1387 config PM_BFIN_WAKE_PG04 1384 config PM_BFIN_WAKE_PG04
1388 bool "Allow Wake-Up from PG04(CAN0_RX)" 1385 bool "Allow Wake-Up from PG04(CAN0_RX)"
1389 depends on PM && BF60x 1386 depends on PM && BF60x
1390 default n 1387 default n
1391 help 1388 help
1392 Enable PG04(CAN0_RX) Wake-up 1389 Enable PG04(CAN0_RX) Wake-up
1393 1390
1394 config PM_BFIN_WAKE_PG04_POL 1391 config PM_BFIN_WAKE_PG04_POL
1395 int "Wake-up priority" 1392 int "Wake-up priority"
1396 depends on PM_BFIN_WAKE_PG04 1393 depends on PM_BFIN_WAKE_PG04
1397 default 0 1394 default 0
1398 help 1395 help
1399 Wake-Up priority 0(low) 1(high) 1396 Wake-Up priority 0(low) 1(high)
1400 1397
1401 config PM_BFIN_WAKE_PG13 1398 config PM_BFIN_WAKE_PG13
1402 bool "Allow Wake-Up from PG13" 1399 bool "Allow Wake-Up from PG13"
1403 depends on PM && BF60x 1400 depends on PM && BF60x
1404 default n 1401 default n
1405 help 1402 help
1406 Enable PG13 Wake-Up 1403 Enable PG13 Wake-Up
1407 1404
1408 config PM_BFIN_WAKE_PG13_POL 1405 config PM_BFIN_WAKE_PG13_POL
1409 int "Wake-up priority" 1406 int "Wake-up priority"
1410 depends on PM_BFIN_WAKE_PG13 1407 depends on PM_BFIN_WAKE_PG13
1411 default 0 1408 default 0
1412 help 1409 help
1413 Wake-Up priority 0(low) 1(high) 1410 Wake-Up priority 0(low) 1(high)
1414 1411
1415 config PM_BFIN_WAKE_USB 1412 config PM_BFIN_WAKE_USB
1416 bool "Allow Wake-Up from (USB)" 1413 bool "Allow Wake-Up from (USB)"
1417 depends on PM && BF60x 1414 depends on PM && BF60x
1418 default n 1415 default n
1419 help 1416 help
1420 Enable (USB) Wake-up 1417 Enable (USB) Wake-up
1421 1418
1422 config PM_BFIN_WAKE_USB_POL 1419 config PM_BFIN_WAKE_USB_POL
1423 int "Wake-up priority" 1420 int "Wake-up priority"
1424 depends on PM_BFIN_WAKE_USB 1421 depends on PM_BFIN_WAKE_USB
1425 default 0 1422 default 0
1426 help 1423 help
1427 Wake-Up priority 0(low) 1(high) 1424 Wake-Up priority 0(low) 1(high)
1428 1425
1429 endmenu 1426 endmenu
1430 1427
1431 menu "CPU Frequency scaling" 1428 menu "CPU Frequency scaling"
1432 1429
1433 source "drivers/cpufreq/Kconfig" 1430 source "drivers/cpufreq/Kconfig"
1434 1431
1435 config BFIN_CPU_FREQ 1432 config BFIN_CPU_FREQ
1436 bool 1433 bool
1437 depends on CPU_FREQ 1434 depends on CPU_FREQ
1438 select CPU_FREQ_TABLE 1435 select CPU_FREQ_TABLE
1439 default y 1436 default y
1440 1437
1441 config CPU_VOLTAGE 1438 config CPU_VOLTAGE
1442 bool "CPU Voltage scaling" 1439 bool "CPU Voltage scaling"
1443 depends on CPU_FREQ 1440 depends on CPU_FREQ
1444 default n 1441 default n
1445 help 1442 help
1446 Say Y here if you want CPU voltage scaling according to the CPU frequency. 1443 Say Y here if you want CPU voltage scaling according to the CPU frequency.
1447 This option violates the PLL BYPASS recommendation in the Blackfin Processor 1444 This option violates the PLL BYPASS recommendation in the Blackfin Processor
1448 manuals. There is a theoretical risk that during VDDINT transitions 1445 manuals. There is a theoretical risk that during VDDINT transitions
1449 the PLL may unlock. 1446 the PLL may unlock.
1450 1447
1451 endmenu 1448 endmenu
1452 1449
1453 source "net/Kconfig" 1450 source "net/Kconfig"
1454 1451
1455 source "drivers/Kconfig" 1452 source "drivers/Kconfig"
1456 1453
1457 source "drivers/firmware/Kconfig" 1454 source "drivers/firmware/Kconfig"
1458 1455
1459 source "fs/Kconfig" 1456 source "fs/Kconfig"
1460 1457
1461 source "arch/blackfin/Kconfig.debug" 1458 source "arch/blackfin/Kconfig.debug"
1462 1459
1463 source "security/Kconfig" 1460 source "security/Kconfig"
1464 1461
1465 source "crypto/Kconfig" 1462 source "crypto/Kconfig"
1466 1463
1467 source "lib/Kconfig" 1464 source "lib/Kconfig"
1 config H8300 1 config H8300
2 bool 2 bool
3 default y 3 default y
4 select HAVE_IDE 4 select HAVE_IDE
5 select HAVE_GENERIC_HARDIRQS 5 select HAVE_GENERIC_HARDIRQS
6 select GENERIC_ATOMIC64 6 select GENERIC_ATOMIC64
7 select HAVE_UID16 7 select HAVE_UID16
8 select VIRT_TO_BUS 8 select VIRT_TO_BUS
9 select ARCH_WANT_IPC_PARSE_VERSION 9 select ARCH_WANT_IPC_PARSE_VERSION
10 select GENERIC_IRQ_SHOW 10 select GENERIC_IRQ_SHOW
11 select GENERIC_CPU_DEVICES 11 select GENERIC_CPU_DEVICES
12 select MODULES_USE_ELF_RELA 12 select MODULES_USE_ELF_RELA
13 select OLD_SIGSUSPEND3 13 select OLD_SIGSUSPEND3
14 select OLD_SIGACTION 14 select OLD_SIGACTION
15 15 select HAVE_UNDERSCORE_SYMBOL_PREFIX
16 config SYMBOL_PREFIX
17 string
18 default "_"
19 16
20 config MMU 17 config MMU
21 bool 18 bool
22 default n 19 default n
23 20
24 config SWAP 21 config SWAP
25 bool 22 bool
26 default n 23 default n
27 24
28 config ZONE_DMA 25 config ZONE_DMA
29 bool 26 bool
30 default y 27 default y
31 28
32 config FPU 29 config FPU
33 bool 30 bool
34 default n 31 default n
35 32
36 config RWSEM_GENERIC_SPINLOCK 33 config RWSEM_GENERIC_SPINLOCK
37 bool 34 bool
38 default y 35 default y
39 36
40 config RWSEM_XCHGADD_ALGORITHM 37 config RWSEM_XCHGADD_ALGORITHM
41 bool 38 bool
42 default n 39 default n
43 40
44 config ARCH_HAS_ILOG2_U32 41 config ARCH_HAS_ILOG2_U32
45 bool 42 bool
46 default n 43 default n
47 44
48 config ARCH_HAS_ILOG2_U64 45 config ARCH_HAS_ILOG2_U64
49 bool 46 bool
50 default n 47 default n
51 48
52 config GENERIC_HWEIGHT 49 config GENERIC_HWEIGHT
53 bool 50 bool
54 default y 51 default y
55 52
56 config GENERIC_CALIBRATE_DELAY 53 config GENERIC_CALIBRATE_DELAY
57 bool 54 bool
58 default y 55 default y
59 56
60 config GENERIC_BUG 57 config GENERIC_BUG
61 bool 58 bool
62 depends on BUG 59 depends on BUG
63 60
64 config TIME_LOW_RES 61 config TIME_LOW_RES
65 bool 62 bool
66 default y 63 default y
67 64
68 config NO_IOPORT 65 config NO_IOPORT
69 def_bool y 66 def_bool y
70 67
71 config NO_DMA 68 config NO_DMA
72 def_bool y 69 def_bool y
73 70
74 config ISA 71 config ISA
75 bool 72 bool
76 default y 73 default y
77 74
78 config PCI 75 config PCI
79 bool 76 bool
80 default n 77 default n
81 78
82 config HZ 79 config HZ
83 int 80 int
84 default 100 81 default 100
85 82
86 source "init/Kconfig" 83 source "init/Kconfig"
87 84
88 source "kernel/Kconfig.freezer" 85 source "kernel/Kconfig.freezer"
89 86
90 source "arch/h8300/Kconfig.cpu" 87 source "arch/h8300/Kconfig.cpu"
91 88
92 menu "Executable file formats" 89 menu "Executable file formats"
93 90
94 source "fs/Kconfig.binfmt" 91 source "fs/Kconfig.binfmt"
95 92
96 endmenu 93 endmenu
97 94
98 source "net/Kconfig" 95 source "net/Kconfig"
99 96
100 source "drivers/base/Kconfig" 97 source "drivers/base/Kconfig"
101 98
102 source "drivers/mtd/Kconfig" 99 source "drivers/mtd/Kconfig"
103 100
104 source "drivers/block/Kconfig" 101 source "drivers/block/Kconfig"
105 102
106 source "drivers/ide/Kconfig" 103 source "drivers/ide/Kconfig"
107 104
108 source "arch/h8300/Kconfig.ide" 105 source "arch/h8300/Kconfig.ide"
109 106
110 source "drivers/net/Kconfig" 107 source "drivers/net/Kconfig"
111 108
112 # 109 #
113 # input - input/joystick depends on it. As does USB. 110 # input - input/joystick depends on it. As does USB.
114 # 111 #
115 source "drivers/input/Kconfig" 112 source "drivers/input/Kconfig"
116 113
117 menu "Character devices" 114 menu "Character devices"
118 115
119 config VT 116 config VT
120 bool "Virtual terminal" 117 bool "Virtual terminal"
121 ---help--- 118 ---help---
122 If you say Y here, you will get support for terminal devices with 119 If you say Y here, you will get support for terminal devices with
123 display and keyboard devices. These are called "virtual" because you 120 display and keyboard devices. These are called "virtual" because you
124 can run several virtual terminals (also called virtual consoles) on 121 can run several virtual terminals (also called virtual consoles) on
125 one physical terminal. This is rather useful, for example one 122 one physical terminal. This is rather useful, for example one
126 virtual terminal can collect system messages and warnings, another 123 virtual terminal can collect system messages and warnings, another
127 one can be used for a text-mode user session, and a third could run 124 one can be used for a text-mode user session, and a third could run
128 an X session, all in parallel. Switching between virtual terminals 125 an X session, all in parallel. Switching between virtual terminals
129 is done with certain key combinations, usually Alt-<function key>. 126 is done with certain key combinations, usually Alt-<function key>.
130 127
131 The setterm command ("man setterm") can be used to change the 128 The setterm command ("man setterm") can be used to change the
132 properties (such as colors or beeping) of a virtual terminal. The 129 properties (such as colors or beeping) of a virtual terminal. The
133 man page console_codes(4) ("man console_codes") contains the special 130 man page console_codes(4) ("man console_codes") contains the special
134 character sequences that can be used to change those properties 131 character sequences that can be used to change those properties
135 directly. The fonts used on virtual terminals can be changed with 132 directly. The fonts used on virtual terminals can be changed with
136 the setfont ("man setfont") command and the key bindings are defined 133 the setfont ("man setfont") command and the key bindings are defined
137 with the loadkeys ("man loadkeys") command. 134 with the loadkeys ("man loadkeys") command.
138 135
139 You need at least one virtual terminal device in order to make use 136 You need at least one virtual terminal device in order to make use
140 of your keyboard and monitor. Therefore, only people configuring an 137 of your keyboard and monitor. Therefore, only people configuring an
141 embedded system would want to say N here in order to save some 138 embedded system would want to say N here in order to save some
142 memory; the only way to log into such a system is then via a serial 139 memory; the only way to log into such a system is then via a serial
143 or network connection. 140 or network connection.
144 141
145 If unsure, say Y, or else you won't be able to do much with your new 142 If unsure, say Y, or else you won't be able to do much with your new
146 shiny Linux system :-) 143 shiny Linux system :-)
147 144
148 config VT_CONSOLE 145 config VT_CONSOLE
149 bool "Support for console on virtual terminal" 146 bool "Support for console on virtual terminal"
150 depends on VT 147 depends on VT
151 ---help--- 148 ---help---
152 The system console is the device which receives all kernel messages 149 The system console is the device which receives all kernel messages
153 and warnings and which allows logins in single user mode. If you 150 and warnings and which allows logins in single user mode. If you
154 answer Y here, a virtual terminal (the device used to interact with 151 answer Y here, a virtual terminal (the device used to interact with
155 a physical terminal) can be used as system console. This is the most 152 a physical terminal) can be used as system console. This is the most
156 common mode of operations, so you should say Y here unless you want 153 common mode of operations, so you should say Y here unless you want
157 the kernel messages be output only to a serial port (in which case 154 the kernel messages be output only to a serial port (in which case
158 you should say Y to "Console on serial port", below). 155 you should say Y to "Console on serial port", below).
159 156
160 If you do say Y here, by default the currently visible virtual 157 If you do say Y here, by default the currently visible virtual
161 terminal (/dev/tty0) will be used as system console. You can change 158 terminal (/dev/tty0) will be used as system console. You can change
162 that with a kernel command line option such as "console=tty3" which 159 that with a kernel command line option such as "console=tty3" which
163 would use the third virtual terminal as system console. (Try "man 160 would use the third virtual terminal as system console. (Try "man
164 bootparam" or see the documentation of your boot loader (lilo or 161 bootparam" or see the documentation of your boot loader (lilo or
165 loadlin) about how to pass options to the kernel at boot time.) 162 loadlin) about how to pass options to the kernel at boot time.)
166 163
167 If unsure, say Y. 164 If unsure, say Y.
168 165
169 config HW_CONSOLE 166 config HW_CONSOLE
170 bool 167 bool
171 depends on VT 168 depends on VT
172 default y 169 default y
173 170
174 comment "Unix98 PTY support" 171 comment "Unix98 PTY support"
175 172
176 config UNIX98_PTYS 173 config UNIX98_PTYS
177 bool "Unix98 PTY support" 174 bool "Unix98 PTY support"
178 ---help--- 175 ---help---
179 A pseudo terminal (PTY) is a software device consisting of two 176 A pseudo terminal (PTY) is a software device consisting of two
180 halves: a master and a slave. The slave device behaves identical to 177 halves: a master and a slave. The slave device behaves identical to
181 a physical terminal; the master device is used by a process to 178 a physical terminal; the master device is used by a process to
182 read data from and write data to the slave, thereby emulating a 179 read data from and write data to the slave, thereby emulating a
183 terminal. Typical programs for the master side are telnet servers 180 terminal. Typical programs for the master side are telnet servers
184 and xterms. 181 and xterms.
185 182
186 Linux has traditionally used the BSD-like names /dev/ptyxx for 183 Linux has traditionally used the BSD-like names /dev/ptyxx for
187 masters and /dev/ttyxx for slaves of pseudo terminals. This scheme 184 masters and /dev/ttyxx for slaves of pseudo terminals. This scheme
188 has a number of problems. The GNU C library glibc 2.1 and later, 185 has a number of problems. The GNU C library glibc 2.1 and later,
189 however, supports the Unix98 naming standard: in order to acquire a 186 however, supports the Unix98 naming standard: in order to acquire a
190 pseudo terminal, a process opens /dev/ptmx; the number of the pseudo 187 pseudo terminal, a process opens /dev/ptmx; the number of the pseudo
191 terminal is then made available to the process and the pseudo 188 terminal is then made available to the process and the pseudo
192 terminal slave can be accessed as /dev/pts/<number>. What was 189 terminal slave can be accessed as /dev/pts/<number>. What was
193 traditionally /dev/ttyp2 will then be /dev/pts/2, for example. 190 traditionally /dev/ttyp2 will then be /dev/pts/2, for example.
194 191
195 The entries in /dev/pts/ are created on the fly by a virtual 192 The entries in /dev/pts/ are created on the fly by a virtual
196 file system; therefore, if you say Y here you should say Y to 193 file system; therefore, if you say Y here you should say Y to
197 "/dev/pts file system for Unix98 PTYs" as well. 194 "/dev/pts file system for Unix98 PTYs" as well.
198 195
199 If you want to say Y here, you need to have the C library glibc 2.1 196 If you want to say Y here, you need to have the C library glibc 2.1
200 or later (equal to libc-6.1, check with "ls -l /lib/libc.so.*"). 197 or later (equal to libc-6.1, check with "ls -l /lib/libc.so.*").
201 Read the instructions in <file:Documentation/Changes> pertaining to 198 Read the instructions in <file:Documentation/Changes> pertaining to
202 pseudo terminals. It's safe to say N. 199 pseudo terminals. It's safe to say N.
203 200
204 source "drivers/char/pcmcia/Kconfig" 201 source "drivers/char/pcmcia/Kconfig"
205 202
206 source "drivers/tty/serial/Kconfig" 203 source "drivers/tty/serial/Kconfig"
207 204
208 source "drivers/i2c/Kconfig" 205 source "drivers/i2c/Kconfig"
209 206
210 source "drivers/hwmon/Kconfig" 207 source "drivers/hwmon/Kconfig"
211 208
212 source "drivers/usb/Kconfig" 209 source "drivers/usb/Kconfig"
213 210
214 source "drivers/uwb/Kconfig" 211 source "drivers/uwb/Kconfig"
215 212
216 endmenu 213 endmenu
217 214
218 source "drivers/staging/Kconfig" 215 source "drivers/staging/Kconfig"
219 216
220 source "fs/Kconfig" 217 source "fs/Kconfig"
221 218
222 source "arch/h8300/Kconfig.debug" 219 source "arch/h8300/Kconfig.debug"
223 220
224 source "security/Kconfig" 221 source "security/Kconfig"
225 222
226 source "crypto/Kconfig" 223 source "crypto/Kconfig"
227 224
228 source "lib/Kconfig" 225 source "lib/Kconfig"
229 226
1 config SYMBOL_PREFIX
2 string
3 default "_"
4
5 config METAG 1 config METAG
6 def_bool y 2 def_bool y
7 select EMBEDDED 3 select EMBEDDED
8 select GENERIC_ATOMIC64 4 select GENERIC_ATOMIC64
9 select GENERIC_CLOCKEVENTS 5 select GENERIC_CLOCKEVENTS
10 select GENERIC_IRQ_SHOW 6 select GENERIC_IRQ_SHOW
11 select GENERIC_SMP_IDLE_THREAD 7 select GENERIC_SMP_IDLE_THREAD
12 select HAVE_64BIT_ALIGNED_ACCESS 8 select HAVE_64BIT_ALIGNED_ACCESS
13 select HAVE_ARCH_TRACEHOOK 9 select HAVE_ARCH_TRACEHOOK
14 select HAVE_C_RECORDMCOUNT 10 select HAVE_C_RECORDMCOUNT
15 select HAVE_DEBUG_KMEMLEAK 11 select HAVE_DEBUG_KMEMLEAK
16 select HAVE_DYNAMIC_FTRACE 12 select HAVE_DYNAMIC_FTRACE
17 select HAVE_FTRACE_MCOUNT_RECORD 13 select HAVE_FTRACE_MCOUNT_RECORD
18 select HAVE_FUNCTION_TRACER 14 select HAVE_FUNCTION_TRACER
19 select HAVE_FUNCTION_TRACE_MCOUNT_TEST 15 select HAVE_FUNCTION_TRACE_MCOUNT_TEST
20 select HAVE_GENERIC_HARDIRQS 16 select HAVE_GENERIC_HARDIRQS
21 select HAVE_KERNEL_BZIP2 17 select HAVE_KERNEL_BZIP2
22 select HAVE_KERNEL_GZIP 18 select HAVE_KERNEL_GZIP
23 select HAVE_KERNEL_LZO 19 select HAVE_KERNEL_LZO
24 select HAVE_KERNEL_XZ 20 select HAVE_KERNEL_XZ
25 select HAVE_MEMBLOCK 21 select HAVE_MEMBLOCK
26 select HAVE_MEMBLOCK_NODE_MAP 22 select HAVE_MEMBLOCK_NODE_MAP
27 select HAVE_MOD_ARCH_SPECIFIC 23 select HAVE_MOD_ARCH_SPECIFIC
28 select HAVE_OPROFILE 24 select HAVE_OPROFILE
29 select HAVE_PERF_EVENTS 25 select HAVE_PERF_EVENTS
30 select HAVE_SYSCALL_TRACEPOINTS 26 select HAVE_SYSCALL_TRACEPOINTS
27 select HAVE_UNDERSCORE_SYMBOL_PREFIX
31 select IRQ_DOMAIN 28 select IRQ_DOMAIN
32 select MODULES_USE_ELF_RELA 29 select MODULES_USE_ELF_RELA
33 select OF 30 select OF
34 select OF_EARLY_FLATTREE 31 select OF_EARLY_FLATTREE
35 select SPARSE_IRQ 32 select SPARSE_IRQ
36 33
37 config STACKTRACE_SUPPORT 34 config STACKTRACE_SUPPORT
38 def_bool y 35 def_bool y
39 36
40 config LOCKDEP_SUPPORT 37 config LOCKDEP_SUPPORT
41 def_bool y 38 def_bool y
42 39
43 config HAVE_LATENCYTOP_SUPPORT 40 config HAVE_LATENCYTOP_SUPPORT
44 def_bool y 41 def_bool y
45 42
46 config RWSEM_GENERIC_SPINLOCK 43 config RWSEM_GENERIC_SPINLOCK
47 def_bool y 44 def_bool y
48 45
49 config RWSEM_XCHGADD_ALGORITHM 46 config RWSEM_XCHGADD_ALGORITHM
50 bool 47 bool
51 48
52 config GENERIC_HWEIGHT 49 config GENERIC_HWEIGHT
53 def_bool y 50 def_bool y
54 51
55 config GENERIC_CALIBRATE_DELAY 52 config GENERIC_CALIBRATE_DELAY
56 def_bool y 53 def_bool y
57 54
58 config GENERIC_GPIO 55 config GENERIC_GPIO
59 def_bool n 56 def_bool n
60 57
61 config NO_IOPORT 58 config NO_IOPORT
62 def_bool y 59 def_bool y
63 60
64 source "init/Kconfig" 61 source "init/Kconfig"
65 62
66 source "kernel/Kconfig.freezer" 63 source "kernel/Kconfig.freezer"
67 64
68 menu "Processor type and features" 65 menu "Processor type and features"
69 66
70 config MMU 67 config MMU
71 def_bool y 68 def_bool y
72 69
73 config STACK_GROWSUP 70 config STACK_GROWSUP
74 def_bool y 71 def_bool y
75 72
76 config HOTPLUG_CPU 73 config HOTPLUG_CPU
77 bool "Enable CPU hotplug support" 74 bool "Enable CPU hotplug support"
78 depends on SMP 75 depends on SMP
79 help 76 help
80 Say Y here to allow turning CPUs off and on. CPUs can be 77 Say Y here to allow turning CPUs off and on. CPUs can be
81 controlled through /sys/devices/system/cpu. 78 controlled through /sys/devices/system/cpu.
82 79
83 Say N if you want to disable CPU hotplug. 80 Say N if you want to disable CPU hotplug.
84 81
85 config HIGHMEM 82 config HIGHMEM
86 bool "High Memory Support" 83 bool "High Memory Support"
87 help 84 help
88 The address space of Meta processors is only 4 Gigabytes large 85 The address space of Meta processors is only 4 Gigabytes large
89 and it has to accommodate user address space, kernel address 86 and it has to accommodate user address space, kernel address
90 space as well as some memory mapped IO. That means that, if you 87 space as well as some memory mapped IO. That means that, if you
91 have a large amount of physical memory and/or IO, not all of the 88 have a large amount of physical memory and/or IO, not all of the
92 memory can be "permanently mapped" by the kernel. The physical 89 memory can be "permanently mapped" by the kernel. The physical
93 memory that is not permanently mapped is called "high memory". 90 memory that is not permanently mapped is called "high memory".
94 91
95 Depending on the selected kernel/user memory split, minimum 92 Depending on the selected kernel/user memory split, minimum
96 vmalloc space and actual amount of RAM, you may not need this 93 vmalloc space and actual amount of RAM, you may not need this
97 option which should result in a slightly faster kernel. 94 option which should result in a slightly faster kernel.
98 95
99 If unsure, say n. 96 If unsure, say n.
100 97
101 source "arch/metag/mm/Kconfig" 98 source "arch/metag/mm/Kconfig"
102 99
103 source "arch/metag/Kconfig.soc" 100 source "arch/metag/Kconfig.soc"
104 101
105 config METAG_META12 102 config METAG_META12
106 bool 103 bool
107 help 104 help
108 Select this from the SoC config symbol to indicate that it contains a 105 Select this from the SoC config symbol to indicate that it contains a
109 Meta 1.2 core. 106 Meta 1.2 core.
110 107
111 config METAG_META21 108 config METAG_META21
112 bool 109 bool
113 help 110 help
114 Select this from the SoC config symbol to indicate that it contains a 111 Select this from the SoC config symbol to indicate that it contains a
115 Meta 2.1 core. 112 Meta 2.1 core.
116 113
117 config SMP 114 config SMP
118 bool "Symmetric multi-processing support" 115 bool "Symmetric multi-processing support"
119 depends on METAG_META21 && METAG_META21_MMU 116 depends on METAG_META21 && METAG_META21_MMU
120 select USE_GENERIC_SMP_HELPERS 117 select USE_GENERIC_SMP_HELPERS
121 help 118 help
122 This enables support for systems with more than one thread running 119 This enables support for systems with more than one thread running
123 Linux. If you have a system with only one thread running Linux, 120 Linux. If you have a system with only one thread running Linux,
124 say N. Otherwise, say Y. 121 say N. Otherwise, say Y.
125 122
126 config NR_CPUS 123 config NR_CPUS
127 int "Maximum number of CPUs (2-4)" if SMP 124 int "Maximum number of CPUs (2-4)" if SMP
128 range 2 4 if SMP 125 range 2 4 if SMP
129 default "1" if !SMP 126 default "1" if !SMP
130 default "4" if SMP 127 default "4" if SMP
131 128
132 config METAG_SMP_WRITE_REORDERING 129 config METAG_SMP_WRITE_REORDERING
133 bool 130 bool
134 help 131 help
135 This attempts to prevent cache-memory incoherence due to external 132 This attempts to prevent cache-memory incoherence due to external
136 reordering of writes from different hardware threads when SMP is 133 reordering of writes from different hardware threads when SMP is
137 enabled. It adds fences (system event 0) to smp_mb and smp_rmb in an 134 enabled. It adds fences (system event 0) to smp_mb and smp_rmb in an
138 attempt to catch some of the cases, and also before writes to shared 135 attempt to catch some of the cases, and also before writes to shared
139 memory in LOCK1 protected atomics and spinlocks. 136 memory in LOCK1 protected atomics and spinlocks.
140 This will not completely prevent cache incoherency on affected cores. 137 This will not completely prevent cache incoherency on affected cores.
141 138
142 config METAG_LNKGET_AROUND_CACHE 139 config METAG_LNKGET_AROUND_CACHE
143 bool 140 bool
144 depends on METAG_META21 141 depends on METAG_META21
145 help 142 help
146 This indicates that the LNKGET/LNKSET instructions go around the 143 This indicates that the LNKGET/LNKSET instructions go around the
147 cache, which requires some extra cache flushes when the memory needs 144 cache, which requires some extra cache flushes when the memory needs
148 to be accessed by normal GET/SET instructions too. 145 to be accessed by normal GET/SET instructions too.
149 146
150 choice 147 choice
151 prompt "Atomicity primitive" 148 prompt "Atomicity primitive"
152 default METAG_ATOMICITY_LNKGET 149 default METAG_ATOMICITY_LNKGET
153 help 150 help
154 This option selects the mechanism for performing atomic operations. 151 This option selects the mechanism for performing atomic operations.
155 152
156 config METAG_ATOMICITY_IRQSOFF 153 config METAG_ATOMICITY_IRQSOFF
157 depends on !SMP 154 depends on !SMP
158 bool "irqsoff" 155 bool "irqsoff"
159 help 156 help
160 This option disables interrupts to achieve atomicity. This mechanism 157 This option disables interrupts to achieve atomicity. This mechanism
161 is not SMP-safe. 158 is not SMP-safe.
162 159
163 config METAG_ATOMICITY_LNKGET 160 config METAG_ATOMICITY_LNKGET
164 depends on METAG_META21 161 depends on METAG_META21
165 bool "lnkget/lnkset" 162 bool "lnkget/lnkset"
166 help 163 help
167 This option uses the LNKGET and LNKSET instructions to achieve 164 This option uses the LNKGET and LNKSET instructions to achieve
168 atomicity. LNKGET/LNKSET are load-link/store-conditional instructions. 165 atomicity. LNKGET/LNKSET are load-link/store-conditional instructions.
169 Choose this option if your system requires low latency. 166 Choose this option if your system requires low latency.
170 167
171 config METAG_ATOMICITY_LOCK1 168 config METAG_ATOMICITY_LOCK1
172 depends on SMP 169 depends on SMP
173 bool "lock1" 170 bool "lock1"
174 help 171 help
175 This option uses the LOCK1 instruction for atomicity. This is mainly 172 This option uses the LOCK1 instruction for atomicity. This is mainly
176 provided as a debugging aid if the lnkget/lnkset atomicity primitive 173 provided as a debugging aid if the lnkget/lnkset atomicity primitive
177 isn't working properly. 174 isn't working properly.
178 175
179 endchoice 176 endchoice
180 177
181 config METAG_FPU 178 config METAG_FPU
182 bool "FPU Support" 179 bool "FPU Support"
183 depends on METAG_META21 180 depends on METAG_META21
184 default y 181 default y
185 help 182 help
186 This option allows processes to use FPU hardware available with this 183 This option allows processes to use FPU hardware available with this
187 CPU. If this option is not enabled FPU registers will not be saved 184 CPU. If this option is not enabled FPU registers will not be saved
188 and restored on context-switch. 185 and restored on context-switch.
189 186
190 If you plan on running programs which are compiled to use hard floats 187 If you plan on running programs which are compiled to use hard floats
191 say Y here. 188 say Y here.
192 189
193 config METAG_DSP 190 config METAG_DSP
194 bool "DSP Support" 191 bool "DSP Support"
195 help 192 help
196 This option allows processes to use DSP hardware available 193 This option allows processes to use DSP hardware available
197 with this CPU. If this option is not enabled DSP registers 194 with this CPU. If this option is not enabled DSP registers
198 will not be saved and restored on context-switch. 195 will not be saved and restored on context-switch.
199 196
200 If you plan on running DSP programs say Y here. 197 If you plan on running DSP programs say Y here.
201 198
202 config METAG_PERFCOUNTER_IRQS 199 config METAG_PERFCOUNTER_IRQS
203 bool "PerfCounters interrupt support" 200 bool "PerfCounters interrupt support"
204 depends on METAG_META21 201 depends on METAG_META21
205 help 202 help
206 This option enables using interrupts to collect information from 203 This option enables using interrupts to collect information from
207 Performance Counters. This option is supported in new META21 204 Performance Counters. This option is supported in new META21
208 (starting from HTP265). 205 (starting from HTP265).
209 206
210 When disabled, Performance Counters information will be collected 207 When disabled, Performance Counters information will be collected
211 based on Timer Interrupt. 208 based on Timer Interrupt.
212 209
213 config HW_PERF_EVENTS 210 config HW_PERF_EVENTS
214 def_bool METAG_PERFCOUNTER_IRQS && PERF_EVENTS 211 def_bool METAG_PERFCOUNTER_IRQS && PERF_EVENTS
215 212
216 config METAG_DA 213 config METAG_DA
217 bool "DA support" 214 bool "DA support"
218 help 215 help
219 Say Y if you plan to use a DA debug adapter with Linux. The presence 216 Say Y if you plan to use a DA debug adapter with Linux. The presence
220 of the DA will be detected automatically at boot, so it is safe to say 217 of the DA will be detected automatically at boot, so it is safe to say
221 Y to this option even when booting without a DA. 218 Y to this option even when booting without a DA.
222 219
223 This enables support for services provided by DA JTAG debug adapters, 220 This enables support for services provided by DA JTAG debug adapters,
224 such as: 221 such as:
225 - communication over DA channels (such as the console driver). 222 - communication over DA channels (such as the console driver).
226 - use of the DA filesystem. 223 - use of the DA filesystem.
227 224
228 menu "Boot options" 225 menu "Boot options"
229 226
230 config METAG_BUILTIN_DTB 227 config METAG_BUILTIN_DTB
231 bool "Embed DTB in kernel image" 228 bool "Embed DTB in kernel image"
232 default y 229 default y
233 help 230 help
234 Embeds a device tree binary in the kernel image. 231 Embeds a device tree binary in the kernel image.
235 232
236 config METAG_BUILTIN_DTB_NAME 233 config METAG_BUILTIN_DTB_NAME
237 string "Built in DTB" 234 string "Built in DTB"
238 depends on METAG_BUILTIN_DTB 235 depends on METAG_BUILTIN_DTB
239 help 236 help
240 Set the name of the DTB to embed (leave blank to pick one 237 Set the name of the DTB to embed (leave blank to pick one
241 automatically based on kernel configuration). 238 automatically based on kernel configuration).
242 239
243 config CMDLINE_BOOL 240 config CMDLINE_BOOL
244 bool "Default bootloader kernel arguments" 241 bool "Default bootloader kernel arguments"
245 242
246 config CMDLINE 243 config CMDLINE
247 string "Kernel command line" 244 string "Kernel command line"
248 depends on CMDLINE_BOOL 245 depends on CMDLINE_BOOL
249 help 246 help
250 On some architectures there is currently no way for the boot loader 247 On some architectures there is currently no way for the boot loader
251 to pass arguments to the kernel. For these architectures, you should 248 to pass arguments to the kernel. For these architectures, you should
252 supply some command-line options at build time by entering them 249 supply some command-line options at build time by entering them
253 here. 250 here.
254 251
255 config CMDLINE_FORCE 252 config CMDLINE_FORCE
256 bool "Force default kernel command string" 253 bool "Force default kernel command string"
257 depends on CMDLINE_BOOL 254 depends on CMDLINE_BOOL
258 help 255 help
259 Set this to have arguments from the default kernel command string 256 Set this to have arguments from the default kernel command string
260 override those passed by the boot loader. 257 override those passed by the boot loader.
261 258
262 endmenu 259 endmenu
263 260
264 source "kernel/Kconfig.preempt" 261 source "kernel/Kconfig.preempt"
265 262
266 source kernel/Kconfig.hz 263 source kernel/Kconfig.hz
267 264
268 endmenu 265 endmenu
269 266
270 menu "Power management options" 267 menu "Power management options"
271 268
272 source kernel/power/Kconfig 269 source kernel/power/Kconfig
273 270
274 endmenu 271 endmenu
275 272
276 menu "Executable file formats" 273 menu "Executable file formats"
277 274
278 source "fs/Kconfig.binfmt" 275 source "fs/Kconfig.binfmt"
279 276
280 endmenu 277 endmenu
281 278
282 source "net/Kconfig" 279 source "net/Kconfig"
283 280
284 source "drivers/Kconfig" 281 source "drivers/Kconfig"
285 282
286 source "fs/Kconfig" 283 source "fs/Kconfig"
287 284
288 source "arch/metag/Kconfig.debug" 285 source "arch/metag/Kconfig.debug"
289 286
290 source "security/Kconfig" 287 source "security/Kconfig"
291 288
292 source "crypto/Kconfig" 289 source "crypto/Kconfig"
293 290
294 source "lib/Kconfig" 291 source "lib/Kconfig"
crypto/asymmetric_keys/x509_cert_parser.c
1 /* X.509 certificate parser 1 /* X.509 certificate parser
2 * 2 *
3 * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved. 3 * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com) 4 * Written by David Howells (dhowells@redhat.com)
5 * 5 *
6 * This program is free software; you can redistribute it and/or 6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence 7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version 8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version. 9 * 2 of the Licence, or (at your option) any later version.
10 */ 10 */
11 11
12 #define pr_fmt(fmt) "X.509: "fmt 12 #define pr_fmt(fmt) "X.509: "fmt
13 #include <linux/kernel.h> 13 #include <linux/kernel.h>
14 #include <linux/slab.h> 14 #include <linux/slab.h>
15 #include <linux/err.h> 15 #include <linux/err.h>
16 #include <linux/oid_registry.h> 16 #include <linux/oid_registry.h>
17 #include "public_key.h" 17 #include "public_key.h"
18 #include "x509_parser.h" 18 #include "x509_parser.h"
19 #include "x509-asn1.h" 19 #include "x509-asn1.h"
20 #include "x509_rsakey-asn1.h" 20 #include "x509_rsakey-asn1.h"
21 21
22 struct x509_parse_context { 22 struct x509_parse_context {
23 struct x509_certificate *cert; /* Certificate being constructed */ 23 struct x509_certificate *cert; /* Certificate being constructed */
24 unsigned long data; /* Start of data */ 24 unsigned long data; /* Start of data */
25 const void *cert_start; /* Start of cert content */ 25 const void *cert_start; /* Start of cert content */
26 const void *key; /* Key data */ 26 const void *key; /* Key data */
27 size_t key_size; /* Size of key data */ 27 size_t key_size; /* Size of key data */
28 enum OID last_oid; /* Last OID encountered */ 28 enum OID last_oid; /* Last OID encountered */
29 enum OID algo_oid; /* Algorithm OID */ 29 enum OID algo_oid; /* Algorithm OID */
30 unsigned char nr_mpi; /* Number of MPIs stored */ 30 unsigned char nr_mpi; /* Number of MPIs stored */
31 u8 o_size; /* Size of organizationName (O) */ 31 u8 o_size; /* Size of organizationName (O) */
32 u8 cn_size; /* Size of commonName (CN) */ 32 u8 cn_size; /* Size of commonName (CN) */
33 u8 email_size; /* Size of emailAddress */ 33 u8 email_size; /* Size of emailAddress */
34 u16 o_offset; /* Offset of organizationName (O) */ 34 u16 o_offset; /* Offset of organizationName (O) */
35 u16 cn_offset; /* Offset of commonName (CN) */ 35 u16 cn_offset; /* Offset of commonName (CN) */
36 u16 email_offset; /* Offset of emailAddress */ 36 u16 email_offset; /* Offset of emailAddress */
37 }; 37 };
38 38
39 /* 39 /*
40 * Free an X.509 certificate 40 * Free an X.509 certificate
41 */ 41 */
42 void x509_free_certificate(struct x509_certificate *cert) 42 void x509_free_certificate(struct x509_certificate *cert)
43 { 43 {
44 if (cert) { 44 if (cert) {
45 public_key_destroy(cert->pub); 45 public_key_destroy(cert->pub);
46 kfree(cert->issuer); 46 kfree(cert->issuer);
47 kfree(cert->subject); 47 kfree(cert->subject);
48 kfree(cert->fingerprint); 48 kfree(cert->fingerprint);
49 kfree(cert->authority); 49 kfree(cert->authority);
50 kfree(cert); 50 kfree(cert);
51 } 51 }
52 } 52 }
53 53
54 /* 54 /*
55 * Parse an X.509 certificate 55 * Parse an X.509 certificate
56 */ 56 */
57 struct x509_certificate *x509_cert_parse(const void *data, size_t datalen) 57 struct x509_certificate *x509_cert_parse(const void *data, size_t datalen)
58 { 58 {
59 struct x509_certificate *cert; 59 struct x509_certificate *cert;
60 struct x509_parse_context *ctx; 60 struct x509_parse_context *ctx;
61 long ret; 61 long ret;
62 62
63 ret = -ENOMEM; 63 ret = -ENOMEM;
64 cert = kzalloc(sizeof(struct x509_certificate), GFP_KERNEL); 64 cert = kzalloc(sizeof(struct x509_certificate), GFP_KERNEL);
65 if (!cert) 65 if (!cert)
66 goto error_no_cert; 66 goto error_no_cert;
67 cert->pub = kzalloc(sizeof(struct public_key), GFP_KERNEL); 67 cert->pub = kzalloc(sizeof(struct public_key), GFP_KERNEL);
68 if (!cert->pub) 68 if (!cert->pub)
69 goto error_no_ctx; 69 goto error_no_ctx;
70 ctx = kzalloc(sizeof(struct x509_parse_context), GFP_KERNEL); 70 ctx = kzalloc(sizeof(struct x509_parse_context), GFP_KERNEL);
71 if (!ctx) 71 if (!ctx)
72 goto error_no_ctx; 72 goto error_no_ctx;
73 73
74 ctx->cert = cert; 74 ctx->cert = cert;
75 ctx->data = (unsigned long)data; 75 ctx->data = (unsigned long)data;
76 76
77 /* Attempt to decode the certificate */ 77 /* Attempt to decode the certificate */
78 ret = asn1_ber_decoder(&x509_decoder, ctx, data, datalen); 78 ret = asn1_ber_decoder(&x509_decoder, ctx, data, datalen);
79 if (ret < 0) 79 if (ret < 0)
80 goto error_decode; 80 goto error_decode;
81 81
82 /* Decode the public key */ 82 /* Decode the public key */
83 ret = asn1_ber_decoder(&x509_rsakey_decoder, ctx, 83 ret = asn1_ber_decoder(&x509_rsakey_decoder, ctx,
84 ctx->key, ctx->key_size); 84 ctx->key, ctx->key_size);
85 if (ret < 0) 85 if (ret < 0)
86 goto error_decode; 86 goto error_decode;
87 87
88 kfree(ctx); 88 kfree(ctx);
89 return cert; 89 return cert;
90 90
91 error_decode: 91 error_decode:
92 kfree(ctx); 92 kfree(ctx);
93 error_no_ctx: 93 error_no_ctx:
94 x509_free_certificate(cert); 94 x509_free_certificate(cert);
95 error_no_cert: 95 error_no_cert:
96 return ERR_PTR(ret); 96 return ERR_PTR(ret);
97 } 97 }
98 98
99 /* 99 /*
100 * Note an OID when we find one for later processing when we know how 100 * Note an OID when we find one for later processing when we know how
101 * to interpret it. 101 * to interpret it.
102 */ 102 */
103 int x509_note_OID(void *context, size_t hdrlen, 103 int x509_note_OID(void *context, size_t hdrlen,
104 unsigned char tag, 104 unsigned char tag,
105 const void *value, size_t vlen) 105 const void *value, size_t vlen)
106 { 106 {
107 struct x509_parse_context *ctx = context; 107 struct x509_parse_context *ctx = context;
108 108
109 ctx->last_oid = look_up_OID(value, vlen); 109 ctx->last_oid = look_up_OID(value, vlen);
110 if (ctx->last_oid == OID__NR) { 110 if (ctx->last_oid == OID__NR) {
111 char buffer[50]; 111 char buffer[50];
112 sprint_oid(value, vlen, buffer, sizeof(buffer)); 112 sprint_oid(value, vlen, buffer, sizeof(buffer));
113 pr_debug("Unknown OID: [%lu] %s\n", 113 pr_debug("Unknown OID: [%lu] %s\n",
114 (unsigned long)value - ctx->data, buffer); 114 (unsigned long)value - ctx->data, buffer);
115 } 115 }
116 return 0; 116 return 0;
117 } 117 }
118 118
119 /* 119 /*
120 * Save the position of the TBS data so that we can check the signature over it 120 * Save the position of the TBS data so that we can check the signature over it
121 * later. 121 * later.
122 */ 122 */
123 int x509_note_tbs_certificate(void *context, size_t hdrlen, 123 int x509_note_tbs_certificate(void *context, size_t hdrlen,
124 unsigned char tag, 124 unsigned char tag,
125 const void *value, size_t vlen) 125 const void *value, size_t vlen)
126 { 126 {
127 struct x509_parse_context *ctx = context; 127 struct x509_parse_context *ctx = context;
128 128
129 pr_debug("x509_note_tbs_certificate(,%zu,%02x,%ld,%zu)!\n", 129 pr_debug("x509_note_tbs_certificate(,%zu,%02x,%ld,%zu)!\n",
130 hdrlen, tag, (unsigned long)value - ctx->data, vlen); 130 hdrlen, tag, (unsigned long)value - ctx->data, vlen);
131 131
132 ctx->cert->tbs = value - hdrlen; 132 ctx->cert->tbs = value - hdrlen;
133 ctx->cert->tbs_size = vlen + hdrlen; 133 ctx->cert->tbs_size = vlen + hdrlen;
134 return 0; 134 return 0;
135 } 135 }
136 136
137 /* 137 /*
138 * Record the public key algorithm 138 * Record the public key algorithm
139 */ 139 */
140 int x509_note_pkey_algo(void *context, size_t hdrlen, 140 int x509_note_pkey_algo(void *context, size_t hdrlen,
141 unsigned char tag, 141 unsigned char tag,
142 const void *value, size_t vlen) 142 const void *value, size_t vlen)
143 { 143 {
144 struct x509_parse_context *ctx = context; 144 struct x509_parse_context *ctx = context;
145 145
146 pr_debug("PubKey Algo: %u\n", ctx->last_oid); 146 pr_debug("PubKey Algo: %u\n", ctx->last_oid);
147 147
148 switch (ctx->last_oid) { 148 switch (ctx->last_oid) {
149 case OID_md2WithRSAEncryption: 149 case OID_md2WithRSAEncryption:
150 case OID_md3WithRSAEncryption: 150 case OID_md3WithRSAEncryption:
151 default: 151 default:
152 return -ENOPKG; /* Unsupported combination */ 152 return -ENOPKG; /* Unsupported combination */
153 153
154 case OID_md4WithRSAEncryption: 154 case OID_md4WithRSAEncryption:
155 ctx->cert->sig_hash_algo = PKEY_HASH_MD5; 155 ctx->cert->sig_hash_algo = PKEY_HASH_MD5;
156 ctx->cert->sig_pkey_algo = PKEY_ALGO_RSA; 156 ctx->cert->sig_pkey_algo = PKEY_ALGO_RSA;
157 break; 157 break;
158 158
159 case OID_sha1WithRSAEncryption: 159 case OID_sha1WithRSAEncryption:
160 ctx->cert->sig_hash_algo = PKEY_HASH_SHA1; 160 ctx->cert->sig_hash_algo = PKEY_HASH_SHA1;
161 ctx->cert->sig_pkey_algo = PKEY_ALGO_RSA; 161 ctx->cert->sig_pkey_algo = PKEY_ALGO_RSA;
162 break; 162 break;
163 163
164 case OID_sha256WithRSAEncryption: 164 case OID_sha256WithRSAEncryption:
165 ctx->cert->sig_hash_algo = PKEY_HASH_SHA256; 165 ctx->cert->sig_hash_algo = PKEY_HASH_SHA256;
166 ctx->cert->sig_pkey_algo = PKEY_ALGO_RSA; 166 ctx->cert->sig_pkey_algo = PKEY_ALGO_RSA;
167 break; 167 break;
168 168
169 case OID_sha384WithRSAEncryption: 169 case OID_sha384WithRSAEncryption:
170 ctx->cert->sig_hash_algo = PKEY_HASH_SHA384; 170 ctx->cert->sig_hash_algo = PKEY_HASH_SHA384;
171 ctx->cert->sig_pkey_algo = PKEY_ALGO_RSA; 171 ctx->cert->sig_pkey_algo = PKEY_ALGO_RSA;
172 break; 172 break;
173 173
174 case OID_sha512WithRSAEncryption: 174 case OID_sha512WithRSAEncryption:
175 ctx->cert->sig_hash_algo = PKEY_HASH_SHA512; 175 ctx->cert->sig_hash_algo = PKEY_HASH_SHA512;
176 ctx->cert->sig_pkey_algo = PKEY_ALGO_RSA; 176 ctx->cert->sig_pkey_algo = PKEY_ALGO_RSA;
177 break; 177 break;
178 178
179 case OID_sha224WithRSAEncryption: 179 case OID_sha224WithRSAEncryption:
180 ctx->cert->sig_hash_algo = PKEY_HASH_SHA224; 180 ctx->cert->sig_hash_algo = PKEY_HASH_SHA224;
181 ctx->cert->sig_pkey_algo = PKEY_ALGO_RSA; 181 ctx->cert->sig_pkey_algo = PKEY_ALGO_RSA;
182 break; 182 break;
183 } 183 }
184 184
185 ctx->algo_oid = ctx->last_oid; 185 ctx->algo_oid = ctx->last_oid;
186 return 0; 186 return 0;
187 } 187 }
188 188
189 /* 189 /*
190 * Note the whereabouts and type of the signature. 190 * Note the whereabouts and type of the signature.
191 */ 191 */
192 int x509_note_signature(void *context, size_t hdrlen, 192 int x509_note_signature(void *context, size_t hdrlen,
193 unsigned char tag, 193 unsigned char tag,
194 const void *value, size_t vlen) 194 const void *value, size_t vlen)
195 { 195 {
196 struct x509_parse_context *ctx = context; 196 struct x509_parse_context *ctx = context;
197 197
198 pr_debug("Signature type: %u size %zu\n", ctx->last_oid, vlen); 198 pr_debug("Signature type: %u size %zu\n", ctx->last_oid, vlen);
199 199
200 if (ctx->last_oid != ctx->algo_oid) { 200 if (ctx->last_oid != ctx->algo_oid) {
201 pr_warn("Got cert with pkey (%u) and sig (%u) algorithm OIDs\n", 201 pr_warn("Got cert with pkey (%u) and sig (%u) algorithm OIDs\n",
202 ctx->algo_oid, ctx->last_oid); 202 ctx->algo_oid, ctx->last_oid);
203 return -EINVAL; 203 return -EINVAL;
204 } 204 }
205 205
206 ctx->cert->sig = value; 206 ctx->cert->sig = value;
207 ctx->cert->sig_size = vlen; 207 ctx->cert->sig_size = vlen;
208 return 0; 208 return 0;
209 } 209 }
210 210
211 /* 211 /*
212 * Note some of the name segments from which we'll fabricate a name. 212 * Note some of the name segments from which we'll fabricate a name.
213 */ 213 */
214 int x509_extract_name_segment(void *context, size_t hdrlen, 214 int x509_extract_name_segment(void *context, size_t hdrlen,
215 unsigned char tag, 215 unsigned char tag,
216 const void *value, size_t vlen) 216 const void *value, size_t vlen)
217 { 217 {
218 struct x509_parse_context *ctx = context; 218 struct x509_parse_context *ctx = context;
219 219
220 switch (ctx->last_oid) { 220 switch (ctx->last_oid) {
221 case OID_commonName: 221 case OID_commonName:
222 ctx->cn_size = vlen; 222 ctx->cn_size = vlen;
223 ctx->cn_offset = (unsigned long)value - ctx->data; 223 ctx->cn_offset = (unsigned long)value - ctx->data;
224 break; 224 break;
225 case OID_organizationName: 225 case OID_organizationName:
226 ctx->o_size = vlen; 226 ctx->o_size = vlen;
227 ctx->o_offset = (unsigned long)value - ctx->data; 227 ctx->o_offset = (unsigned long)value - ctx->data;
228 break; 228 break;
229 case OID_email_address: 229 case OID_email_address:
230 ctx->email_size = vlen; 230 ctx->email_size = vlen;
231 ctx->email_offset = (unsigned long)value - ctx->data; 231 ctx->email_offset = (unsigned long)value - ctx->data;
232 break; 232 break;
233 default: 233 default:
234 break; 234 break;
235 } 235 }
236 236
237 return 0; 237 return 0;
238 } 238 }
239 239
240 /* 240 /*
241 * Fabricate and save the issuer and subject names 241 * Fabricate and save the issuer and subject names
242 */ 242 */
243 static int x509_fabricate_name(struct x509_parse_context *ctx, size_t hdrlen, 243 static int x509_fabricate_name(struct x509_parse_context *ctx, size_t hdrlen,
244 unsigned char tag, 244 unsigned char tag,
245 char **_name, size_t vlen) 245 char **_name, size_t vlen)
246 { 246 {
247 const void *name, *data = (const void *)ctx->data; 247 const void *name, *data = (const void *)ctx->data;
248 size_t namesize; 248 size_t namesize;
249 char *buffer; 249 char *buffer;
250 250
251 if (*_name) 251 if (*_name)
252 return -EINVAL; 252 return -EINVAL;
253 253
254 /* Empty name string if no material */ 254 /* Empty name string if no material */
255 if (!ctx->cn_size && !ctx->o_size && !ctx->email_size) { 255 if (!ctx->cn_size && !ctx->o_size && !ctx->email_size) {
256 buffer = kmalloc(1, GFP_KERNEL); 256 buffer = kmalloc(1, GFP_KERNEL);
257 if (!buffer) 257 if (!buffer)
258 return -ENOMEM; 258 return -ENOMEM;
259 buffer[0] = 0; 259 buffer[0] = 0;
260 goto done; 260 goto done;
261 } 261 }
262 262
263 if (ctx->cn_size && ctx->o_size) { 263 if (ctx->cn_size && ctx->o_size) {
264 /* Consider combining O and CN, but use only the CN if it is 264 /* Consider combining O and CN, but use only the CN if it is
265 * prefixed by the O, or a significant portion thereof. 265 * prefixed by the O, or a significant portion thereof.
266 */ 266 */
267 namesize = ctx->cn_size; 267 namesize = ctx->cn_size;
268 name = data + ctx->cn_offset; 268 name = data + ctx->cn_offset;
269 if (ctx->cn_size >= ctx->o_size && 269 if (ctx->cn_size >= ctx->o_size &&
270 memcmp(data + ctx->cn_offset, data + ctx->o_offset, 270 memcmp(data + ctx->cn_offset, data + ctx->o_offset,
271 ctx->o_size) == 0) 271 ctx->o_size) == 0)
272 goto single_component; 272 goto single_component;
273 if (ctx->cn_size >= 7 && 273 if (ctx->cn_size >= 7 &&
274 ctx->o_size >= 7 && 274 ctx->o_size >= 7 &&
275 memcmp(data + ctx->cn_offset, data + ctx->o_offset, 7) == 0) 275 memcmp(data + ctx->cn_offset, data + ctx->o_offset, 7) == 0)
276 goto single_component; 276 goto single_component;
277 277
278 buffer = kmalloc(ctx->o_size + 2 + ctx->cn_size + 1, 278 buffer = kmalloc(ctx->o_size + 2 + ctx->cn_size + 1,
279 GFP_KERNEL); 279 GFP_KERNEL);
280 if (!buffer) 280 if (!buffer)
281 return -ENOMEM; 281 return -ENOMEM;
282 282
283 memcpy(buffer, 283 memcpy(buffer,
284 data + ctx->o_offset, ctx->o_size); 284 data + ctx->o_offset, ctx->o_size);
285 buffer[ctx->o_size + 0] = ':'; 285 buffer[ctx->o_size + 0] = ':';
286 buffer[ctx->o_size + 1] = ' '; 286 buffer[ctx->o_size + 1] = ' ';
287 memcpy(buffer + ctx->o_size + 2, 287 memcpy(buffer + ctx->o_size + 2,
288 data + ctx->cn_offset, ctx->cn_size); 288 data + ctx->cn_offset, ctx->cn_size);
289 buffer[ctx->o_size + 2 + ctx->cn_size] = 0; 289 buffer[ctx->o_size + 2 + ctx->cn_size] = 0;
290 goto done; 290 goto done;
291 291
292 } else if (ctx->cn_size) { 292 } else if (ctx->cn_size) {
293 namesize = ctx->cn_size; 293 namesize = ctx->cn_size;
294 name = data + ctx->cn_offset; 294 name = data + ctx->cn_offset;
295 } else if (ctx->o_size) { 295 } else if (ctx->o_size) {
296 namesize = ctx->o_size; 296 namesize = ctx->o_size;
297 name = data + ctx->o_offset; 297 name = data + ctx->o_offset;
298 } else { 298 } else {
299 namesize = ctx->email_size; 299 namesize = ctx->email_size;
300 name = data + ctx->email_offset; 300 name = data + ctx->email_offset;
301 } 301 }
302 302
303 single_component: 303 single_component:
304 buffer = kmalloc(namesize + 1, GFP_KERNEL); 304 buffer = kmalloc(namesize + 1, GFP_KERNEL);
305 if (!buffer) 305 if (!buffer)
306 return -ENOMEM; 306 return -ENOMEM;
307 memcpy(buffer, name, namesize); 307 memcpy(buffer, name, namesize);
308 buffer[namesize] = 0; 308 buffer[namesize] = 0;
309 309
310 done: 310 done:
311 *_name = buffer; 311 *_name = buffer;
312 ctx->cn_size = 0; 312 ctx->cn_size = 0;
313 ctx->o_size = 0; 313 ctx->o_size = 0;
314 ctx->email_size = 0; 314 ctx->email_size = 0;
315 return 0; 315 return 0;
316 } 316 }
317 317
318 int x509_note_issuer(void *context, size_t hdrlen, 318 int x509_note_issuer(void *context, size_t hdrlen,
319 unsigned char tag, 319 unsigned char tag,
320 const void *value, size_t vlen) 320 const void *value, size_t vlen)
321 { 321 {
322 struct x509_parse_context *ctx = context; 322 struct x509_parse_context *ctx = context;
323 return x509_fabricate_name(ctx, hdrlen, tag, &ctx->cert->issuer, vlen); 323 return x509_fabricate_name(ctx, hdrlen, tag, &ctx->cert->issuer, vlen);
324 } 324 }
325 325
326 int x509_note_subject(void *context, size_t hdrlen, 326 int x509_note_subject(void *context, size_t hdrlen,
327 unsigned char tag, 327 unsigned char tag,
328 const void *value, size_t vlen) 328 const void *value, size_t vlen)
329 { 329 {
330 struct x509_parse_context *ctx = context; 330 struct x509_parse_context *ctx = context;
331 return x509_fabricate_name(ctx, hdrlen, tag, &ctx->cert->subject, vlen); 331 return x509_fabricate_name(ctx, hdrlen, tag, &ctx->cert->subject, vlen);
332 } 332 }
333 333
334 /* 334 /*
335 * Extract the data for the public key algorithm 335 * Extract the data for the public key algorithm
336 */ 336 */
337 int x509_extract_key_data(void *context, size_t hdrlen, 337 int x509_extract_key_data(void *context, size_t hdrlen,
338 unsigned char tag, 338 unsigned char tag,
339 const void *value, size_t vlen) 339 const void *value, size_t vlen)
340 { 340 {
341 struct x509_parse_context *ctx = context; 341 struct x509_parse_context *ctx = context;
342 342
343 if (ctx->last_oid != OID_rsaEncryption) 343 if (ctx->last_oid != OID_rsaEncryption)
344 return -ENOPKG; 344 return -ENOPKG;
345 345
346 /* There seems to be an extraneous 0 byte on the front of the data */ 346 /* There seems to be an extraneous 0 byte on the front of the data */
347 ctx->cert->pkey_algo = PKEY_ALGO_RSA; 347 ctx->cert->pkey_algo = PKEY_ALGO_RSA;
348 ctx->key = value + 1; 348 ctx->key = value + 1;
349 ctx->key_size = vlen - 1; 349 ctx->key_size = vlen - 1;
350 return 0; 350 return 0;
351 } 351 }
352 352
353 /* 353 /*
354 * Extract a RSA public key value 354 * Extract a RSA public key value
355 */ 355 */
356 int rsa_extract_mpi(void *context, size_t hdrlen, 356 int rsa_extract_mpi(void *context, size_t hdrlen,
357 unsigned char tag, 357 unsigned char tag,
358 const void *value, size_t vlen) 358 const void *value, size_t vlen)
359 { 359 {
360 struct x509_parse_context *ctx = context; 360 struct x509_parse_context *ctx = context;
361 MPI mpi; 361 MPI mpi;
362 362
363 if (ctx->nr_mpi >= ARRAY_SIZE(ctx->cert->pub->mpi)) { 363 if (ctx->nr_mpi >= ARRAY_SIZE(ctx->cert->pub->mpi)) {
364 pr_err("Too many public key MPIs in certificate\n"); 364 pr_err("Too many public key MPIs in certificate\n");
365 return -EBADMSG; 365 return -EBADMSG;
366 } 366 }
367 367
368 mpi = mpi_read_raw_data(value, vlen); 368 mpi = mpi_read_raw_data(value, vlen);
369 if (!mpi) 369 if (!mpi)
370 return -ENOMEM; 370 return -ENOMEM;
371 371
372 ctx->cert->pub->mpi[ctx->nr_mpi++] = mpi; 372 ctx->cert->pub->mpi[ctx->nr_mpi++] = mpi;
373 return 0; 373 return 0;
374 } 374 }
375 375
376 /* The keyIdentifier in AuthorityKeyIdentifier SEQUENCE is tag(CONT,PRIM,0) */
377 #define SEQ_TAG_KEYID (ASN1_CONT << 6)
378
376 /* 379 /*
377 * Process certificate extensions that are used to qualify the certificate. 380 * Process certificate extensions that are used to qualify the certificate.
378 */ 381 */
379 int x509_process_extension(void *context, size_t hdrlen, 382 int x509_process_extension(void *context, size_t hdrlen,
380 unsigned char tag, 383 unsigned char tag,
381 const void *value, size_t vlen) 384 const void *value, size_t vlen)
382 { 385 {
383 struct x509_parse_context *ctx = context; 386 struct x509_parse_context *ctx = context;
384 const unsigned char *v = value; 387 const unsigned char *v = value;
385 char *f; 388 char *f;
386 int i; 389 int i;
387 390
388 pr_debug("Extension: %u\n", ctx->last_oid); 391 pr_debug("Extension: %u\n", ctx->last_oid);
389 392
390 if (ctx->last_oid == OID_subjectKeyIdentifier) { 393 if (ctx->last_oid == OID_subjectKeyIdentifier) {
391 /* Get hold of the key fingerprint */ 394 /* Get hold of the key fingerprint */
392 if (vlen < 3) 395 if (vlen < 3)
393 return -EBADMSG; 396 return -EBADMSG;
394 if (v[0] != ASN1_OTS || v[1] != vlen - 2) 397 if (v[0] != ASN1_OTS || v[1] != vlen - 2)
395 return -EBADMSG; 398 return -EBADMSG;
396 v += 2; 399 v += 2;
397 vlen -= 2; 400 vlen -= 2;
398 401
399 f = kmalloc(vlen * 2 + 1, GFP_KERNEL); 402 f = kmalloc(vlen * 2 + 1, GFP_KERNEL);
400 if (!f) 403 if (!f)
401 return -ENOMEM; 404 return -ENOMEM;
402 for (i = 0; i < vlen; i++) 405 for (i = 0; i < vlen; i++)
403 sprintf(f + i * 2, "%02x", v[i]); 406 sprintf(f + i * 2, "%02x", v[i]);
404 pr_debug("fingerprint %s\n", f); 407 pr_debug("fingerprint %s\n", f);
405 ctx->cert->fingerprint = f; 408 ctx->cert->fingerprint = f;
406 return 0; 409 return 0;
407 } 410 }
408 411
409 if (ctx->last_oid == OID_authorityKeyIdentifier) { 412 if (ctx->last_oid == OID_authorityKeyIdentifier) {
413 size_t key_len;
414
410 /* Get hold of the CA key fingerprint */ 415 /* Get hold of the CA key fingerprint */
411 if (vlen < 5) 416 if (vlen < 5)
412 return -EBADMSG; 417 return -EBADMSG;
413 if (v[0] != (ASN1_SEQ | (ASN1_CONS << 5)) || 418
414 v[1] != vlen - 2 || 419 /* Authority Key Identifier must be a Constructed SEQUENCE */
415 v[2] != (ASN1_CONT << 6) || 420 if (v[0] != (ASN1_SEQ | (ASN1_CONS << 5)))
416 v[3] != vlen - 4)
417 return -EBADMSG; 421 return -EBADMSG;
418 v += 4;
419 vlen -= 4;
420 422
421 f = kmalloc(vlen * 2 + 1, GFP_KERNEL); 423 /* Authority Key Identifier is not indefinite length */
424 if (unlikely(vlen == ASN1_INDEFINITE_LENGTH))
425 return -EBADMSG;
426
427 if (vlen < ASN1_INDEFINITE_LENGTH) {
428 /* Short Form length */
429 if (v[1] != vlen - 2 ||
430 v[2] != SEQ_TAG_KEYID ||
431 v[3] > vlen - 4)
432 return -EBADMSG;
433
434 key_len = v[3];
435 v += 4;
436 } else {
437 /* Long Form length */
438 size_t seq_len = 0;
439 size_t sub = v[1] - ASN1_INDEFINITE_LENGTH;
440
441 if (sub > 2)
442 return -EBADMSG;
443
444 /* calculate the length from subsequent octets */
445 v += 2;
446 for (i = 0; i < sub; i++) {
447 seq_len <<= 8;
448 seq_len |= v[i];
449 }
450
451 if (seq_len != vlen - 2 - sub ||
452 v[sub] != SEQ_TAG_KEYID ||
453 v[sub + 1] > vlen - 4 - sub)
454 return -EBADMSG;
455
456 key_len = v[sub + 1];
457 v += (sub + 2);
458 }
459
460 f = kmalloc(key_len * 2 + 1, GFP_KERNEL);
422 if (!f) 461 if (!f)
423 return -ENOMEM; 462 return -ENOMEM;
424 for (i = 0; i < vlen; i++) 463 for (i = 0; i < key_len; i++)
425 sprintf(f + i * 2, "%02x", v[i]); 464 sprintf(f + i * 2, "%02x", v[i]);
426 pr_debug("authority %s\n", f); 465 pr_debug("authority %s\n", f);
427 ctx->cert->authority = f; 466 ctx->cert->authority = f;
428 return 0; 467 return 0;
429 } 468 }
430 469
431 return 0; 470 return 0;
432 } 471 }
433 472
434 /* 473 /*
435 * Record a certificate time. 474 * Record a certificate time.
436 */ 475 */
437 static int x509_note_time(struct tm *tm, size_t hdrlen, 476 static int x509_note_time(struct tm *tm, size_t hdrlen,
438 unsigned char tag, 477 unsigned char tag,
439 const unsigned char *value, size_t vlen) 478 const unsigned char *value, size_t vlen)
440 { 479 {
441 const unsigned char *p = value; 480 const unsigned char *p = value;
442 481
443 #define dec2bin(X) ((X) - '0') 482 #define dec2bin(X) ((X) - '0')
444 #define DD2bin(P) ({ unsigned x = dec2bin(P[0]) * 10 + dec2bin(P[1]); P += 2; x; }) 483 #define DD2bin(P) ({ unsigned x = dec2bin(P[0]) * 10 + dec2bin(P[1]); P += 2; x; })
445 484
446 if (tag == ASN1_UNITIM) { 485 if (tag == ASN1_UNITIM) {
447 /* UTCTime: YYMMDDHHMMSSZ */ 486 /* UTCTime: YYMMDDHHMMSSZ */
448 if (vlen != 13) 487 if (vlen != 13)
449 goto unsupported_time; 488 goto unsupported_time;
450 tm->tm_year = DD2bin(p); 489 tm->tm_year = DD2bin(p);
451 if (tm->tm_year >= 50) 490 if (tm->tm_year >= 50)
452 tm->tm_year += 1900; 491 tm->tm_year += 1900;
453 else 492 else
454 tm->tm_year += 2000; 493 tm->tm_year += 2000;
455 } else if (tag == ASN1_GENTIM) { 494 } else if (tag == ASN1_GENTIM) {
456 /* GenTime: YYYYMMDDHHMMSSZ */ 495 /* GenTime: YYYYMMDDHHMMSSZ */
457 if (vlen != 15) 496 if (vlen != 15)
458 goto unsupported_time; 497 goto unsupported_time;
459 tm->tm_year = DD2bin(p) * 100 + DD2bin(p); 498 tm->tm_year = DD2bin(p) * 100 + DD2bin(p);
460 } else { 499 } else {
461 goto unsupported_time; 500 goto unsupported_time;
462 } 501 }
463 502
464 tm->tm_year -= 1900; 503 tm->tm_year -= 1900;
465 tm->tm_mon = DD2bin(p) - 1; 504 tm->tm_mon = DD2bin(p) - 1;
466 tm->tm_mday = DD2bin(p); 505 tm->tm_mday = DD2bin(p);
467 tm->tm_hour = DD2bin(p); 506 tm->tm_hour = DD2bin(p);
468 tm->tm_min = DD2bin(p); 507 tm->tm_min = DD2bin(p);
469 tm->tm_sec = DD2bin(p); 508 tm->tm_sec = DD2bin(p);
470 509
471 if (*p != 'Z') 510 if (*p != 'Z')
472 goto unsupported_time; 511 goto unsupported_time;
473 512
474 return 0; 513 return 0;
475 514
476 unsupported_time: 515 unsupported_time:
477 pr_debug("Got unsupported time [tag %02x]: '%*.*s'\n", 516 pr_debug("Got unsupported time [tag %02x]: '%*.*s'\n",
478 tag, (int)vlen, (int)vlen, value); 517 tag, (int)vlen, (int)vlen, value);
479 return -EBADMSG; 518 return -EBADMSG;
480 } 519 }
481 520
482 int x509_note_not_before(void *context, size_t hdrlen, 521 int x509_note_not_before(void *context, size_t hdrlen,
483 unsigned char tag, 522 unsigned char tag,
484 const void *value, size_t vlen) 523 const void *value, size_t vlen)
485 { 524 {
486 struct x509_parse_context *ctx = context; 525 struct x509_parse_context *ctx = context;
487 return x509_note_time(&ctx->cert->valid_from, hdrlen, tag, value, vlen); 526 return x509_note_time(&ctx->cert->valid_from, hdrlen, tag, value, vlen);
488 } 527 }
489 528
490 int x509_note_not_after(void *context, size_t hdrlen, 529 int x509_note_not_after(void *context, size_t hdrlen,
491 unsigned char tag, 530 unsigned char tag,
492 const void *value, size_t vlen) 531 const void *value, size_t vlen)
493 { 532 {
494 struct x509_parse_context *ctx = context; 533 struct x509_parse_context *ctx = context;
drivers/mtd/chips/gen_probe.c
1 /* 1 /*
2 * Routines common to all CFI-type probes. 2 * Routines common to all CFI-type probes.
3 * (C) 2001-2003 Red Hat, Inc. 3 * (C) 2001-2003 Red Hat, Inc.
4 * GPL'd 4 * GPL'd
5 */ 5 */
6 6
7 #include <linux/kernel.h> 7 #include <linux/kernel.h>
8 #include <linux/slab.h> 8 #include <linux/slab.h>
9 #include <linux/module.h> 9 #include <linux/module.h>
10 #include <linux/mtd/mtd.h> 10 #include <linux/mtd/mtd.h>
11 #include <linux/mtd/map.h> 11 #include <linux/mtd/map.h>
12 #include <linux/mtd/cfi.h> 12 #include <linux/mtd/cfi.h>
13 #include <linux/mtd/gen_probe.h> 13 #include <linux/mtd/gen_probe.h>
14 14
15 static struct mtd_info *check_cmd_set(struct map_info *, int); 15 static struct mtd_info *check_cmd_set(struct map_info *, int);
16 static struct cfi_private *genprobe_ident_chips(struct map_info *map, 16 static struct cfi_private *genprobe_ident_chips(struct map_info *map,
17 struct chip_probe *cp); 17 struct chip_probe *cp);
18 static int genprobe_new_chip(struct map_info *map, struct chip_probe *cp, 18 static int genprobe_new_chip(struct map_info *map, struct chip_probe *cp,
19 struct cfi_private *cfi); 19 struct cfi_private *cfi);
20 20
21 struct mtd_info *mtd_do_chip_probe(struct map_info *map, struct chip_probe *cp) 21 struct mtd_info *mtd_do_chip_probe(struct map_info *map, struct chip_probe *cp)
22 { 22 {
23 struct mtd_info *mtd = NULL; 23 struct mtd_info *mtd = NULL;
24 struct cfi_private *cfi; 24 struct cfi_private *cfi;
25 25
26 /* First probe the map to see if we have CFI stuff there. */ 26 /* First probe the map to see if we have CFI stuff there. */
27 cfi = genprobe_ident_chips(map, cp); 27 cfi = genprobe_ident_chips(map, cp);
28 28
29 if (!cfi) 29 if (!cfi)
30 return NULL; 30 return NULL;
31 31
32 map->fldrv_priv = cfi; 32 map->fldrv_priv = cfi;
33 /* OK we liked it. Now find a driver for the command set it talks */ 33 /* OK we liked it. Now find a driver for the command set it talks */
34 34
35 mtd = check_cmd_set(map, 1); /* First the primary cmdset */ 35 mtd = check_cmd_set(map, 1); /* First the primary cmdset */
36 if (!mtd) 36 if (!mtd)
37 mtd = check_cmd_set(map, 0); /* Then the secondary */ 37 mtd = check_cmd_set(map, 0); /* Then the secondary */
38 38
39 if (mtd) { 39 if (mtd) {
40 if (mtd->size > map->size) { 40 if (mtd->size > map->size) {
41 printk(KERN_WARNING "Reducing visibility of %ldKiB chip to %ldKiB\n", 41 printk(KERN_WARNING "Reducing visibility of %ldKiB chip to %ldKiB\n",
42 (unsigned long)mtd->size >> 10, 42 (unsigned long)mtd->size >> 10,
43 (unsigned long)map->size >> 10); 43 (unsigned long)map->size >> 10);
44 mtd->size = map->size; 44 mtd->size = map->size;
45 } 45 }
46 return mtd; 46 return mtd;
47 } 47 }
48 48
49 printk(KERN_WARNING"gen_probe: No supported Vendor Command Set found\n"); 49 printk(KERN_WARNING"gen_probe: No supported Vendor Command Set found\n");
50 50
51 kfree(cfi->cfiq); 51 kfree(cfi->cfiq);
52 kfree(cfi); 52 kfree(cfi);
53 map->fldrv_priv = NULL; 53 map->fldrv_priv = NULL;
54 return NULL; 54 return NULL;
55 } 55 }
56 EXPORT_SYMBOL(mtd_do_chip_probe); 56 EXPORT_SYMBOL(mtd_do_chip_probe);
57 57
58 58
59 static struct cfi_private *genprobe_ident_chips(struct map_info *map, struct chip_probe *cp) 59 static struct cfi_private *genprobe_ident_chips(struct map_info *map, struct chip_probe *cp)
60 { 60 {
61 struct cfi_private cfi; 61 struct cfi_private cfi;
62 struct cfi_private *retcfi; 62 struct cfi_private *retcfi;
63 unsigned long *chip_map; 63 unsigned long *chip_map;
64 int i, j, mapsize; 64 int i, j, mapsize;
65 int max_chips; 65 int max_chips;
66 66
67 memset(&cfi, 0, sizeof(cfi)); 67 memset(&cfi, 0, sizeof(cfi));
68 68
69 /* Call the probetype-specific code with all permutations of 69 /* Call the probetype-specific code with all permutations of
70 interleave and device type, etc. */ 70 interleave and device type, etc. */
71 if (!genprobe_new_chip(map, cp, &cfi)) { 71 if (!genprobe_new_chip(map, cp, &cfi)) {
72 /* The probe didn't like it */ 72 /* The probe didn't like it */
73 pr_debug("%s: Found no %s device at location zero\n", 73 pr_debug("%s: Found no %s device at location zero\n",
74 cp->name, map->name); 74 cp->name, map->name);
75 return NULL; 75 return NULL;
76 } 76 }
77 77
78 #if 0 /* Let the CFI probe routine do this sanity check. The Intel and AMD 78 #if 0 /* Let the CFI probe routine do this sanity check. The Intel and AMD
79 probe routines won't ever return a broken CFI structure anyway, 79 probe routines won't ever return a broken CFI structure anyway,
80 because they make them up themselves. 80 because they make them up themselves.
81 */ 81 */
82 if (cfi.cfiq->NumEraseRegions == 0) { 82 if (cfi.cfiq->NumEraseRegions == 0) {
83 printk(KERN_WARNING "Number of erase regions is zero\n"); 83 printk(KERN_WARNING "Number of erase regions is zero\n");
84 kfree(cfi.cfiq); 84 kfree(cfi.cfiq);
85 return NULL; 85 return NULL;
86 } 86 }
87 #endif 87 #endif
88 cfi.chipshift = cfi.cfiq->DevSize; 88 cfi.chipshift = cfi.cfiq->DevSize;
89 89
90 if (cfi_interleave_is_1(&cfi)) { 90 if (cfi_interleave_is_1(&cfi)) {
91 ; 91 ;
92 } else if (cfi_interleave_is_2(&cfi)) { 92 } else if (cfi_interleave_is_2(&cfi)) {
93 cfi.chipshift++; 93 cfi.chipshift++;
94 } else if (cfi_interleave_is_4((&cfi))) { 94 } else if (cfi_interleave_is_4((&cfi))) {
95 cfi.chipshift += 2; 95 cfi.chipshift += 2;
96 } else if (cfi_interleave_is_8(&cfi)) { 96 } else if (cfi_interleave_is_8(&cfi)) {
97 cfi.chipshift += 3; 97 cfi.chipshift += 3;
98 } else { 98 } else {
99 BUG(); 99 BUG();
100 } 100 }
101 101
102 cfi.numchips = 1; 102 cfi.numchips = 1;
103 103
104 /* 104 /*
105 * Allocate memory for bitmap of valid chips. 105 * Allocate memory for bitmap of valid chips.
106 * Align bitmap storage size to full byte. 106 * Align bitmap storage size to full byte.
107 */ 107 */
108 max_chips = map->size >> cfi.chipshift; 108 max_chips = map->size >> cfi.chipshift;
109 if (!max_chips) { 109 if (!max_chips) {
110 printk(KERN_WARNING "NOR chip too large to fit in mapping. Attempting to cope...\n"); 110 printk(KERN_WARNING "NOR chip too large to fit in mapping. Attempting to cope...\n");
111 max_chips = 1; 111 max_chips = 1;
112 } 112 }
113 113
114 mapsize = sizeof(long) * DIV_ROUND_UP(max_chips, BITS_PER_LONG); 114 mapsize = sizeof(long) * DIV_ROUND_UP(max_chips, BITS_PER_LONG);
115 chip_map = kzalloc(mapsize, GFP_KERNEL); 115 chip_map = kzalloc(mapsize, GFP_KERNEL);
116 if (!chip_map) { 116 if (!chip_map) {
117 printk(KERN_WARNING "%s: kmalloc failed for CFI chip map\n", map->name); 117 printk(KERN_WARNING "%s: kmalloc failed for CFI chip map\n", map->name);
118 kfree(cfi.cfiq); 118 kfree(cfi.cfiq);
119 return NULL; 119 return NULL;
120 } 120 }
121 121
122 set_bit(0, chip_map); /* Mark first chip valid */ 122 set_bit(0, chip_map); /* Mark first chip valid */
123 123
124 /* 124 /*
125 * Now probe for other chips, checking sensibly for aliases while 125 * Now probe for other chips, checking sensibly for aliases while
126 * we're at it. The new_chip probe above should have let the first 126 * we're at it. The new_chip probe above should have let the first
127 * chip in read mode. 127 * chip in read mode.
128 */ 128 */
129 129
130 for (i = 1; i < max_chips; i++) { 130 for (i = 1; i < max_chips; i++) {
131 cp->probe_chip(map, i << cfi.chipshift, chip_map, &cfi); 131 cp->probe_chip(map, i << cfi.chipshift, chip_map, &cfi);
132 } 132 }
133 133
134 /* 134 /*
135 * Now allocate the space for the structures we need to return to 135 * Now allocate the space for the structures we need to return to
136 * our caller, and copy the appropriate data into them. 136 * our caller, and copy the appropriate data into them.
137 */ 137 */
138 138
139 retcfi = kmalloc(sizeof(struct cfi_private) + cfi.numchips * sizeof(struct flchip), GFP_KERNEL); 139 retcfi = kmalloc(sizeof(struct cfi_private) + cfi.numchips * sizeof(struct flchip), GFP_KERNEL);
140 140
141 if (!retcfi) { 141 if (!retcfi) {
142 printk(KERN_WARNING "%s: kmalloc failed for CFI private structure\n", map->name); 142 printk(KERN_WARNING "%s: kmalloc failed for CFI private structure\n", map->name);
143 kfree(cfi.cfiq); 143 kfree(cfi.cfiq);
144 kfree(chip_map); 144 kfree(chip_map);
145 return NULL; 145 return NULL;
146 } 146 }
147 147
148 memcpy(retcfi, &cfi, sizeof(cfi)); 148 memcpy(retcfi, &cfi, sizeof(cfi));
149 memset(&retcfi->chips[0], 0, sizeof(struct flchip) * cfi.numchips); 149 memset(&retcfi->chips[0], 0, sizeof(struct flchip) * cfi.numchips);
150 150
151 for (i = 0, j = 0; (j < cfi.numchips) && (i < max_chips); i++) { 151 for (i = 0, j = 0; (j < cfi.numchips) && (i < max_chips); i++) {
152 if(test_bit(i, chip_map)) { 152 if(test_bit(i, chip_map)) {
153 struct flchip *pchip = &retcfi->chips[j++]; 153 struct flchip *pchip = &retcfi->chips[j++];
154 154
155 pchip->start = (i << cfi.chipshift); 155 pchip->start = (i << cfi.chipshift);
156 pchip->state = FL_READY; 156 pchip->state = FL_READY;
157 init_waitqueue_head(&pchip->wq); 157 init_waitqueue_head(&pchip->wq);
158 mutex_init(&pchip->mutex); 158 mutex_init(&pchip->mutex);
159 } 159 }
160 } 160 }
161 161
162 kfree(chip_map); 162 kfree(chip_map);
163 return retcfi; 163 return retcfi;
164 } 164 }
165 165
166 166
167 static int genprobe_new_chip(struct map_info *map, struct chip_probe *cp, 167 static int genprobe_new_chip(struct map_info *map, struct chip_probe *cp,
168 struct cfi_private *cfi) 168 struct cfi_private *cfi)
169 { 169 {
170 int min_chips = (map_bankwidth(map)/4?:1); /* At most 4-bytes wide. */ 170 int min_chips = (map_bankwidth(map)/4?:1); /* At most 4-bytes wide. */
171 int max_chips = map_bankwidth(map); /* And minimum 1 */ 171 int max_chips = map_bankwidth(map); /* And minimum 1 */
172 int nr_chips, type; 172 int nr_chips, type;
173 173
174 for (nr_chips = max_chips; nr_chips >= min_chips; nr_chips >>= 1) { 174 for (nr_chips = max_chips; nr_chips >= min_chips; nr_chips >>= 1) {
175 175
176 if (!cfi_interleave_supported(nr_chips)) 176 if (!cfi_interleave_supported(nr_chips))
177 continue; 177 continue;
178 178
179 cfi->interleave = nr_chips; 179 cfi->interleave = nr_chips;
180 180
181 /* Minimum device size. Don't look for one 8-bit device 181 /* Minimum device size. Don't look for one 8-bit device
182 in a 16-bit bus, etc. */ 182 in a 16-bit bus, etc. */
183 type = map_bankwidth(map) / nr_chips; 183 type = map_bankwidth(map) / nr_chips;
184 184
185 for (; type <= CFI_DEVICETYPE_X32; type<<=1) { 185 for (; type <= CFI_DEVICETYPE_X32; type<<=1) {
186 cfi->device_type = type; 186 cfi->device_type = type;
187 187
188 if (cp->probe_chip(map, 0, NULL, cfi)) 188 if (cp->probe_chip(map, 0, NULL, cfi))
189 return 1; 189 return 1;
190 } 190 }
191 } 191 }
192 return 0; 192 return 0;
193 } 193 }
194 194
195 typedef struct mtd_info *cfi_cmdset_fn_t(struct map_info *, int); 195 typedef struct mtd_info *cfi_cmdset_fn_t(struct map_info *, int);
196 196
197 extern cfi_cmdset_fn_t cfi_cmdset_0001; 197 extern cfi_cmdset_fn_t cfi_cmdset_0001;
198 extern cfi_cmdset_fn_t cfi_cmdset_0002; 198 extern cfi_cmdset_fn_t cfi_cmdset_0002;
199 extern cfi_cmdset_fn_t cfi_cmdset_0020; 199 extern cfi_cmdset_fn_t cfi_cmdset_0020;
200 200
201 static inline struct mtd_info *cfi_cmdset_unknown(struct map_info *map, 201 static inline struct mtd_info *cfi_cmdset_unknown(struct map_info *map,
202 int primary) 202 int primary)
203 { 203 {
204 struct cfi_private *cfi = map->fldrv_priv; 204 struct cfi_private *cfi = map->fldrv_priv;
205 __u16 type = primary?cfi->cfiq->P_ID:cfi->cfiq->A_ID; 205 __u16 type = primary?cfi->cfiq->P_ID:cfi->cfiq->A_ID;
206 #ifdef CONFIG_MODULES 206 #ifdef CONFIG_MODULES
207 char probename[16+sizeof(MODULE_SYMBOL_PREFIX)]; 207 char probename[sizeof(VMLINUX_SYMBOL_STR(cfi_cmdset_%4.4X))];
208 cfi_cmdset_fn_t *probe_function; 208 cfi_cmdset_fn_t *probe_function;
209 209
210 sprintf(probename, MODULE_SYMBOL_PREFIX "cfi_cmdset_%4.4X", type); 210 sprintf(probename, VMLINUX_SYMBOL_STR(cfi_cmdset_%4.4X), type);
211 211
212 probe_function = __symbol_get(probename); 212 probe_function = __symbol_get(probename);
213 if (!probe_function) { 213 if (!probe_function) {
214 request_module(probename + sizeof(MODULE_SYMBOL_PREFIX) - 1); 214 char modname[sizeof("cfi_cmdset_%4.4X")];
215 sprintf(modname, "cfi_cmdset_%4.4X", type);
216 request_module(modname);
215 probe_function = __symbol_get(probename); 217 probe_function = __symbol_get(probename);
216 } 218 }
217 219
218 if (probe_function) { 220 if (probe_function) {
219 struct mtd_info *mtd; 221 struct mtd_info *mtd;
220 222
221 mtd = (*probe_function)(map, primary); 223 mtd = (*probe_function)(map, primary);
222 /* If it was happy, it'll have increased its own use count */ 224 /* If it was happy, it'll have increased its own use count */
223 symbol_put_addr(probe_function); 225 symbol_put_addr(probe_function);
224 return mtd; 226 return mtd;
225 } 227 }
226 #endif 228 #endif
227 printk(KERN_NOTICE "Support for command set %04X not present\n", type); 229 printk(KERN_NOTICE "Support for command set %04X not present\n", type);
228 230
229 return NULL; 231 return NULL;
230 } 232 }
231 233
232 static struct mtd_info *check_cmd_set(struct map_info *map, int primary) 234 static struct mtd_info *check_cmd_set(struct map_info *map, int primary)
233 { 235 {
234 struct cfi_private *cfi = map->fldrv_priv; 236 struct cfi_private *cfi = map->fldrv_priv;
235 __u16 type = primary?cfi->cfiq->P_ID:cfi->cfiq->A_ID; 237 __u16 type = primary?cfi->cfiq->P_ID:cfi->cfiq->A_ID;
236 238
237 if (type == P_ID_NONE || type == P_ID_RESERVED) 239 if (type == P_ID_NONE || type == P_ID_RESERVED)
238 return NULL; 240 return NULL;
239 241
240 switch(type){ 242 switch(type){
241 /* We need these for the !CONFIG_MODULES case, 243 /* We need these for the !CONFIG_MODULES case,
242 because symbol_get() doesn't work there */ 244 because symbol_get() doesn't work there */
243 #ifdef CONFIG_MTD_CFI_INTELEXT 245 #ifdef CONFIG_MTD_CFI_INTELEXT
244 case P_ID_INTEL_EXT: 246 case P_ID_INTEL_EXT:
245 case P_ID_INTEL_STD: 247 case P_ID_INTEL_STD:
246 case P_ID_INTEL_PERFORMANCE: 248 case P_ID_INTEL_PERFORMANCE:
247 return cfi_cmdset_0001(map, primary); 249 return cfi_cmdset_0001(map, primary);
248 #endif 250 #endif
249 #ifdef CONFIG_MTD_CFI_AMDSTD 251 #ifdef CONFIG_MTD_CFI_AMDSTD
250 case P_ID_AMD_STD: 252 case P_ID_AMD_STD:
251 case P_ID_SST_OLD: 253 case P_ID_SST_OLD:
252 case P_ID_WINBOND: 254 case P_ID_WINBOND:
253 return cfi_cmdset_0002(map, primary); 255 return cfi_cmdset_0002(map, primary);
254 #endif 256 #endif
255 #ifdef CONFIG_MTD_CFI_STAA 257 #ifdef CONFIG_MTD_CFI_STAA
256 case P_ID_ST_ADV: 258 case P_ID_ST_ADV:
257 return cfi_cmdset_0020(map, primary); 259 return cfi_cmdset_0020(map, primary);
258 #endif 260 #endif
259 default: 261 default:
260 return cfi_cmdset_unknown(map, primary); 262 return cfi_cmdset_unknown(map, primary);
261 } 263 }
262 } 264 }
263 265
264 MODULE_LICENSE("GPL"); 266 MODULE_LICENSE("GPL");
265 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); 267 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
266 MODULE_DESCRIPTION("Helper routines for flash chip probe code"); 268 MODULE_DESCRIPTION("Helper routines for flash chip probe code");
267 269
include/asm-generic/unistd.h
1 #include <uapi/asm-generic/unistd.h> 1 #include <uapi/asm-generic/unistd.h>
2 #include <linux/export.h>
2 3
3 /* 4 /*
4 * These are required system calls, we should 5 * These are required system calls, we should
5 * invert the logic eventually and let them 6 * invert the logic eventually and let them
6 * be selected by default. 7 * be selected by default.
7 */ 8 */
8 #if __BITS_PER_LONG == 32 9 #if __BITS_PER_LONG == 32
9 #define __ARCH_WANT_STAT64 10 #define __ARCH_WANT_STAT64
10 #define __ARCH_WANT_SYS_LLSEEK 11 #define __ARCH_WANT_SYS_LLSEEK
11 #endif 12 #endif
12 13
include/asm-generic/vmlinux.lds.h
1 /* 1 /*
2 * Helper macros to support writing architecture specific 2 * Helper macros to support writing architecture specific
3 * linker scripts. 3 * linker scripts.
4 * 4 *
5 * A minimal linker scripts has following content: 5 * A minimal linker scripts has following content:
6 * [This is a sample, architectures may have special requiriements] 6 * [This is a sample, architectures may have special requiriements]
7 * 7 *
8 * OUTPUT_FORMAT(...) 8 * OUTPUT_FORMAT(...)
9 * OUTPUT_ARCH(...) 9 * OUTPUT_ARCH(...)
10 * ENTRY(...) 10 * ENTRY(...)
11 * SECTIONS 11 * SECTIONS
12 * { 12 * {
13 * . = START; 13 * . = START;
14 * __init_begin = .; 14 * __init_begin = .;
15 * HEAD_TEXT_SECTION 15 * HEAD_TEXT_SECTION
16 * INIT_TEXT_SECTION(PAGE_SIZE) 16 * INIT_TEXT_SECTION(PAGE_SIZE)
17 * INIT_DATA_SECTION(...) 17 * INIT_DATA_SECTION(...)
18 * PERCPU_SECTION(CACHELINE_SIZE) 18 * PERCPU_SECTION(CACHELINE_SIZE)
19 * __init_end = .; 19 * __init_end = .;
20 * 20 *
21 * _stext = .; 21 * _stext = .;
22 * TEXT_SECTION = 0 22 * TEXT_SECTION = 0
23 * _etext = .; 23 * _etext = .;
24 * 24 *
25 * _sdata = .; 25 * _sdata = .;
26 * RO_DATA_SECTION(PAGE_SIZE) 26 * RO_DATA_SECTION(PAGE_SIZE)
27 * RW_DATA_SECTION(...) 27 * RW_DATA_SECTION(...)
28 * _edata = .; 28 * _edata = .;
29 * 29 *
30 * EXCEPTION_TABLE(...) 30 * EXCEPTION_TABLE(...)
31 * NOTES 31 * NOTES
32 * 32 *
33 * BSS_SECTION(0, 0, 0) 33 * BSS_SECTION(0, 0, 0)
34 * _end = .; 34 * _end = .;
35 * 35 *
36 * STABS_DEBUG 36 * STABS_DEBUG
37 * DWARF_DEBUG 37 * DWARF_DEBUG
38 * 38 *
39 * DISCARDS // must be the last 39 * DISCARDS // must be the last
40 * } 40 * }
41 * 41 *
42 * [__init_begin, __init_end] is the init section that may be freed after init 42 * [__init_begin, __init_end] is the init section that may be freed after init
43 * [_stext, _etext] is the text section 43 * [_stext, _etext] is the text section
44 * [_sdata, _edata] is the data section 44 * [_sdata, _edata] is the data section
45 * 45 *
46 * Some of the included output section have their own set of constants. 46 * Some of the included output section have their own set of constants.
47 * Examples are: [__initramfs_start, __initramfs_end] for initramfs and 47 * Examples are: [__initramfs_start, __initramfs_end] for initramfs and
48 * [__nosave_begin, __nosave_end] for the nosave data 48 * [__nosave_begin, __nosave_end] for the nosave data
49 */ 49 */
50 50
51 #ifndef LOAD_OFFSET 51 #ifndef LOAD_OFFSET
52 #define LOAD_OFFSET 0 52 #define LOAD_OFFSET 0
53 #endif 53 #endif
54 54
55 #ifndef SYMBOL_PREFIX 55 #include <linux/export.h>
56 #define VMLINUX_SYMBOL(sym) sym
57 #else
58 #define PASTE2(x,y) x##y
59 #define PASTE(x,y) PASTE2(x,y)
60 #define VMLINUX_SYMBOL(sym) PASTE(SYMBOL_PREFIX, sym)
61 #endif
62 56
63 /* Align . to a 8 byte boundary equals to maximum function alignment. */ 57 /* Align . to a 8 byte boundary equals to maximum function alignment. */
64 #define ALIGN_FUNCTION() . = ALIGN(8) 58 #define ALIGN_FUNCTION() . = ALIGN(8)
65 59
66 /* 60 /*
67 * Align to a 32 byte boundary equal to the 61 * Align to a 32 byte boundary equal to the
68 * alignment gcc 4.5 uses for a struct 62 * alignment gcc 4.5 uses for a struct
69 */ 63 */
70 #define STRUCT_ALIGNMENT 32 64 #define STRUCT_ALIGNMENT 32
71 #define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT) 65 #define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT)
72 66
73 /* The actual configuration determine if the init/exit sections 67 /* The actual configuration determine if the init/exit sections
74 * are handled as text/data or they can be discarded (which 68 * are handled as text/data or they can be discarded (which
75 * often happens at runtime) 69 * often happens at runtime)
76 */ 70 */
77 #ifdef CONFIG_HOTPLUG 71 #ifdef CONFIG_HOTPLUG
78 #define DEV_KEEP(sec) *(.dev##sec) 72 #define DEV_KEEP(sec) *(.dev##sec)
79 #define DEV_DISCARD(sec) 73 #define DEV_DISCARD(sec)
80 #else 74 #else
81 #define DEV_KEEP(sec) 75 #define DEV_KEEP(sec)
82 #define DEV_DISCARD(sec) *(.dev##sec) 76 #define DEV_DISCARD(sec) *(.dev##sec)
83 #endif 77 #endif
84 78
85 #ifdef CONFIG_HOTPLUG_CPU 79 #ifdef CONFIG_HOTPLUG_CPU
86 #define CPU_KEEP(sec) *(.cpu##sec) 80 #define CPU_KEEP(sec) *(.cpu##sec)
87 #define CPU_DISCARD(sec) 81 #define CPU_DISCARD(sec)
88 #else 82 #else
89 #define CPU_KEEP(sec) 83 #define CPU_KEEP(sec)
90 #define CPU_DISCARD(sec) *(.cpu##sec) 84 #define CPU_DISCARD(sec) *(.cpu##sec)
91 #endif 85 #endif
92 86
93 #if defined(CONFIG_MEMORY_HOTPLUG) 87 #if defined(CONFIG_MEMORY_HOTPLUG)
94 #define MEM_KEEP(sec) *(.mem##sec) 88 #define MEM_KEEP(sec) *(.mem##sec)
95 #define MEM_DISCARD(sec) 89 #define MEM_DISCARD(sec)
96 #else 90 #else
97 #define MEM_KEEP(sec) 91 #define MEM_KEEP(sec)
98 #define MEM_DISCARD(sec) *(.mem##sec) 92 #define MEM_DISCARD(sec) *(.mem##sec)
99 #endif 93 #endif
100 94
101 #ifdef CONFIG_FTRACE_MCOUNT_RECORD 95 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
102 #define MCOUNT_REC() . = ALIGN(8); \ 96 #define MCOUNT_REC() . = ALIGN(8); \
103 VMLINUX_SYMBOL(__start_mcount_loc) = .; \ 97 VMLINUX_SYMBOL(__start_mcount_loc) = .; \
104 *(__mcount_loc) \ 98 *(__mcount_loc) \
105 VMLINUX_SYMBOL(__stop_mcount_loc) = .; 99 VMLINUX_SYMBOL(__stop_mcount_loc) = .;
106 #else 100 #else
107 #define MCOUNT_REC() 101 #define MCOUNT_REC()
108 #endif 102 #endif
109 103
110 #ifdef CONFIG_TRACE_BRANCH_PROFILING 104 #ifdef CONFIG_TRACE_BRANCH_PROFILING
111 #define LIKELY_PROFILE() VMLINUX_SYMBOL(__start_annotated_branch_profile) = .; \ 105 #define LIKELY_PROFILE() VMLINUX_SYMBOL(__start_annotated_branch_profile) = .; \
112 *(_ftrace_annotated_branch) \ 106 *(_ftrace_annotated_branch) \
113 VMLINUX_SYMBOL(__stop_annotated_branch_profile) = .; 107 VMLINUX_SYMBOL(__stop_annotated_branch_profile) = .;
114 #else 108 #else
115 #define LIKELY_PROFILE() 109 #define LIKELY_PROFILE()
116 #endif 110 #endif
117 111
118 #ifdef CONFIG_PROFILE_ALL_BRANCHES 112 #ifdef CONFIG_PROFILE_ALL_BRANCHES
119 #define BRANCH_PROFILE() VMLINUX_SYMBOL(__start_branch_profile) = .; \ 113 #define BRANCH_PROFILE() VMLINUX_SYMBOL(__start_branch_profile) = .; \
120 *(_ftrace_branch) \ 114 *(_ftrace_branch) \
121 VMLINUX_SYMBOL(__stop_branch_profile) = .; 115 VMLINUX_SYMBOL(__stop_branch_profile) = .;
122 #else 116 #else
123 #define BRANCH_PROFILE() 117 #define BRANCH_PROFILE()
124 #endif 118 #endif
125 119
126 #ifdef CONFIG_EVENT_TRACING 120 #ifdef CONFIG_EVENT_TRACING
127 #define FTRACE_EVENTS() . = ALIGN(8); \ 121 #define FTRACE_EVENTS() . = ALIGN(8); \
128 VMLINUX_SYMBOL(__start_ftrace_events) = .; \ 122 VMLINUX_SYMBOL(__start_ftrace_events) = .; \
129 *(_ftrace_events) \ 123 *(_ftrace_events) \
130 VMLINUX_SYMBOL(__stop_ftrace_events) = .; 124 VMLINUX_SYMBOL(__stop_ftrace_events) = .;
131 #else 125 #else
132 #define FTRACE_EVENTS() 126 #define FTRACE_EVENTS()
133 #endif 127 #endif
134 128
135 #ifdef CONFIG_TRACING 129 #ifdef CONFIG_TRACING
136 #define TRACE_PRINTKS() VMLINUX_SYMBOL(__start___trace_bprintk_fmt) = .; \ 130 #define TRACE_PRINTKS() VMLINUX_SYMBOL(__start___trace_bprintk_fmt) = .; \
137 *(__trace_printk_fmt) /* Trace_printk fmt' pointer */ \ 131 *(__trace_printk_fmt) /* Trace_printk fmt' pointer */ \
138 VMLINUX_SYMBOL(__stop___trace_bprintk_fmt) = .; 132 VMLINUX_SYMBOL(__stop___trace_bprintk_fmt) = .;
139 #else 133 #else
140 #define TRACE_PRINTKS() 134 #define TRACE_PRINTKS()
141 #endif 135 #endif
142 136
143 #ifdef CONFIG_FTRACE_SYSCALLS 137 #ifdef CONFIG_FTRACE_SYSCALLS
144 #define TRACE_SYSCALLS() . = ALIGN(8); \ 138 #define TRACE_SYSCALLS() . = ALIGN(8); \
145 VMLINUX_SYMBOL(__start_syscalls_metadata) = .; \ 139 VMLINUX_SYMBOL(__start_syscalls_metadata) = .; \
146 *(__syscalls_metadata) \ 140 *(__syscalls_metadata) \
147 VMLINUX_SYMBOL(__stop_syscalls_metadata) = .; 141 VMLINUX_SYMBOL(__stop_syscalls_metadata) = .;
148 #else 142 #else
149 #define TRACE_SYSCALLS() 143 #define TRACE_SYSCALLS()
150 #endif 144 #endif
151 145
152 #ifdef CONFIG_CLKSRC_OF 146 #ifdef CONFIG_CLKSRC_OF
153 #define CLKSRC_OF_TABLES() . = ALIGN(8); \ 147 #define CLKSRC_OF_TABLES() . = ALIGN(8); \
154 VMLINUX_SYMBOL(__clksrc_of_table) = .; \ 148 VMLINUX_SYMBOL(__clksrc_of_table) = .; \
155 *(__clksrc_of_table) \ 149 *(__clksrc_of_table) \
156 *(__clksrc_of_table_end) 150 *(__clksrc_of_table_end)
157 #else 151 #else
158 #define CLKSRC_OF_TABLES() 152 #define CLKSRC_OF_TABLES()
159 #endif 153 #endif
160 154
161 #ifdef CONFIG_IRQCHIP 155 #ifdef CONFIG_IRQCHIP
162 #define IRQCHIP_OF_MATCH_TABLE() \ 156 #define IRQCHIP_OF_MATCH_TABLE() \
163 . = ALIGN(8); \ 157 . = ALIGN(8); \
164 VMLINUX_SYMBOL(__irqchip_begin) = .; \ 158 VMLINUX_SYMBOL(__irqchip_begin) = .; \
165 *(__irqchip_of_table) \ 159 *(__irqchip_of_table) \
166 *(__irqchip_of_end) 160 *(__irqchip_of_end)
167 #else 161 #else
168 #define IRQCHIP_OF_MATCH_TABLE() 162 #define IRQCHIP_OF_MATCH_TABLE()
169 #endif 163 #endif
170 164
171 #ifdef CONFIG_COMMON_CLK 165 #ifdef CONFIG_COMMON_CLK
172 #define CLK_OF_TABLES() . = ALIGN(8); \ 166 #define CLK_OF_TABLES() . = ALIGN(8); \
173 VMLINUX_SYMBOL(__clk_of_table) = .; \ 167 VMLINUX_SYMBOL(__clk_of_table) = .; \
174 *(__clk_of_table) \ 168 *(__clk_of_table) \
175 *(__clk_of_table_end) 169 *(__clk_of_table_end)
176 #else 170 #else
177 #define CLK_OF_TABLES() 171 #define CLK_OF_TABLES()
178 #endif 172 #endif
179 173
180 #define KERNEL_DTB() \ 174 #define KERNEL_DTB() \
181 STRUCT_ALIGN(); \ 175 STRUCT_ALIGN(); \
182 VMLINUX_SYMBOL(__dtb_start) = .; \ 176 VMLINUX_SYMBOL(__dtb_start) = .; \
183 *(.dtb.init.rodata) \ 177 *(.dtb.init.rodata) \
184 VMLINUX_SYMBOL(__dtb_end) = .; 178 VMLINUX_SYMBOL(__dtb_end) = .;
185 179
186 /* .data section */ 180 /* .data section */
187 #define DATA_DATA \ 181 #define DATA_DATA \
188 *(.data) \ 182 *(.data) \
189 *(.ref.data) \ 183 *(.ref.data) \
190 *(.data..shared_aligned) /* percpu related */ \ 184 *(.data..shared_aligned) /* percpu related */ \
191 DEV_KEEP(init.data) \ 185 DEV_KEEP(init.data) \
192 DEV_KEEP(exit.data) \ 186 DEV_KEEP(exit.data) \
193 CPU_KEEP(init.data) \ 187 CPU_KEEP(init.data) \
194 CPU_KEEP(exit.data) \ 188 CPU_KEEP(exit.data) \
195 MEM_KEEP(init.data) \ 189 MEM_KEEP(init.data) \
196 MEM_KEEP(exit.data) \ 190 MEM_KEEP(exit.data) \
197 *(.data.unlikely) \ 191 *(.data.unlikely) \
198 STRUCT_ALIGN(); \ 192 STRUCT_ALIGN(); \
199 *(__tracepoints) \ 193 *(__tracepoints) \
200 /* implement dynamic printk debug */ \ 194 /* implement dynamic printk debug */ \
201 . = ALIGN(8); \ 195 . = ALIGN(8); \
202 VMLINUX_SYMBOL(__start___jump_table) = .; \ 196 VMLINUX_SYMBOL(__start___jump_table) = .; \
203 *(__jump_table) \ 197 *(__jump_table) \
204 VMLINUX_SYMBOL(__stop___jump_table) = .; \ 198 VMLINUX_SYMBOL(__stop___jump_table) = .; \
205 . = ALIGN(8); \ 199 . = ALIGN(8); \
206 VMLINUX_SYMBOL(__start___verbose) = .; \ 200 VMLINUX_SYMBOL(__start___verbose) = .; \
207 *(__verbose) \ 201 *(__verbose) \
208 VMLINUX_SYMBOL(__stop___verbose) = .; \ 202 VMLINUX_SYMBOL(__stop___verbose) = .; \
209 LIKELY_PROFILE() \ 203 LIKELY_PROFILE() \
210 BRANCH_PROFILE() \ 204 BRANCH_PROFILE() \
211 TRACE_PRINTKS() 205 TRACE_PRINTKS()
212 206
213 /* 207 /*
214 * Data section helpers 208 * Data section helpers
215 */ 209 */
216 #define NOSAVE_DATA \ 210 #define NOSAVE_DATA \
217 . = ALIGN(PAGE_SIZE); \ 211 . = ALIGN(PAGE_SIZE); \
218 VMLINUX_SYMBOL(__nosave_begin) = .; \ 212 VMLINUX_SYMBOL(__nosave_begin) = .; \
219 *(.data..nosave) \ 213 *(.data..nosave) \
220 . = ALIGN(PAGE_SIZE); \ 214 . = ALIGN(PAGE_SIZE); \
221 VMLINUX_SYMBOL(__nosave_end) = .; 215 VMLINUX_SYMBOL(__nosave_end) = .;
222 216
223 #define PAGE_ALIGNED_DATA(page_align) \ 217 #define PAGE_ALIGNED_DATA(page_align) \
224 . = ALIGN(page_align); \ 218 . = ALIGN(page_align); \
225 *(.data..page_aligned) 219 *(.data..page_aligned)
226 220
227 #define READ_MOSTLY_DATA(align) \ 221 #define READ_MOSTLY_DATA(align) \
228 . = ALIGN(align); \ 222 . = ALIGN(align); \
229 *(.data..read_mostly) \ 223 *(.data..read_mostly) \
230 . = ALIGN(align); 224 . = ALIGN(align);
231 225
232 #define CACHELINE_ALIGNED_DATA(align) \ 226 #define CACHELINE_ALIGNED_DATA(align) \
233 . = ALIGN(align); \ 227 . = ALIGN(align); \
234 *(.data..cacheline_aligned) 228 *(.data..cacheline_aligned)
235 229
236 #define INIT_TASK_DATA(align) \ 230 #define INIT_TASK_DATA(align) \
237 . = ALIGN(align); \ 231 . = ALIGN(align); \
238 *(.data..init_task) 232 *(.data..init_task)
239 233
240 /* 234 /*
241 * Read only Data 235 * Read only Data
242 */ 236 */
243 #define RO_DATA_SECTION(align) \ 237 #define RO_DATA_SECTION(align) \
244 . = ALIGN((align)); \ 238 . = ALIGN((align)); \
245 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \ 239 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
246 VMLINUX_SYMBOL(__start_rodata) = .; \ 240 VMLINUX_SYMBOL(__start_rodata) = .; \
247 *(.rodata) *(.rodata.*) \ 241 *(.rodata) *(.rodata.*) \
248 *(__vermagic) /* Kernel version magic */ \ 242 *(__vermagic) /* Kernel version magic */ \
249 . = ALIGN(8); \ 243 . = ALIGN(8); \
250 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \ 244 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
251 *(__tracepoints_ptrs) /* Tracepoints: pointer array */\ 245 *(__tracepoints_ptrs) /* Tracepoints: pointer array */\
252 VMLINUX_SYMBOL(__stop___tracepoints_ptrs) = .; \ 246 VMLINUX_SYMBOL(__stop___tracepoints_ptrs) = .; \
253 *(__tracepoints_strings)/* Tracepoints: strings */ \ 247 *(__tracepoints_strings)/* Tracepoints: strings */ \
254 } \ 248 } \
255 \ 249 \
256 .rodata1 : AT(ADDR(.rodata1) - LOAD_OFFSET) { \ 250 .rodata1 : AT(ADDR(.rodata1) - LOAD_OFFSET) { \
257 *(.rodata1) \ 251 *(.rodata1) \
258 } \ 252 } \
259 \ 253 \
260 BUG_TABLE \ 254 BUG_TABLE \
261 \ 255 \
262 /* PCI quirks */ \ 256 /* PCI quirks */ \
263 .pci_fixup : AT(ADDR(.pci_fixup) - LOAD_OFFSET) { \ 257 .pci_fixup : AT(ADDR(.pci_fixup) - LOAD_OFFSET) { \
264 VMLINUX_SYMBOL(__start_pci_fixups_early) = .; \ 258 VMLINUX_SYMBOL(__start_pci_fixups_early) = .; \
265 *(.pci_fixup_early) \ 259 *(.pci_fixup_early) \
266 VMLINUX_SYMBOL(__end_pci_fixups_early) = .; \ 260 VMLINUX_SYMBOL(__end_pci_fixups_early) = .; \
267 VMLINUX_SYMBOL(__start_pci_fixups_header) = .; \ 261 VMLINUX_SYMBOL(__start_pci_fixups_header) = .; \
268 *(.pci_fixup_header) \ 262 *(.pci_fixup_header) \
269 VMLINUX_SYMBOL(__end_pci_fixups_header) = .; \ 263 VMLINUX_SYMBOL(__end_pci_fixups_header) = .; \
270 VMLINUX_SYMBOL(__start_pci_fixups_final) = .; \ 264 VMLINUX_SYMBOL(__start_pci_fixups_final) = .; \
271 *(.pci_fixup_final) \ 265 *(.pci_fixup_final) \
272 VMLINUX_SYMBOL(__end_pci_fixups_final) = .; \ 266 VMLINUX_SYMBOL(__end_pci_fixups_final) = .; \
273 VMLINUX_SYMBOL(__start_pci_fixups_enable) = .; \ 267 VMLINUX_SYMBOL(__start_pci_fixups_enable) = .; \
274 *(.pci_fixup_enable) \ 268 *(.pci_fixup_enable) \
275 VMLINUX_SYMBOL(__end_pci_fixups_enable) = .; \ 269 VMLINUX_SYMBOL(__end_pci_fixups_enable) = .; \
276 VMLINUX_SYMBOL(__start_pci_fixups_resume) = .; \ 270 VMLINUX_SYMBOL(__start_pci_fixups_resume) = .; \
277 *(.pci_fixup_resume) \ 271 *(.pci_fixup_resume) \
278 VMLINUX_SYMBOL(__end_pci_fixups_resume) = .; \ 272 VMLINUX_SYMBOL(__end_pci_fixups_resume) = .; \
279 VMLINUX_SYMBOL(__start_pci_fixups_resume_early) = .; \ 273 VMLINUX_SYMBOL(__start_pci_fixups_resume_early) = .; \
280 *(.pci_fixup_resume_early) \ 274 *(.pci_fixup_resume_early) \
281 VMLINUX_SYMBOL(__end_pci_fixups_resume_early) = .; \ 275 VMLINUX_SYMBOL(__end_pci_fixups_resume_early) = .; \
282 VMLINUX_SYMBOL(__start_pci_fixups_suspend) = .; \ 276 VMLINUX_SYMBOL(__start_pci_fixups_suspend) = .; \
283 *(.pci_fixup_suspend) \ 277 *(.pci_fixup_suspend) \
284 VMLINUX_SYMBOL(__end_pci_fixups_suspend) = .; \ 278 VMLINUX_SYMBOL(__end_pci_fixups_suspend) = .; \
285 } \ 279 } \
286 \ 280 \
287 /* Built-in firmware blobs */ \ 281 /* Built-in firmware blobs */ \
288 .builtin_fw : AT(ADDR(.builtin_fw) - LOAD_OFFSET) { \ 282 .builtin_fw : AT(ADDR(.builtin_fw) - LOAD_OFFSET) { \
289 VMLINUX_SYMBOL(__start_builtin_fw) = .; \ 283 VMLINUX_SYMBOL(__start_builtin_fw) = .; \
290 *(.builtin_fw) \ 284 *(.builtin_fw) \
291 VMLINUX_SYMBOL(__end_builtin_fw) = .; \ 285 VMLINUX_SYMBOL(__end_builtin_fw) = .; \
292 } \ 286 } \
293 \ 287 \
294 /* RapidIO route ops */ \ 288 /* RapidIO route ops */ \
295 .rio_ops : AT(ADDR(.rio_ops) - LOAD_OFFSET) { \ 289 .rio_ops : AT(ADDR(.rio_ops) - LOAD_OFFSET) { \
296 VMLINUX_SYMBOL(__start_rio_switch_ops) = .; \ 290 VMLINUX_SYMBOL(__start_rio_switch_ops) = .; \
297 *(.rio_switch_ops) \ 291 *(.rio_switch_ops) \
298 VMLINUX_SYMBOL(__end_rio_switch_ops) = .; \ 292 VMLINUX_SYMBOL(__end_rio_switch_ops) = .; \
299 } \ 293 } \
300 \ 294 \
301 TRACEDATA \ 295 TRACEDATA \
302 \ 296 \
303 /* Kernel symbol table: Normal symbols */ \ 297 /* Kernel symbol table: Normal symbols */ \
304 __ksymtab : AT(ADDR(__ksymtab) - LOAD_OFFSET) { \ 298 __ksymtab : AT(ADDR(__ksymtab) - LOAD_OFFSET) { \
305 VMLINUX_SYMBOL(__start___ksymtab) = .; \ 299 VMLINUX_SYMBOL(__start___ksymtab) = .; \
306 *(SORT(___ksymtab+*)) \ 300 *(SORT(___ksymtab+*)) \
307 VMLINUX_SYMBOL(__stop___ksymtab) = .; \ 301 VMLINUX_SYMBOL(__stop___ksymtab) = .; \
308 } \ 302 } \
309 \ 303 \
310 /* Kernel symbol table: GPL-only symbols */ \ 304 /* Kernel symbol table: GPL-only symbols */ \
311 __ksymtab_gpl : AT(ADDR(__ksymtab_gpl) - LOAD_OFFSET) { \ 305 __ksymtab_gpl : AT(ADDR(__ksymtab_gpl) - LOAD_OFFSET) { \
312 VMLINUX_SYMBOL(__start___ksymtab_gpl) = .; \ 306 VMLINUX_SYMBOL(__start___ksymtab_gpl) = .; \
313 *(SORT(___ksymtab_gpl+*)) \ 307 *(SORT(___ksymtab_gpl+*)) \
314 VMLINUX_SYMBOL(__stop___ksymtab_gpl) = .; \ 308 VMLINUX_SYMBOL(__stop___ksymtab_gpl) = .; \
315 } \ 309 } \
316 \ 310 \
317 /* Kernel symbol table: Normal unused symbols */ \ 311 /* Kernel symbol table: Normal unused symbols */ \
318 __ksymtab_unused : AT(ADDR(__ksymtab_unused) - LOAD_OFFSET) { \ 312 __ksymtab_unused : AT(ADDR(__ksymtab_unused) - LOAD_OFFSET) { \
319 VMLINUX_SYMBOL(__start___ksymtab_unused) = .; \ 313 VMLINUX_SYMBOL(__start___ksymtab_unused) = .; \
320 *(SORT(___ksymtab_unused+*)) \ 314 *(SORT(___ksymtab_unused+*)) \
321 VMLINUX_SYMBOL(__stop___ksymtab_unused) = .; \ 315 VMLINUX_SYMBOL(__stop___ksymtab_unused) = .; \
322 } \ 316 } \
323 \ 317 \
324 /* Kernel symbol table: GPL-only unused symbols */ \ 318 /* Kernel symbol table: GPL-only unused symbols */ \
325 __ksymtab_unused_gpl : AT(ADDR(__ksymtab_unused_gpl) - LOAD_OFFSET) { \ 319 __ksymtab_unused_gpl : AT(ADDR(__ksymtab_unused_gpl) - LOAD_OFFSET) { \
326 VMLINUX_SYMBOL(__start___ksymtab_unused_gpl) = .; \ 320 VMLINUX_SYMBOL(__start___ksymtab_unused_gpl) = .; \
327 *(SORT(___ksymtab_unused_gpl+*)) \ 321 *(SORT(___ksymtab_unused_gpl+*)) \
328 VMLINUX_SYMBOL(__stop___ksymtab_unused_gpl) = .; \ 322 VMLINUX_SYMBOL(__stop___ksymtab_unused_gpl) = .; \
329 } \ 323 } \
330 \ 324 \
331 /* Kernel symbol table: GPL-future-only symbols */ \ 325 /* Kernel symbol table: GPL-future-only symbols */ \
332 __ksymtab_gpl_future : AT(ADDR(__ksymtab_gpl_future) - LOAD_OFFSET) { \ 326 __ksymtab_gpl_future : AT(ADDR(__ksymtab_gpl_future) - LOAD_OFFSET) { \
333 VMLINUX_SYMBOL(__start___ksymtab_gpl_future) = .; \ 327 VMLINUX_SYMBOL(__start___ksymtab_gpl_future) = .; \
334 *(SORT(___ksymtab_gpl_future+*)) \ 328 *(SORT(___ksymtab_gpl_future+*)) \
335 VMLINUX_SYMBOL(__stop___ksymtab_gpl_future) = .; \ 329 VMLINUX_SYMBOL(__stop___ksymtab_gpl_future) = .; \
336 } \ 330 } \
337 \ 331 \
338 /* Kernel symbol table: Normal symbols */ \ 332 /* Kernel symbol table: Normal symbols */ \
339 __kcrctab : AT(ADDR(__kcrctab) - LOAD_OFFSET) { \ 333 __kcrctab : AT(ADDR(__kcrctab) - LOAD_OFFSET) { \
340 VMLINUX_SYMBOL(__start___kcrctab) = .; \ 334 VMLINUX_SYMBOL(__start___kcrctab) = .; \
341 *(SORT(___kcrctab+*)) \ 335 *(SORT(___kcrctab+*)) \
342 VMLINUX_SYMBOL(__stop___kcrctab) = .; \ 336 VMLINUX_SYMBOL(__stop___kcrctab) = .; \
343 } \ 337 } \
344 \ 338 \
345 /* Kernel symbol table: GPL-only symbols */ \ 339 /* Kernel symbol table: GPL-only symbols */ \
346 __kcrctab_gpl : AT(ADDR(__kcrctab_gpl) - LOAD_OFFSET) { \ 340 __kcrctab_gpl : AT(ADDR(__kcrctab_gpl) - LOAD_OFFSET) { \
347 VMLINUX_SYMBOL(__start___kcrctab_gpl) = .; \ 341 VMLINUX_SYMBOL(__start___kcrctab_gpl) = .; \
348 *(SORT(___kcrctab_gpl+*)) \ 342 *(SORT(___kcrctab_gpl+*)) \
349 VMLINUX_SYMBOL(__stop___kcrctab_gpl) = .; \ 343 VMLINUX_SYMBOL(__stop___kcrctab_gpl) = .; \
350 } \ 344 } \
351 \ 345 \
352 /* Kernel symbol table: Normal unused symbols */ \ 346 /* Kernel symbol table: Normal unused symbols */ \
353 __kcrctab_unused : AT(ADDR(__kcrctab_unused) - LOAD_OFFSET) { \ 347 __kcrctab_unused : AT(ADDR(__kcrctab_unused) - LOAD_OFFSET) { \
354 VMLINUX_SYMBOL(__start___kcrctab_unused) = .; \ 348 VMLINUX_SYMBOL(__start___kcrctab_unused) = .; \
355 *(SORT(___kcrctab_unused+*)) \ 349 *(SORT(___kcrctab_unused+*)) \
356 VMLINUX_SYMBOL(__stop___kcrctab_unused) = .; \ 350 VMLINUX_SYMBOL(__stop___kcrctab_unused) = .; \
357 } \ 351 } \
358 \ 352 \
359 /* Kernel symbol table: GPL-only unused symbols */ \ 353 /* Kernel symbol table: GPL-only unused symbols */ \
360 __kcrctab_unused_gpl : AT(ADDR(__kcrctab_unused_gpl) - LOAD_OFFSET) { \ 354 __kcrctab_unused_gpl : AT(ADDR(__kcrctab_unused_gpl) - LOAD_OFFSET) { \
361 VMLINUX_SYMBOL(__start___kcrctab_unused_gpl) = .; \ 355 VMLINUX_SYMBOL(__start___kcrctab_unused_gpl) = .; \
362 *(SORT(___kcrctab_unused_gpl+*)) \ 356 *(SORT(___kcrctab_unused_gpl+*)) \
363 VMLINUX_SYMBOL(__stop___kcrctab_unused_gpl) = .; \ 357 VMLINUX_SYMBOL(__stop___kcrctab_unused_gpl) = .; \
364 } \ 358 } \
365 \ 359 \
366 /* Kernel symbol table: GPL-future-only symbols */ \ 360 /* Kernel symbol table: GPL-future-only symbols */ \
367 __kcrctab_gpl_future : AT(ADDR(__kcrctab_gpl_future) - LOAD_OFFSET) { \ 361 __kcrctab_gpl_future : AT(ADDR(__kcrctab_gpl_future) - LOAD_OFFSET) { \
368 VMLINUX_SYMBOL(__start___kcrctab_gpl_future) = .; \ 362 VMLINUX_SYMBOL(__start___kcrctab_gpl_future) = .; \
369 *(SORT(___kcrctab_gpl_future+*)) \ 363 *(SORT(___kcrctab_gpl_future+*)) \
370 VMLINUX_SYMBOL(__stop___kcrctab_gpl_future) = .; \ 364 VMLINUX_SYMBOL(__stop___kcrctab_gpl_future) = .; \
371 } \ 365 } \
372 \ 366 \
373 /* Kernel symbol table: strings */ \ 367 /* Kernel symbol table: strings */ \
374 __ksymtab_strings : AT(ADDR(__ksymtab_strings) - LOAD_OFFSET) { \ 368 __ksymtab_strings : AT(ADDR(__ksymtab_strings) - LOAD_OFFSET) { \
375 *(__ksymtab_strings) \ 369 *(__ksymtab_strings) \
376 } \ 370 } \
377 \ 371 \
378 /* __*init sections */ \ 372 /* __*init sections */ \
379 __init_rodata : AT(ADDR(__init_rodata) - LOAD_OFFSET) { \ 373 __init_rodata : AT(ADDR(__init_rodata) - LOAD_OFFSET) { \
380 *(.ref.rodata) \ 374 *(.ref.rodata) \
381 DEV_KEEP(init.rodata) \ 375 DEV_KEEP(init.rodata) \
382 DEV_KEEP(exit.rodata) \ 376 DEV_KEEP(exit.rodata) \
383 CPU_KEEP(init.rodata) \ 377 CPU_KEEP(init.rodata) \
384 CPU_KEEP(exit.rodata) \ 378 CPU_KEEP(exit.rodata) \
385 MEM_KEEP(init.rodata) \ 379 MEM_KEEP(init.rodata) \
386 MEM_KEEP(exit.rodata) \ 380 MEM_KEEP(exit.rodata) \
387 } \ 381 } \
388 \ 382 \
389 /* Built-in module parameters. */ \ 383 /* Built-in module parameters. */ \
390 __param : AT(ADDR(__param) - LOAD_OFFSET) { \ 384 __param : AT(ADDR(__param) - LOAD_OFFSET) { \
391 VMLINUX_SYMBOL(__start___param) = .; \ 385 VMLINUX_SYMBOL(__start___param) = .; \
392 *(__param) \ 386 *(__param) \
393 VMLINUX_SYMBOL(__stop___param) = .; \ 387 VMLINUX_SYMBOL(__stop___param) = .; \
394 } \ 388 } \
395 \ 389 \
396 /* Built-in module versions. */ \ 390 /* Built-in module versions. */ \
397 __modver : AT(ADDR(__modver) - LOAD_OFFSET) { \ 391 __modver : AT(ADDR(__modver) - LOAD_OFFSET) { \
398 VMLINUX_SYMBOL(__start___modver) = .; \ 392 VMLINUX_SYMBOL(__start___modver) = .; \
399 *(__modver) \ 393 *(__modver) \
400 VMLINUX_SYMBOL(__stop___modver) = .; \ 394 VMLINUX_SYMBOL(__stop___modver) = .; \
401 . = ALIGN((align)); \ 395 . = ALIGN((align)); \
402 VMLINUX_SYMBOL(__end_rodata) = .; \ 396 VMLINUX_SYMBOL(__end_rodata) = .; \
403 } \ 397 } \
404 . = ALIGN((align)); 398 . = ALIGN((align));
405 399
406 /* RODATA & RO_DATA provided for backward compatibility. 400 /* RODATA & RO_DATA provided for backward compatibility.
407 * All archs are supposed to use RO_DATA() */ 401 * All archs are supposed to use RO_DATA() */
408 #define RODATA RO_DATA_SECTION(4096) 402 #define RODATA RO_DATA_SECTION(4096)
409 #define RO_DATA(align) RO_DATA_SECTION(align) 403 #define RO_DATA(align) RO_DATA_SECTION(align)
410 404
411 #define SECURITY_INIT \ 405 #define SECURITY_INIT \
412 .security_initcall.init : AT(ADDR(.security_initcall.init) - LOAD_OFFSET) { \ 406 .security_initcall.init : AT(ADDR(.security_initcall.init) - LOAD_OFFSET) { \
413 VMLINUX_SYMBOL(__security_initcall_start) = .; \ 407 VMLINUX_SYMBOL(__security_initcall_start) = .; \
414 *(.security_initcall.init) \ 408 *(.security_initcall.init) \
415 VMLINUX_SYMBOL(__security_initcall_end) = .; \ 409 VMLINUX_SYMBOL(__security_initcall_end) = .; \
416 } 410 }
417 411
418 /* .text section. Map to function alignment to avoid address changes 412 /* .text section. Map to function alignment to avoid address changes
419 * during second ld run in second ld pass when generating System.map */ 413 * during second ld run in second ld pass when generating System.map */
420 #define TEXT_TEXT \ 414 #define TEXT_TEXT \
421 ALIGN_FUNCTION(); \ 415 ALIGN_FUNCTION(); \
422 *(.text.hot) \ 416 *(.text.hot) \
423 *(.text) \ 417 *(.text) \
424 *(.ref.text) \ 418 *(.ref.text) \
425 DEV_KEEP(init.text) \ 419 DEV_KEEP(init.text) \
426 DEV_KEEP(exit.text) \ 420 DEV_KEEP(exit.text) \
427 CPU_KEEP(init.text) \ 421 CPU_KEEP(init.text) \
428 CPU_KEEP(exit.text) \ 422 CPU_KEEP(exit.text) \
429 MEM_KEEP(init.text) \ 423 MEM_KEEP(init.text) \
430 MEM_KEEP(exit.text) \ 424 MEM_KEEP(exit.text) \
431 *(.text.unlikely) 425 *(.text.unlikely)
432 426
433 427
434 /* sched.text is aling to function alignment to secure we have same 428 /* sched.text is aling to function alignment to secure we have same
435 * address even at second ld pass when generating System.map */ 429 * address even at second ld pass when generating System.map */
436 #define SCHED_TEXT \ 430 #define SCHED_TEXT \
437 ALIGN_FUNCTION(); \ 431 ALIGN_FUNCTION(); \
438 VMLINUX_SYMBOL(__sched_text_start) = .; \ 432 VMLINUX_SYMBOL(__sched_text_start) = .; \
439 *(.sched.text) \ 433 *(.sched.text) \
440 VMLINUX_SYMBOL(__sched_text_end) = .; 434 VMLINUX_SYMBOL(__sched_text_end) = .;
441 435
442 /* spinlock.text is aling to function alignment to secure we have same 436 /* spinlock.text is aling to function alignment to secure we have same
443 * address even at second ld pass when generating System.map */ 437 * address even at second ld pass when generating System.map */
444 #define LOCK_TEXT \ 438 #define LOCK_TEXT \
445 ALIGN_FUNCTION(); \ 439 ALIGN_FUNCTION(); \
446 VMLINUX_SYMBOL(__lock_text_start) = .; \ 440 VMLINUX_SYMBOL(__lock_text_start) = .; \
447 *(.spinlock.text) \ 441 *(.spinlock.text) \
448 VMLINUX_SYMBOL(__lock_text_end) = .; 442 VMLINUX_SYMBOL(__lock_text_end) = .;
449 443
450 #define KPROBES_TEXT \ 444 #define KPROBES_TEXT \
451 ALIGN_FUNCTION(); \ 445 ALIGN_FUNCTION(); \
452 VMLINUX_SYMBOL(__kprobes_text_start) = .; \ 446 VMLINUX_SYMBOL(__kprobes_text_start) = .; \
453 *(.kprobes.text) \ 447 *(.kprobes.text) \
454 VMLINUX_SYMBOL(__kprobes_text_end) = .; 448 VMLINUX_SYMBOL(__kprobes_text_end) = .;
455 449
456 #define ENTRY_TEXT \ 450 #define ENTRY_TEXT \
457 ALIGN_FUNCTION(); \ 451 ALIGN_FUNCTION(); \
458 VMLINUX_SYMBOL(__entry_text_start) = .; \ 452 VMLINUX_SYMBOL(__entry_text_start) = .; \
459 *(.entry.text) \ 453 *(.entry.text) \
460 VMLINUX_SYMBOL(__entry_text_end) = .; 454 VMLINUX_SYMBOL(__entry_text_end) = .;
461 455
462 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 456 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
463 #define IRQENTRY_TEXT \ 457 #define IRQENTRY_TEXT \
464 ALIGN_FUNCTION(); \ 458 ALIGN_FUNCTION(); \
465 VMLINUX_SYMBOL(__irqentry_text_start) = .; \ 459 VMLINUX_SYMBOL(__irqentry_text_start) = .; \
466 *(.irqentry.text) \ 460 *(.irqentry.text) \
467 VMLINUX_SYMBOL(__irqentry_text_end) = .; 461 VMLINUX_SYMBOL(__irqentry_text_end) = .;
468 #else 462 #else
469 #define IRQENTRY_TEXT 463 #define IRQENTRY_TEXT
470 #endif 464 #endif
471 465
472 /* Section used for early init (in .S files) */ 466 /* Section used for early init (in .S files) */
473 #define HEAD_TEXT *(.head.text) 467 #define HEAD_TEXT *(.head.text)
474 468
475 #define HEAD_TEXT_SECTION \ 469 #define HEAD_TEXT_SECTION \
476 .head.text : AT(ADDR(.head.text) - LOAD_OFFSET) { \ 470 .head.text : AT(ADDR(.head.text) - LOAD_OFFSET) { \
477 HEAD_TEXT \ 471 HEAD_TEXT \
478 } 472 }
479 473
480 /* 474 /*
481 * Exception table 475 * Exception table
482 */ 476 */
483 #define EXCEPTION_TABLE(align) \ 477 #define EXCEPTION_TABLE(align) \
484 . = ALIGN(align); \ 478 . = ALIGN(align); \
485 __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { \ 479 __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { \
486 VMLINUX_SYMBOL(__start___ex_table) = .; \ 480 VMLINUX_SYMBOL(__start___ex_table) = .; \
487 *(__ex_table) \ 481 *(__ex_table) \
488 VMLINUX_SYMBOL(__stop___ex_table) = .; \ 482 VMLINUX_SYMBOL(__stop___ex_table) = .; \
489 } 483 }
490 484
491 /* 485 /*
492 * Init task 486 * Init task
493 */ 487 */
494 #define INIT_TASK_DATA_SECTION(align) \ 488 #define INIT_TASK_DATA_SECTION(align) \
495 . = ALIGN(align); \ 489 . = ALIGN(align); \
496 .data..init_task : AT(ADDR(.data..init_task) - LOAD_OFFSET) { \ 490 .data..init_task : AT(ADDR(.data..init_task) - LOAD_OFFSET) { \
497 INIT_TASK_DATA(align) \ 491 INIT_TASK_DATA(align) \
498 } 492 }
499 493
500 #ifdef CONFIG_CONSTRUCTORS 494 #ifdef CONFIG_CONSTRUCTORS
501 #define KERNEL_CTORS() . = ALIGN(8); \ 495 #define KERNEL_CTORS() . = ALIGN(8); \
502 VMLINUX_SYMBOL(__ctors_start) = .; \ 496 VMLINUX_SYMBOL(__ctors_start) = .; \
503 *(.ctors) \ 497 *(.ctors) \
504 VMLINUX_SYMBOL(__ctors_end) = .; 498 VMLINUX_SYMBOL(__ctors_end) = .;
505 #else 499 #else
506 #define KERNEL_CTORS() 500 #define KERNEL_CTORS()
507 #endif 501 #endif
508 502
509 /* init and exit section handling */ 503 /* init and exit section handling */
510 #define INIT_DATA \ 504 #define INIT_DATA \
511 *(.init.data) \ 505 *(.init.data) \
512 DEV_DISCARD(init.data) \ 506 DEV_DISCARD(init.data) \
513 CPU_DISCARD(init.data) \ 507 CPU_DISCARD(init.data) \
514 MEM_DISCARD(init.data) \ 508 MEM_DISCARD(init.data) \
515 KERNEL_CTORS() \ 509 KERNEL_CTORS() \
516 MCOUNT_REC() \ 510 MCOUNT_REC() \
517 *(.init.rodata) \ 511 *(.init.rodata) \
518 FTRACE_EVENTS() \ 512 FTRACE_EVENTS() \
519 TRACE_SYSCALLS() \ 513 TRACE_SYSCALLS() \
520 DEV_DISCARD(init.rodata) \ 514 DEV_DISCARD(init.rodata) \
521 CPU_DISCARD(init.rodata) \ 515 CPU_DISCARD(init.rodata) \
522 MEM_DISCARD(init.rodata) \ 516 MEM_DISCARD(init.rodata) \
523 CLK_OF_TABLES() \ 517 CLK_OF_TABLES() \
524 CLKSRC_OF_TABLES() \ 518 CLKSRC_OF_TABLES() \
525 KERNEL_DTB() \ 519 KERNEL_DTB() \
526 IRQCHIP_OF_MATCH_TABLE() 520 IRQCHIP_OF_MATCH_TABLE()
527 521
528 #define INIT_TEXT \ 522 #define INIT_TEXT \
529 *(.init.text) \ 523 *(.init.text) \
530 DEV_DISCARD(init.text) \ 524 DEV_DISCARD(init.text) \
531 CPU_DISCARD(init.text) \ 525 CPU_DISCARD(init.text) \
532 MEM_DISCARD(init.text) 526 MEM_DISCARD(init.text)
533 527
534 #define EXIT_DATA \ 528 #define EXIT_DATA \
535 *(.exit.data) \ 529 *(.exit.data) \
536 DEV_DISCARD(exit.data) \ 530 DEV_DISCARD(exit.data) \
537 DEV_DISCARD(exit.rodata) \ 531 DEV_DISCARD(exit.rodata) \
538 CPU_DISCARD(exit.data) \ 532 CPU_DISCARD(exit.data) \
539 CPU_DISCARD(exit.rodata) \ 533 CPU_DISCARD(exit.rodata) \
540 MEM_DISCARD(exit.data) \ 534 MEM_DISCARD(exit.data) \
541 MEM_DISCARD(exit.rodata) 535 MEM_DISCARD(exit.rodata)
542 536
543 #define EXIT_TEXT \ 537 #define EXIT_TEXT \
544 *(.exit.text) \ 538 *(.exit.text) \
545 DEV_DISCARD(exit.text) \ 539 DEV_DISCARD(exit.text) \
546 CPU_DISCARD(exit.text) \ 540 CPU_DISCARD(exit.text) \
547 MEM_DISCARD(exit.text) 541 MEM_DISCARD(exit.text)
548 542
549 #define EXIT_CALL \ 543 #define EXIT_CALL \
550 *(.exitcall.exit) 544 *(.exitcall.exit)
551 545
552 /* 546 /*
553 * bss (Block Started by Symbol) - uninitialized data 547 * bss (Block Started by Symbol) - uninitialized data
554 * zeroed during startup 548 * zeroed during startup
555 */ 549 */
556 #define SBSS(sbss_align) \ 550 #define SBSS(sbss_align) \
557 . = ALIGN(sbss_align); \ 551 . = ALIGN(sbss_align); \
558 .sbss : AT(ADDR(.sbss) - LOAD_OFFSET) { \ 552 .sbss : AT(ADDR(.sbss) - LOAD_OFFSET) { \
559 *(.sbss) \ 553 *(.sbss) \
560 *(.scommon) \ 554 *(.scommon) \
561 } 555 }
562 556
563 /* 557 /*
564 * Allow archectures to redefine BSS_FIRST_SECTIONS to add extra 558 * Allow archectures to redefine BSS_FIRST_SECTIONS to add extra
565 * sections to the front of bss. 559 * sections to the front of bss.
566 */ 560 */
567 #ifndef BSS_FIRST_SECTIONS 561 #ifndef BSS_FIRST_SECTIONS
568 #define BSS_FIRST_SECTIONS 562 #define BSS_FIRST_SECTIONS
569 #endif 563 #endif
570 564
571 #define BSS(bss_align) \ 565 #define BSS(bss_align) \
572 . = ALIGN(bss_align); \ 566 . = ALIGN(bss_align); \
573 .bss : AT(ADDR(.bss) - LOAD_OFFSET) { \ 567 .bss : AT(ADDR(.bss) - LOAD_OFFSET) { \
574 BSS_FIRST_SECTIONS \ 568 BSS_FIRST_SECTIONS \
575 *(.bss..page_aligned) \ 569 *(.bss..page_aligned) \
576 *(.dynbss) \ 570 *(.dynbss) \
577 *(.bss) \ 571 *(.bss) \
578 *(COMMON) \ 572 *(COMMON) \
579 } 573 }
580 574
581 /* 575 /*
582 * DWARF debug sections. 576 * DWARF debug sections.
583 * Symbols in the DWARF debugging sections are relative to 577 * Symbols in the DWARF debugging sections are relative to
584 * the beginning of the section so we begin them at 0. 578 * the beginning of the section so we begin them at 0.
585 */ 579 */
586 #define DWARF_DEBUG \ 580 #define DWARF_DEBUG \
587 /* DWARF 1 */ \ 581 /* DWARF 1 */ \
588 .debug 0 : { *(.debug) } \ 582 .debug 0 : { *(.debug) } \
589 .line 0 : { *(.line) } \ 583 .line 0 : { *(.line) } \
590 /* GNU DWARF 1 extensions */ \ 584 /* GNU DWARF 1 extensions */ \
591 .debug_srcinfo 0 : { *(.debug_srcinfo) } \ 585 .debug_srcinfo 0 : { *(.debug_srcinfo) } \
592 .debug_sfnames 0 : { *(.debug_sfnames) } \ 586 .debug_sfnames 0 : { *(.debug_sfnames) } \
593 /* DWARF 1.1 and DWARF 2 */ \ 587 /* DWARF 1.1 and DWARF 2 */ \
594 .debug_aranges 0 : { *(.debug_aranges) } \ 588 .debug_aranges 0 : { *(.debug_aranges) } \
595 .debug_pubnames 0 : { *(.debug_pubnames) } \ 589 .debug_pubnames 0 : { *(.debug_pubnames) } \
596 /* DWARF 2 */ \ 590 /* DWARF 2 */ \
597 .debug_info 0 : { *(.debug_info \ 591 .debug_info 0 : { *(.debug_info \
598 .gnu.linkonce.wi.*) } \ 592 .gnu.linkonce.wi.*) } \
599 .debug_abbrev 0 : { *(.debug_abbrev) } \ 593 .debug_abbrev 0 : { *(.debug_abbrev) } \
600 .debug_line 0 : { *(.debug_line) } \ 594 .debug_line 0 : { *(.debug_line) } \
601 .debug_frame 0 : { *(.debug_frame) } \ 595 .debug_frame 0 : { *(.debug_frame) } \
602 .debug_str 0 : { *(.debug_str) } \ 596 .debug_str 0 : { *(.debug_str) } \
603 .debug_loc 0 : { *(.debug_loc) } \ 597 .debug_loc 0 : { *(.debug_loc) } \
604 .debug_macinfo 0 : { *(.debug_macinfo) } \ 598 .debug_macinfo 0 : { *(.debug_macinfo) } \
605 /* SGI/MIPS DWARF 2 extensions */ \ 599 /* SGI/MIPS DWARF 2 extensions */ \
606 .debug_weaknames 0 : { *(.debug_weaknames) } \ 600 .debug_weaknames 0 : { *(.debug_weaknames) } \
607 .debug_funcnames 0 : { *(.debug_funcnames) } \ 601 .debug_funcnames 0 : { *(.debug_funcnames) } \
608 .debug_typenames 0 : { *(.debug_typenames) } \ 602 .debug_typenames 0 : { *(.debug_typenames) } \
609 .debug_varnames 0 : { *(.debug_varnames) } \ 603 .debug_varnames 0 : { *(.debug_varnames) } \
610 604
611 /* Stabs debugging sections. */ 605 /* Stabs debugging sections. */
612 #define STABS_DEBUG \ 606 #define STABS_DEBUG \
613 .stab 0 : { *(.stab) } \ 607 .stab 0 : { *(.stab) } \
614 .stabstr 0 : { *(.stabstr) } \ 608 .stabstr 0 : { *(.stabstr) } \
615 .stab.excl 0 : { *(.stab.excl) } \ 609 .stab.excl 0 : { *(.stab.excl) } \
616 .stab.exclstr 0 : { *(.stab.exclstr) } \ 610 .stab.exclstr 0 : { *(.stab.exclstr) } \
617 .stab.index 0 : { *(.stab.index) } \ 611 .stab.index 0 : { *(.stab.index) } \
618 .stab.indexstr 0 : { *(.stab.indexstr) } \ 612 .stab.indexstr 0 : { *(.stab.indexstr) } \
619 .comment 0 : { *(.comment) } 613 .comment 0 : { *(.comment) }
620 614
621 #ifdef CONFIG_GENERIC_BUG 615 #ifdef CONFIG_GENERIC_BUG
622 #define BUG_TABLE \ 616 #define BUG_TABLE \
623 . = ALIGN(8); \ 617 . = ALIGN(8); \
624 __bug_table : AT(ADDR(__bug_table) - LOAD_OFFSET) { \ 618 __bug_table : AT(ADDR(__bug_table) - LOAD_OFFSET) { \
625 VMLINUX_SYMBOL(__start___bug_table) = .; \ 619 VMLINUX_SYMBOL(__start___bug_table) = .; \
626 *(__bug_table) \ 620 *(__bug_table) \
627 VMLINUX_SYMBOL(__stop___bug_table) = .; \ 621 VMLINUX_SYMBOL(__stop___bug_table) = .; \
628 } 622 }
629 #else 623 #else
630 #define BUG_TABLE 624 #define BUG_TABLE
631 #endif 625 #endif
632 626
633 #ifdef CONFIG_PM_TRACE 627 #ifdef CONFIG_PM_TRACE
634 #define TRACEDATA \ 628 #define TRACEDATA \
635 . = ALIGN(4); \ 629 . = ALIGN(4); \
636 .tracedata : AT(ADDR(.tracedata) - LOAD_OFFSET) { \ 630 .tracedata : AT(ADDR(.tracedata) - LOAD_OFFSET) { \
637 VMLINUX_SYMBOL(__tracedata_start) = .; \ 631 VMLINUX_SYMBOL(__tracedata_start) = .; \
638 *(.tracedata) \ 632 *(.tracedata) \
639 VMLINUX_SYMBOL(__tracedata_end) = .; \ 633 VMLINUX_SYMBOL(__tracedata_end) = .; \
640 } 634 }
641 #else 635 #else
642 #define TRACEDATA 636 #define TRACEDATA
643 #endif 637 #endif
644 638
645 #define NOTES \ 639 #define NOTES \
646 .notes : AT(ADDR(.notes) - LOAD_OFFSET) { \ 640 .notes : AT(ADDR(.notes) - LOAD_OFFSET) { \
647 VMLINUX_SYMBOL(__start_notes) = .; \ 641 VMLINUX_SYMBOL(__start_notes) = .; \
648 *(.note.*) \ 642 *(.note.*) \
649 VMLINUX_SYMBOL(__stop_notes) = .; \ 643 VMLINUX_SYMBOL(__stop_notes) = .; \
650 } 644 }
651 645
652 #define INIT_SETUP(initsetup_align) \ 646 #define INIT_SETUP(initsetup_align) \
653 . = ALIGN(initsetup_align); \ 647 . = ALIGN(initsetup_align); \
654 VMLINUX_SYMBOL(__setup_start) = .; \ 648 VMLINUX_SYMBOL(__setup_start) = .; \
655 *(.init.setup) \ 649 *(.init.setup) \
656 VMLINUX_SYMBOL(__setup_end) = .; 650 VMLINUX_SYMBOL(__setup_end) = .;
657 651
658 #define INIT_CALLS_LEVEL(level) \ 652 #define INIT_CALLS_LEVEL(level) \
659 VMLINUX_SYMBOL(__initcall##level##_start) = .; \ 653 VMLINUX_SYMBOL(__initcall##level##_start) = .; \
660 *(.initcall##level##.init) \ 654 *(.initcall##level##.init) \
661 *(.initcall##level##s.init) \ 655 *(.initcall##level##s.init) \
662 656
663 #define INIT_CALLS \ 657 #define INIT_CALLS \
664 VMLINUX_SYMBOL(__initcall_start) = .; \ 658 VMLINUX_SYMBOL(__initcall_start) = .; \
665 *(.initcallearly.init) \ 659 *(.initcallearly.init) \
666 INIT_CALLS_LEVEL(0) \ 660 INIT_CALLS_LEVEL(0) \
667 INIT_CALLS_LEVEL(1) \ 661 INIT_CALLS_LEVEL(1) \
668 INIT_CALLS_LEVEL(2) \ 662 INIT_CALLS_LEVEL(2) \
669 INIT_CALLS_LEVEL(3) \ 663 INIT_CALLS_LEVEL(3) \
670 INIT_CALLS_LEVEL(4) \ 664 INIT_CALLS_LEVEL(4) \
671 INIT_CALLS_LEVEL(5) \ 665 INIT_CALLS_LEVEL(5) \
672 INIT_CALLS_LEVEL(rootfs) \ 666 INIT_CALLS_LEVEL(rootfs) \
673 INIT_CALLS_LEVEL(6) \ 667 INIT_CALLS_LEVEL(6) \
674 INIT_CALLS_LEVEL(7) \ 668 INIT_CALLS_LEVEL(7) \
675 VMLINUX_SYMBOL(__initcall_end) = .; 669 VMLINUX_SYMBOL(__initcall_end) = .;
676 670
677 #define CON_INITCALL \ 671 #define CON_INITCALL \
678 VMLINUX_SYMBOL(__con_initcall_start) = .; \ 672 VMLINUX_SYMBOL(__con_initcall_start) = .; \
679 *(.con_initcall.init) \ 673 *(.con_initcall.init) \
680 VMLINUX_SYMBOL(__con_initcall_end) = .; 674 VMLINUX_SYMBOL(__con_initcall_end) = .;
681 675
682 #define SECURITY_INITCALL \ 676 #define SECURITY_INITCALL \
683 VMLINUX_SYMBOL(__security_initcall_start) = .; \ 677 VMLINUX_SYMBOL(__security_initcall_start) = .; \
684 *(.security_initcall.init) \ 678 *(.security_initcall.init) \
685 VMLINUX_SYMBOL(__security_initcall_end) = .; 679 VMLINUX_SYMBOL(__security_initcall_end) = .;
686 680
687 #ifdef CONFIG_BLK_DEV_INITRD 681 #ifdef CONFIG_BLK_DEV_INITRD
688 #define INIT_RAM_FS \ 682 #define INIT_RAM_FS \
689 . = ALIGN(4); \ 683 . = ALIGN(4); \
690 VMLINUX_SYMBOL(__initramfs_start) = .; \ 684 VMLINUX_SYMBOL(__initramfs_start) = .; \
691 *(.init.ramfs) \ 685 *(.init.ramfs) \
692 . = ALIGN(8); \ 686 . = ALIGN(8); \
693 *(.init.ramfs.info) 687 *(.init.ramfs.info)
694 #else 688 #else
695 #define INIT_RAM_FS 689 #define INIT_RAM_FS
696 #endif 690 #endif
697 691
698 /* 692 /*
699 * Default discarded sections. 693 * Default discarded sections.
700 * 694 *
701 * Some archs want to discard exit text/data at runtime rather than 695 * Some archs want to discard exit text/data at runtime rather than
702 * link time due to cross-section references such as alt instructions, 696 * link time due to cross-section references such as alt instructions,
703 * bug table, eh_frame, etc. DISCARDS must be the last of output 697 * bug table, eh_frame, etc. DISCARDS must be the last of output
704 * section definitions so that such archs put those in earlier section 698 * section definitions so that such archs put those in earlier section
705 * definitions. 699 * definitions.
706 */ 700 */
707 #define DISCARDS \ 701 #define DISCARDS \
708 /DISCARD/ : { \ 702 /DISCARD/ : { \
709 EXIT_TEXT \ 703 EXIT_TEXT \
710 EXIT_DATA \ 704 EXIT_DATA \
711 EXIT_CALL \ 705 EXIT_CALL \
712 *(.discard) \ 706 *(.discard) \
713 *(.discard.*) \ 707 *(.discard.*) \
714 } 708 }
715 709
716 /** 710 /**
717 * PERCPU_INPUT - the percpu input sections 711 * PERCPU_INPUT - the percpu input sections
718 * @cacheline: cacheline size 712 * @cacheline: cacheline size
719 * 713 *
720 * The core percpu section names and core symbols which do not rely 714 * The core percpu section names and core symbols which do not rely
721 * directly upon load addresses. 715 * directly upon load addresses.
722 * 716 *
723 * @cacheline is used to align subsections to avoid false cacheline 717 * @cacheline is used to align subsections to avoid false cacheline
724 * sharing between subsections for different purposes. 718 * sharing between subsections for different purposes.
725 */ 719 */
726 #define PERCPU_INPUT(cacheline) \ 720 #define PERCPU_INPUT(cacheline) \
727 VMLINUX_SYMBOL(__per_cpu_start) = .; \ 721 VMLINUX_SYMBOL(__per_cpu_start) = .; \
728 *(.data..percpu..first) \ 722 *(.data..percpu..first) \
729 . = ALIGN(PAGE_SIZE); \ 723 . = ALIGN(PAGE_SIZE); \
730 *(.data..percpu..page_aligned) \ 724 *(.data..percpu..page_aligned) \
731 . = ALIGN(cacheline); \ 725 . = ALIGN(cacheline); \
732 *(.data..percpu..readmostly) \ 726 *(.data..percpu..readmostly) \
733 . = ALIGN(cacheline); \ 727 . = ALIGN(cacheline); \
734 *(.data..percpu) \ 728 *(.data..percpu) \
735 *(.data..percpu..shared_aligned) \ 729 *(.data..percpu..shared_aligned) \
736 VMLINUX_SYMBOL(__per_cpu_end) = .; 730 VMLINUX_SYMBOL(__per_cpu_end) = .;
737 731
738 /** 732 /**
739 * PERCPU_VADDR - define output section for percpu area 733 * PERCPU_VADDR - define output section for percpu area
740 * @cacheline: cacheline size 734 * @cacheline: cacheline size
741 * @vaddr: explicit base address (optional) 735 * @vaddr: explicit base address (optional)
742 * @phdr: destination PHDR (optional) 736 * @phdr: destination PHDR (optional)
743 * 737 *
744 * Macro which expands to output section for percpu area. 738 * Macro which expands to output section for percpu area.
745 * 739 *
746 * @cacheline is used to align subsections to avoid false cacheline 740 * @cacheline is used to align subsections to avoid false cacheline
747 * sharing between subsections for different purposes. 741 * sharing between subsections for different purposes.
748 * 742 *
749 * If @vaddr is not blank, it specifies explicit base address and all 743 * If @vaddr is not blank, it specifies explicit base address and all
750 * percpu symbols will be offset from the given address. If blank, 744 * percpu symbols will be offset from the given address. If blank,
751 * @vaddr always equals @laddr + LOAD_OFFSET. 745 * @vaddr always equals @laddr + LOAD_OFFSET.
752 * 746 *
753 * @phdr defines the output PHDR to use if not blank. Be warned that 747 * @phdr defines the output PHDR to use if not blank. Be warned that
754 * output PHDR is sticky. If @phdr is specified, the next output 748 * output PHDR is sticky. If @phdr is specified, the next output
755 * section in the linker script will go there too. @phdr should have 749 * section in the linker script will go there too. @phdr should have
756 * a leading colon. 750 * a leading colon.
757 * 751 *
758 * Note that this macros defines __per_cpu_load as an absolute symbol. 752 * Note that this macros defines __per_cpu_load as an absolute symbol.
759 * If there is no need to put the percpu section at a predetermined 753 * If there is no need to put the percpu section at a predetermined
760 * address, use PERCPU_SECTION. 754 * address, use PERCPU_SECTION.
761 */ 755 */
762 #define PERCPU_VADDR(cacheline, vaddr, phdr) \ 756 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
763 VMLINUX_SYMBOL(__per_cpu_load) = .; \ 757 VMLINUX_SYMBOL(__per_cpu_load) = .; \
764 .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \ 758 .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
765 - LOAD_OFFSET) { \ 759 - LOAD_OFFSET) { \
766 PERCPU_INPUT(cacheline) \ 760 PERCPU_INPUT(cacheline) \
767 } phdr \ 761 } phdr \
768 . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu); 762 . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
769 763
770 /** 764 /**
771 * PERCPU_SECTION - define output section for percpu area, simple version 765 * PERCPU_SECTION - define output section for percpu area, simple version
772 * @cacheline: cacheline size 766 * @cacheline: cacheline size
773 * 767 *
774 * Align to PAGE_SIZE and outputs output section for percpu area. This 768 * Align to PAGE_SIZE and outputs output section for percpu area. This
775 * macro doesn't manipulate @vaddr or @phdr and __per_cpu_load and 769 * macro doesn't manipulate @vaddr or @phdr and __per_cpu_load and
776 * __per_cpu_start will be identical. 770 * __per_cpu_start will be identical.
777 * 771 *
778 * This macro is equivalent to ALIGN(PAGE_SIZE); PERCPU_VADDR(@cacheline,,) 772 * This macro is equivalent to ALIGN(PAGE_SIZE); PERCPU_VADDR(@cacheline,,)
779 * except that __per_cpu_load is defined as a relative symbol against 773 * except that __per_cpu_load is defined as a relative symbol against
780 * .data..percpu which is required for relocatable x86_32 configuration. 774 * .data..percpu which is required for relocatable x86_32 configuration.
781 */ 775 */
782 #define PERCPU_SECTION(cacheline) \ 776 #define PERCPU_SECTION(cacheline) \
783 . = ALIGN(PAGE_SIZE); \ 777 . = ALIGN(PAGE_SIZE); \
784 .data..percpu : AT(ADDR(.data..percpu) - LOAD_OFFSET) { \ 778 .data..percpu : AT(ADDR(.data..percpu) - LOAD_OFFSET) { \
785 VMLINUX_SYMBOL(__per_cpu_load) = .; \ 779 VMLINUX_SYMBOL(__per_cpu_load) = .; \
786 PERCPU_INPUT(cacheline) \ 780 PERCPU_INPUT(cacheline) \
787 } 781 }
788 782
789 783
790 /* 784 /*
791 * Definition of the high level *_SECTION macros 785 * Definition of the high level *_SECTION macros
792 * They will fit only a subset of the architectures 786 * They will fit only a subset of the architectures
793 */ 787 */
794 788
795 789
796 /* 790 /*
797 * Writeable data. 791 * Writeable data.
798 * All sections are combined in a single .data section. 792 * All sections are combined in a single .data section.
799 * The sections following CONSTRUCTORS are arranged so their 793 * The sections following CONSTRUCTORS are arranged so their
800 * typical alignment matches. 794 * typical alignment matches.
801 * A cacheline is typical/always less than a PAGE_SIZE so 795 * A cacheline is typical/always less than a PAGE_SIZE so
802 * the sections that has this restriction (or similar) 796 * the sections that has this restriction (or similar)
803 * is located before the ones requiring PAGE_SIZE alignment. 797 * is located before the ones requiring PAGE_SIZE alignment.
804 * NOSAVE_DATA starts and ends with a PAGE_SIZE alignment which 798 * NOSAVE_DATA starts and ends with a PAGE_SIZE alignment which
805 * matches the requirement of PAGE_ALIGNED_DATA. 799 * matches the requirement of PAGE_ALIGNED_DATA.
806 * 800 *
807 * use 0 as page_align if page_aligned data is not used */ 801 * use 0 as page_align if page_aligned data is not used */
808 #define RW_DATA_SECTION(cacheline, pagealigned, inittask) \ 802 #define RW_DATA_SECTION(cacheline, pagealigned, inittask) \
809 . = ALIGN(PAGE_SIZE); \ 803 . = ALIGN(PAGE_SIZE); \
810 .data : AT(ADDR(.data) - LOAD_OFFSET) { \ 804 .data : AT(ADDR(.data) - LOAD_OFFSET) { \
811 INIT_TASK_DATA(inittask) \ 805 INIT_TASK_DATA(inittask) \
812 NOSAVE_DATA \ 806 NOSAVE_DATA \
813 PAGE_ALIGNED_DATA(pagealigned) \ 807 PAGE_ALIGNED_DATA(pagealigned) \
814 CACHELINE_ALIGNED_DATA(cacheline) \ 808 CACHELINE_ALIGNED_DATA(cacheline) \
815 READ_MOSTLY_DATA(cacheline) \ 809 READ_MOSTLY_DATA(cacheline) \
816 DATA_DATA \ 810 DATA_DATA \
817 CONSTRUCTORS \ 811 CONSTRUCTORS \
818 } 812 }
819 813
820 #define INIT_TEXT_SECTION(inittext_align) \ 814 #define INIT_TEXT_SECTION(inittext_align) \
821 . = ALIGN(inittext_align); \ 815 . = ALIGN(inittext_align); \
822 .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) { \ 816 .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) { \
823 VMLINUX_SYMBOL(_sinittext) = .; \ 817 VMLINUX_SYMBOL(_sinittext) = .; \
824 INIT_TEXT \ 818 INIT_TEXT \
825 VMLINUX_SYMBOL(_einittext) = .; \ 819 VMLINUX_SYMBOL(_einittext) = .; \
826 } 820 }
827 821
828 #define INIT_DATA_SECTION(initsetup_align) \ 822 #define INIT_DATA_SECTION(initsetup_align) \
829 .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { \ 823 .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { \
830 INIT_DATA \ 824 INIT_DATA \
831 INIT_SETUP(initsetup_align) \ 825 INIT_SETUP(initsetup_align) \
832 INIT_CALLS \ 826 INIT_CALLS \
833 CON_INITCALL \ 827 CON_INITCALL \
834 SECURITY_INITCALL \ 828 SECURITY_INITCALL \
835 INIT_RAM_FS \ 829 INIT_RAM_FS \
836 } 830 }
837 831
838 #define BSS_SECTION(sbss_align, bss_align, stop_align) \ 832 #define BSS_SECTION(sbss_align, bss_align, stop_align) \
839 . = ALIGN(sbss_align); \ 833 . = ALIGN(sbss_align); \
840 VMLINUX_SYMBOL(__bss_start) = .; \ 834 VMLINUX_SYMBOL(__bss_start) = .; \
841 SBSS(sbss_align) \ 835 SBSS(sbss_align) \
842 BSS(bss_align) \ 836 BSS(bss_align) \
843 . = ALIGN(stop_align); \ 837 . = ALIGN(stop_align); \
844 VMLINUX_SYMBOL(__bss_stop) = .; 838 VMLINUX_SYMBOL(__bss_stop) = .;
845 839
include/linux/export.h
1 #ifndef _LINUX_EXPORT_H 1 #ifndef _LINUX_EXPORT_H
2 #define _LINUX_EXPORT_H 2 #define _LINUX_EXPORT_H
3 /* 3 /*
4 * Export symbols from the kernel to modules. Forked from module.h 4 * Export symbols from the kernel to modules. Forked from module.h
5 * to reduce the amount of pointless cruft we feed to gcc when only 5 * to reduce the amount of pointless cruft we feed to gcc when only
6 * exporting a simple symbol or two. 6 * exporting a simple symbol or two.
7 * 7 *
8 * If you feel the need to add #include <linux/foo.h> to this file 8 * Try not to add #includes here. It slows compilation and makes kernel
9 * then you are doing something wrong and should go away silently. 9 * hackers place grumpy comments in header files.
10 */ 10 */
11 11
12 /* Some toolchains use a `_' prefix for all user symbols. */ 12 /* Some toolchains use a `_' prefix for all user symbols. */
13 #ifdef CONFIG_SYMBOL_PREFIX 13 #ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX
14 #define MODULE_SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX 14 #define __VMLINUX_SYMBOL(x) _##x
15 #define __VMLINUX_SYMBOL_STR(x) "_" #x
15 #else 16 #else
16 #define MODULE_SYMBOL_PREFIX "" 17 #define __VMLINUX_SYMBOL(x) x
18 #define __VMLINUX_SYMBOL_STR(x) #x
17 #endif 19 #endif
18 20
21 /* Indirect, so macros are expanded before pasting. */
22 #define VMLINUX_SYMBOL(x) __VMLINUX_SYMBOL(x)
23 #define VMLINUX_SYMBOL_STR(x) __VMLINUX_SYMBOL_STR(x)
24
25 #ifndef __ASSEMBLY__
19 struct kernel_symbol 26 struct kernel_symbol
20 { 27 {
21 unsigned long value; 28 unsigned long value;
22 const char *name; 29 const char *name;
23 }; 30 };
24 31
25 #ifdef MODULE 32 #ifdef MODULE
26 extern struct module __this_module; 33 extern struct module __this_module;
27 #define THIS_MODULE (&__this_module) 34 #define THIS_MODULE (&__this_module)
28 #else 35 #else
29 #define THIS_MODULE ((struct module *)0) 36 #define THIS_MODULE ((struct module *)0)
30 #endif 37 #endif
31 38
32 #ifdef CONFIG_MODULES 39 #ifdef CONFIG_MODULES
33 40
34 #ifndef __GENKSYMS__ 41 #ifndef __GENKSYMS__
35 #ifdef CONFIG_MODVERSIONS 42 #ifdef CONFIG_MODVERSIONS
36 /* Mark the CRC weak since genksyms apparently decides not to 43 /* Mark the CRC weak since genksyms apparently decides not to
37 * generate a checksums for some symbols */ 44 * generate a checksums for some symbols */
38 #define __CRC_SYMBOL(sym, sec) \ 45 #define __CRC_SYMBOL(sym, sec) \
39 extern void *__crc_##sym __attribute__((weak)); \ 46 extern void *__crc_##sym __attribute__((weak)); \
40 static const unsigned long __kcrctab_##sym \ 47 static const unsigned long __kcrctab_##sym \
41 __used \ 48 __used \
42 __attribute__((section("___kcrctab" sec "+" #sym), unused)) \ 49 __attribute__((section("___kcrctab" sec "+" #sym), unused)) \
43 = (unsigned long) &__crc_##sym; 50 = (unsigned long) &__crc_##sym;
44 #else 51 #else
45 #define __CRC_SYMBOL(sym, sec) 52 #define __CRC_SYMBOL(sym, sec)
46 #endif 53 #endif
47 54
48 /* For every exported symbol, place a struct in the __ksymtab section */ 55 /* For every exported symbol, place a struct in the __ksymtab section */
49 #define __EXPORT_SYMBOL(sym, sec) \ 56 #define __EXPORT_SYMBOL(sym, sec) \
50 extern typeof(sym) sym; \ 57 extern typeof(sym) sym; \
51 __CRC_SYMBOL(sym, sec) \ 58 __CRC_SYMBOL(sym, sec) \
52 static const char __kstrtab_##sym[] \ 59 static const char __kstrtab_##sym[] \
53 __attribute__((section("__ksymtab_strings"), aligned(1))) \ 60 __attribute__((section("__ksymtab_strings"), aligned(1))) \
54 = MODULE_SYMBOL_PREFIX #sym; \ 61 = VMLINUX_SYMBOL_STR(sym); \
55 static const struct kernel_symbol __ksymtab_##sym \ 62 static const struct kernel_symbol __ksymtab_##sym \
56 __used \ 63 __used \
57 __attribute__((section("___ksymtab" sec "+" #sym), unused)) \ 64 __attribute__((section("___ksymtab" sec "+" #sym), unused)) \
58 = { (unsigned long)&sym, __kstrtab_##sym } 65 = { (unsigned long)&sym, __kstrtab_##sym }
59 66
60 #define EXPORT_SYMBOL(sym) \ 67 #define EXPORT_SYMBOL(sym) \
61 __EXPORT_SYMBOL(sym, "") 68 __EXPORT_SYMBOL(sym, "")
62 69
63 #define EXPORT_SYMBOL_GPL(sym) \ 70 #define EXPORT_SYMBOL_GPL(sym) \
64 __EXPORT_SYMBOL(sym, "_gpl") 71 __EXPORT_SYMBOL(sym, "_gpl")
65 72
66 #define EXPORT_SYMBOL_GPL_FUTURE(sym) \ 73 #define EXPORT_SYMBOL_GPL_FUTURE(sym) \
67 __EXPORT_SYMBOL(sym, "_gpl_future") 74 __EXPORT_SYMBOL(sym, "_gpl_future")
68 75
69 #ifdef CONFIG_UNUSED_SYMBOLS 76 #ifdef CONFIG_UNUSED_SYMBOLS
70 #define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused") 77 #define EXPORT_UNUSED_SYMBOL(sym) __EXPORT_SYMBOL(sym, "_unused")
71 #define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl") 78 #define EXPORT_UNUSED_SYMBOL_GPL(sym) __EXPORT_SYMBOL(sym, "_unused_gpl")
72 #else 79 #else
73 #define EXPORT_UNUSED_SYMBOL(sym) 80 #define EXPORT_UNUSED_SYMBOL(sym)
74 #define EXPORT_UNUSED_SYMBOL_GPL(sym) 81 #define EXPORT_UNUSED_SYMBOL_GPL(sym)
75 #endif 82 #endif
76 83
77 #endif /* __GENKSYMS__ */ 84 #endif /* __GENKSYMS__ */
78 85
79 #else /* !CONFIG_MODULES... */ 86 #else /* !CONFIG_MODULES... */
80 87
81 #define EXPORT_SYMBOL(sym) 88 #define EXPORT_SYMBOL(sym)
82 #define EXPORT_SYMBOL_GPL(sym) 89 #define EXPORT_SYMBOL_GPL(sym)
83 #define EXPORT_SYMBOL_GPL_FUTURE(sym) 90 #define EXPORT_SYMBOL_GPL_FUTURE(sym)
84 #define EXPORT_UNUSED_SYMBOL(sym) 91 #define EXPORT_UNUSED_SYMBOL(sym)
85 #define EXPORT_UNUSED_SYMBOL_GPL(sym) 92 #define EXPORT_UNUSED_SYMBOL_GPL(sym)
86 93
87 #endif /* CONFIG_MODULES */ 94 #endif /* CONFIG_MODULES */
95 #endif /* !__ASSEMBLY__ */
88 96
89 #endif /* _LINUX_EXPORT_H */ 97 #endif /* _LINUX_EXPORT_H */
90 98
include/linux/kernel.h
1 #ifndef _LINUX_KERNEL_H 1 #ifndef _LINUX_KERNEL_H
2 #define _LINUX_KERNEL_H 2 #define _LINUX_KERNEL_H
3 3
4 4
5 #include <stdarg.h> 5 #include <stdarg.h>
6 #include <linux/linkage.h> 6 #include <linux/linkage.h>
7 #include <linux/stddef.h> 7 #include <linux/stddef.h>
8 #include <linux/types.h> 8 #include <linux/types.h>
9 #include <linux/compiler.h> 9 #include <linux/compiler.h>
10 #include <linux/bitops.h> 10 #include <linux/bitops.h>
11 #include <linux/log2.h> 11 #include <linux/log2.h>
12 #include <linux/typecheck.h> 12 #include <linux/typecheck.h>
13 #include <linux/printk.h> 13 #include <linux/printk.h>
14 #include <linux/dynamic_debug.h> 14 #include <linux/dynamic_debug.h>
15 #include <asm/byteorder.h> 15 #include <asm/byteorder.h>
16 #include <uapi/linux/kernel.h> 16 #include <uapi/linux/kernel.h>
17 17
18 #define USHRT_MAX ((u16)(~0U)) 18 #define USHRT_MAX ((u16)(~0U))
19 #define SHRT_MAX ((s16)(USHRT_MAX>>1)) 19 #define SHRT_MAX ((s16)(USHRT_MAX>>1))
20 #define SHRT_MIN ((s16)(-SHRT_MAX - 1)) 20 #define SHRT_MIN ((s16)(-SHRT_MAX - 1))
21 #define INT_MAX ((int)(~0U>>1)) 21 #define INT_MAX ((int)(~0U>>1))
22 #define INT_MIN (-INT_MAX - 1) 22 #define INT_MIN (-INT_MAX - 1)
23 #define UINT_MAX (~0U) 23 #define UINT_MAX (~0U)
24 #define LONG_MAX ((long)(~0UL>>1)) 24 #define LONG_MAX ((long)(~0UL>>1))
25 #define LONG_MIN (-LONG_MAX - 1) 25 #define LONG_MIN (-LONG_MAX - 1)
26 #define ULONG_MAX (~0UL) 26 #define ULONG_MAX (~0UL)
27 #define LLONG_MAX ((long long)(~0ULL>>1)) 27 #define LLONG_MAX ((long long)(~0ULL>>1))
28 #define LLONG_MIN (-LLONG_MAX - 1) 28 #define LLONG_MIN (-LLONG_MAX - 1)
29 #define ULLONG_MAX (~0ULL) 29 #define ULLONG_MAX (~0ULL)
30 #define SIZE_MAX (~(size_t)0) 30 #define SIZE_MAX (~(size_t)0)
31 31
32 #define STACK_MAGIC 0xdeadbeef 32 #define STACK_MAGIC 0xdeadbeef
33 33
34 #define REPEAT_BYTE(x) ((~0ul / 0xff) * (x)) 34 #define REPEAT_BYTE(x) ((~0ul / 0xff) * (x))
35 35
36 #define ALIGN(x, a) __ALIGN_KERNEL((x), (a)) 36 #define ALIGN(x, a) __ALIGN_KERNEL((x), (a))
37 #define __ALIGN_MASK(x, mask) __ALIGN_KERNEL_MASK((x), (mask)) 37 #define __ALIGN_MASK(x, mask) __ALIGN_KERNEL_MASK((x), (mask))
38 #define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a))) 38 #define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a)))
39 #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) 39 #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0)
40 40
41 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) 41 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
42 42
43 /* 43 /*
44 * This looks more complex than it should be. But we need to 44 * This looks more complex than it should be. But we need to
45 * get the type for the ~ right in round_down (it needs to be 45 * get the type for the ~ right in round_down (it needs to be
46 * as wide as the result!), and we want to evaluate the macro 46 * as wide as the result!), and we want to evaluate the macro
47 * arguments just once each. 47 * arguments just once each.
48 */ 48 */
49 #define __round_mask(x, y) ((__typeof__(x))((y)-1)) 49 #define __round_mask(x, y) ((__typeof__(x))((y)-1))
50 #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) 50 #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
51 #define round_down(x, y) ((x) & ~__round_mask(x, y)) 51 #define round_down(x, y) ((x) & ~__round_mask(x, y))
52 52
53 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) 53 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
54 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) 54 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
55 #define DIV_ROUND_UP_ULL(ll,d) \ 55 #define DIV_ROUND_UP_ULL(ll,d) \
56 ({ unsigned long long _tmp = (ll)+(d)-1; do_div(_tmp, d); _tmp; }) 56 ({ unsigned long long _tmp = (ll)+(d)-1; do_div(_tmp, d); _tmp; })
57 57
58 #if BITS_PER_LONG == 32 58 #if BITS_PER_LONG == 32
59 # define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP_ULL(ll, d) 59 # define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP_ULL(ll, d)
60 #else 60 #else
61 # define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP(ll,d) 61 # define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP(ll,d)
62 #endif 62 #endif
63 63
64 /* The `const' in roundup() prevents gcc-3.3 from calling __divdi3 */ 64 /* The `const' in roundup() prevents gcc-3.3 from calling __divdi3 */
65 #define roundup(x, y) ( \ 65 #define roundup(x, y) ( \
66 { \ 66 { \
67 const typeof(y) __y = y; \ 67 const typeof(y) __y = y; \
68 (((x) + (__y - 1)) / __y) * __y; \ 68 (((x) + (__y - 1)) / __y) * __y; \
69 } \ 69 } \
70 ) 70 )
71 #define rounddown(x, y) ( \ 71 #define rounddown(x, y) ( \
72 { \ 72 { \
73 typeof(x) __x = (x); \ 73 typeof(x) __x = (x); \
74 __x - (__x % (y)); \ 74 __x - (__x % (y)); \
75 } \ 75 } \
76 ) 76 )
77 77
78 /* 78 /*
79 * Divide positive or negative dividend by positive divisor and round 79 * Divide positive or negative dividend by positive divisor and round
80 * to closest integer. Result is undefined for negative divisors and 80 * to closest integer. Result is undefined for negative divisors and
81 * for negative dividends if the divisor variable type is unsigned. 81 * for negative dividends if the divisor variable type is unsigned.
82 */ 82 */
83 #define DIV_ROUND_CLOSEST(x, divisor)( \ 83 #define DIV_ROUND_CLOSEST(x, divisor)( \
84 { \ 84 { \
85 typeof(x) __x = x; \ 85 typeof(x) __x = x; \
86 typeof(divisor) __d = divisor; \ 86 typeof(divisor) __d = divisor; \
87 (((typeof(x))-1) > 0 || \ 87 (((typeof(x))-1) > 0 || \
88 ((typeof(divisor))-1) > 0 || (__x) > 0) ? \ 88 ((typeof(divisor))-1) > 0 || (__x) > 0) ? \
89 (((__x) + ((__d) / 2)) / (__d)) : \ 89 (((__x) + ((__d) / 2)) / (__d)) : \
90 (((__x) - ((__d) / 2)) / (__d)); \ 90 (((__x) - ((__d) / 2)) / (__d)); \
91 } \ 91 } \
92 ) 92 )
93 93
94 /* 94 /*
95 * Multiplies an integer by a fraction, while avoiding unnecessary 95 * Multiplies an integer by a fraction, while avoiding unnecessary
96 * overflow or loss of precision. 96 * overflow or loss of precision.
97 */ 97 */
98 #define mult_frac(x, numer, denom)( \ 98 #define mult_frac(x, numer, denom)( \
99 { \ 99 { \
100 typeof(x) quot = (x) / (denom); \ 100 typeof(x) quot = (x) / (denom); \
101 typeof(x) rem = (x) % (denom); \ 101 typeof(x) rem = (x) % (denom); \
102 (quot * (numer)) + ((rem * (numer)) / (denom)); \ 102 (quot * (numer)) + ((rem * (numer)) / (denom)); \
103 } \ 103 } \
104 ) 104 )
105 105
106 106
107 #define _RET_IP_ (unsigned long)__builtin_return_address(0) 107 #define _RET_IP_ (unsigned long)__builtin_return_address(0)
108 #define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; }) 108 #define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; })
109 109
110 #ifdef CONFIG_LBDAF 110 #ifdef CONFIG_LBDAF
111 # include <asm/div64.h> 111 # include <asm/div64.h>
112 # define sector_div(a, b) do_div(a, b) 112 # define sector_div(a, b) do_div(a, b)
113 #else 113 #else
114 # define sector_div(n, b)( \ 114 # define sector_div(n, b)( \
115 { \ 115 { \
116 int _res; \ 116 int _res; \
117 _res = (n) % (b); \ 117 _res = (n) % (b); \
118 (n) /= (b); \ 118 (n) /= (b); \
119 _res; \ 119 _res; \
120 } \ 120 } \
121 ) 121 )
122 #endif 122 #endif
123 123
124 /** 124 /**
125 * upper_32_bits - return bits 32-63 of a number 125 * upper_32_bits - return bits 32-63 of a number
126 * @n: the number we're accessing 126 * @n: the number we're accessing
127 * 127 *
128 * A basic shift-right of a 64- or 32-bit quantity. Use this to suppress 128 * A basic shift-right of a 64- or 32-bit quantity. Use this to suppress
129 * the "right shift count >= width of type" warning when that quantity is 129 * the "right shift count >= width of type" warning when that quantity is
130 * 32-bits. 130 * 32-bits.
131 */ 131 */
132 #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16)) 132 #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
133 133
134 /** 134 /**
135 * lower_32_bits - return bits 0-31 of a number 135 * lower_32_bits - return bits 0-31 of a number
136 * @n: the number we're accessing 136 * @n: the number we're accessing
137 */ 137 */
138 #define lower_32_bits(n) ((u32)(n)) 138 #define lower_32_bits(n) ((u32)(n))
139 139
140 struct completion; 140 struct completion;
141 struct pt_regs; 141 struct pt_regs;
142 struct user; 142 struct user;
143 143
144 #ifdef CONFIG_PREEMPT_VOLUNTARY 144 #ifdef CONFIG_PREEMPT_VOLUNTARY
145 extern int _cond_resched(void); 145 extern int _cond_resched(void);
146 # define might_resched() _cond_resched() 146 # define might_resched() _cond_resched()
147 #else 147 #else
148 # define might_resched() do { } while (0) 148 # define might_resched() do { } while (0)
149 #endif 149 #endif
150 150
151 #ifdef CONFIG_DEBUG_ATOMIC_SLEEP 151 #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
152 void __might_sleep(const char *file, int line, int preempt_offset); 152 void __might_sleep(const char *file, int line, int preempt_offset);
153 /** 153 /**
154 * might_sleep - annotation for functions that can sleep 154 * might_sleep - annotation for functions that can sleep
155 * 155 *
156 * this macro will print a stack trace if it is executed in an atomic 156 * this macro will print a stack trace if it is executed in an atomic
157 * context (spinlock, irq-handler, ...). 157 * context (spinlock, irq-handler, ...).
158 * 158 *
159 * This is a useful debugging help to be able to catch problems early and not 159 * This is a useful debugging help to be able to catch problems early and not
160 * be bitten later when the calling function happens to sleep when it is not 160 * be bitten later when the calling function happens to sleep when it is not
161 * supposed to. 161 * supposed to.
162 */ 162 */
163 # define might_sleep() \ 163 # define might_sleep() \
164 do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0) 164 do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
165 #else 165 #else
166 static inline void __might_sleep(const char *file, int line, 166 static inline void __might_sleep(const char *file, int line,
167 int preempt_offset) { } 167 int preempt_offset) { }
168 # define might_sleep() do { might_resched(); } while (0) 168 # define might_sleep() do { might_resched(); } while (0)
169 #endif 169 #endif
170 170
171 #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0) 171 #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0)
172 172
173 /* 173 /*
174 * abs() handles unsigned and signed longs, ints, shorts and chars. For all 174 * abs() handles unsigned and signed longs, ints, shorts and chars. For all
175 * input types abs() returns a signed long. 175 * input types abs() returns a signed long.
176 * abs() should not be used for 64-bit types (s64, u64, long long) - use abs64() 176 * abs() should not be used for 64-bit types (s64, u64, long long) - use abs64()
177 * for those. 177 * for those.
178 */ 178 */
179 #define abs(x) ({ \ 179 #define abs(x) ({ \
180 long ret; \ 180 long ret; \
181 if (sizeof(x) == sizeof(long)) { \ 181 if (sizeof(x) == sizeof(long)) { \
182 long __x = (x); \ 182 long __x = (x); \
183 ret = (__x < 0) ? -__x : __x; \ 183 ret = (__x < 0) ? -__x : __x; \
184 } else { \ 184 } else { \
185 int __x = (x); \ 185 int __x = (x); \
186 ret = (__x < 0) ? -__x : __x; \ 186 ret = (__x < 0) ? -__x : __x; \
187 } \ 187 } \
188 ret; \ 188 ret; \
189 }) 189 })
190 190
191 #define abs64(x) ({ \ 191 #define abs64(x) ({ \
192 s64 __x = (x); \ 192 s64 __x = (x); \
193 (__x < 0) ? -__x : __x; \ 193 (__x < 0) ? -__x : __x; \
194 }) 194 })
195 195
196 #ifdef CONFIG_PROVE_LOCKING 196 #ifdef CONFIG_PROVE_LOCKING
197 void might_fault(void); 197 void might_fault(void);
198 #else 198 #else
199 static inline void might_fault(void) 199 static inline void might_fault(void)
200 { 200 {
201 might_sleep(); 201 might_sleep();
202 } 202 }
203 #endif 203 #endif
204 204
205 extern struct atomic_notifier_head panic_notifier_list; 205 extern struct atomic_notifier_head panic_notifier_list;
206 extern long (*panic_blink)(int state); 206 extern long (*panic_blink)(int state);
207 __printf(1, 2) 207 __printf(1, 2)
208 void panic(const char *fmt, ...) 208 void panic(const char *fmt, ...)
209 __noreturn __cold; 209 __noreturn __cold;
210 extern void oops_enter(void); 210 extern void oops_enter(void);
211 extern void oops_exit(void); 211 extern void oops_exit(void);
212 void print_oops_end_marker(void); 212 void print_oops_end_marker(void);
213 extern int oops_may_print(void); 213 extern int oops_may_print(void);
214 void do_exit(long error_code) 214 void do_exit(long error_code)
215 __noreturn; 215 __noreturn;
216 void complete_and_exit(struct completion *, long) 216 void complete_and_exit(struct completion *, long)
217 __noreturn; 217 __noreturn;
218 218
219 /* Internal, do not use. */ 219 /* Internal, do not use. */
220 int __must_check _kstrtoul(const char *s, unsigned int base, unsigned long *res); 220 int __must_check _kstrtoul(const char *s, unsigned int base, unsigned long *res);
221 int __must_check _kstrtol(const char *s, unsigned int base, long *res); 221 int __must_check _kstrtol(const char *s, unsigned int base, long *res);
222 222
223 int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res); 223 int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res);
224 int __must_check kstrtoll(const char *s, unsigned int base, long long *res); 224 int __must_check kstrtoll(const char *s, unsigned int base, long long *res);
225 225
226 /** 226 /**
227 * kstrtoul - convert a string to an unsigned long 227 * kstrtoul - convert a string to an unsigned long
228 * @s: The start of the string. The string must be null-terminated, and may also 228 * @s: The start of the string. The string must be null-terminated, and may also
229 * include a single newline before its terminating null. The first character 229 * include a single newline before its terminating null. The first character
230 * may also be a plus sign, but not a minus sign. 230 * may also be a plus sign, but not a minus sign.
231 * @base: The number base to use. The maximum supported base is 16. If base is 231 * @base: The number base to use. The maximum supported base is 16. If base is
232 * given as 0, then the base of the string is automatically detected with the 232 * given as 0, then the base of the string is automatically detected with the
233 * conventional semantics - If it begins with 0x the number will be parsed as a 233 * conventional semantics - If it begins with 0x the number will be parsed as a
234 * hexadecimal (case insensitive), if it otherwise begins with 0, it will be 234 * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
235 * parsed as an octal number. Otherwise it will be parsed as a decimal. 235 * parsed as an octal number. Otherwise it will be parsed as a decimal.
236 * @res: Where to write the result of the conversion on success. 236 * @res: Where to write the result of the conversion on success.
237 * 237 *
238 * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error. 238 * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
239 * Used as a replacement for the obsolete simple_strtoull. Return code must 239 * Used as a replacement for the obsolete simple_strtoull. Return code must
240 * be checked. 240 * be checked.
241 */ 241 */
242 static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res) 242 static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res)
243 { 243 {
244 /* 244 /*
245 * We want to shortcut function call, but 245 * We want to shortcut function call, but
246 * __builtin_types_compatible_p(unsigned long, unsigned long long) = 0. 246 * __builtin_types_compatible_p(unsigned long, unsigned long long) = 0.
247 */ 247 */
248 if (sizeof(unsigned long) == sizeof(unsigned long long) && 248 if (sizeof(unsigned long) == sizeof(unsigned long long) &&
249 __alignof__(unsigned long) == __alignof__(unsigned long long)) 249 __alignof__(unsigned long) == __alignof__(unsigned long long))
250 return kstrtoull(s, base, (unsigned long long *)res); 250 return kstrtoull(s, base, (unsigned long long *)res);
251 else 251 else
252 return _kstrtoul(s, base, res); 252 return _kstrtoul(s, base, res);
253 } 253 }
254 254
255 /** 255 /**
256 * kstrtol - convert a string to a long 256 * kstrtol - convert a string to a long
257 * @s: The start of the string. The string must be null-terminated, and may also 257 * @s: The start of the string. The string must be null-terminated, and may also
258 * include a single newline before its terminating null. The first character 258 * include a single newline before its terminating null. The first character
259 * may also be a plus sign or a minus sign. 259 * may also be a plus sign or a minus sign.
260 * @base: The number base to use. The maximum supported base is 16. If base is 260 * @base: The number base to use. The maximum supported base is 16. If base is
261 * given as 0, then the base of the string is automatically detected with the 261 * given as 0, then the base of the string is automatically detected with the
262 * conventional semantics - If it begins with 0x the number will be parsed as a 262 * conventional semantics - If it begins with 0x the number will be parsed as a
263 * hexadecimal (case insensitive), if it otherwise begins with 0, it will be 263 * hexadecimal (case insensitive), if it otherwise begins with 0, it will be
264 * parsed as an octal number. Otherwise it will be parsed as a decimal. 264 * parsed as an octal number. Otherwise it will be parsed as a decimal.
265 * @res: Where to write the result of the conversion on success. 265 * @res: Where to write the result of the conversion on success.
266 * 266 *
267 * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error. 267 * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
268 * Used as a replacement for the obsolete simple_strtoull. Return code must 268 * Used as a replacement for the obsolete simple_strtoull. Return code must
269 * be checked. 269 * be checked.
270 */ 270 */
271 static inline int __must_check kstrtol(const char *s, unsigned int base, long *res) 271 static inline int __must_check kstrtol(const char *s, unsigned int base, long *res)
272 { 272 {
273 /* 273 /*
274 * We want to shortcut function call, but 274 * We want to shortcut function call, but
275 * __builtin_types_compatible_p(long, long long) = 0. 275 * __builtin_types_compatible_p(long, long long) = 0.
276 */ 276 */
277 if (sizeof(long) == sizeof(long long) && 277 if (sizeof(long) == sizeof(long long) &&
278 __alignof__(long) == __alignof__(long long)) 278 __alignof__(long) == __alignof__(long long))
279 return kstrtoll(s, base, (long long *)res); 279 return kstrtoll(s, base, (long long *)res);
280 else 280 else
281 return _kstrtol(s, base, res); 281 return _kstrtol(s, base, res);
282 } 282 }
283 283
284 int __must_check kstrtouint(const char *s, unsigned int base, unsigned int *res); 284 int __must_check kstrtouint(const char *s, unsigned int base, unsigned int *res);
285 int __must_check kstrtoint(const char *s, unsigned int base, int *res); 285 int __must_check kstrtoint(const char *s, unsigned int base, int *res);
286 286
287 static inline int __must_check kstrtou64(const char *s, unsigned int base, u64 *res) 287 static inline int __must_check kstrtou64(const char *s, unsigned int base, u64 *res)
288 { 288 {
289 return kstrtoull(s, base, res); 289 return kstrtoull(s, base, res);
290 } 290 }
291 291
292 static inline int __must_check kstrtos64(const char *s, unsigned int base, s64 *res) 292 static inline int __must_check kstrtos64(const char *s, unsigned int base, s64 *res)
293 { 293 {
294 return kstrtoll(s, base, res); 294 return kstrtoll(s, base, res);
295 } 295 }
296 296
297 static inline int __must_check kstrtou32(const char *s, unsigned int base, u32 *res) 297 static inline int __must_check kstrtou32(const char *s, unsigned int base, u32 *res)
298 { 298 {
299 return kstrtouint(s, base, res); 299 return kstrtouint(s, base, res);
300 } 300 }
301 301
302 static inline int __must_check kstrtos32(const char *s, unsigned int base, s32 *res) 302 static inline int __must_check kstrtos32(const char *s, unsigned int base, s32 *res)
303 { 303 {
304 return kstrtoint(s, base, res); 304 return kstrtoint(s, base, res);
305 } 305 }
306 306
307 int __must_check kstrtou16(const char *s, unsigned int base, u16 *res); 307 int __must_check kstrtou16(const char *s, unsigned int base, u16 *res);
308 int __must_check kstrtos16(const char *s, unsigned int base, s16 *res); 308 int __must_check kstrtos16(const char *s, unsigned int base, s16 *res);
309 int __must_check kstrtou8(const char *s, unsigned int base, u8 *res); 309 int __must_check kstrtou8(const char *s, unsigned int base, u8 *res);
310 int __must_check kstrtos8(const char *s, unsigned int base, s8 *res); 310 int __must_check kstrtos8(const char *s, unsigned int base, s8 *res);
311 311
312 int __must_check kstrtoull_from_user(const char __user *s, size_t count, unsigned int base, unsigned long long *res); 312 int __must_check kstrtoull_from_user(const char __user *s, size_t count, unsigned int base, unsigned long long *res);
313 int __must_check kstrtoll_from_user(const char __user *s, size_t count, unsigned int base, long long *res); 313 int __must_check kstrtoll_from_user(const char __user *s, size_t count, unsigned int base, long long *res);
314 int __must_check kstrtoul_from_user(const char __user *s, size_t count, unsigned int base, unsigned long *res); 314 int __must_check kstrtoul_from_user(const char __user *s, size_t count, unsigned int base, unsigned long *res);
315 int __must_check kstrtol_from_user(const char __user *s, size_t count, unsigned int base, long *res); 315 int __must_check kstrtol_from_user(const char __user *s, size_t count, unsigned int base, long *res);
316 int __must_check kstrtouint_from_user(const char __user *s, size_t count, unsigned int base, unsigned int *res); 316 int __must_check kstrtouint_from_user(const char __user *s, size_t count, unsigned int base, unsigned int *res);
317 int __must_check kstrtoint_from_user(const char __user *s, size_t count, unsigned int base, int *res); 317 int __must_check kstrtoint_from_user(const char __user *s, size_t count, unsigned int base, int *res);
318 int __must_check kstrtou16_from_user(const char __user *s, size_t count, unsigned int base, u16 *res); 318 int __must_check kstrtou16_from_user(const char __user *s, size_t count, unsigned int base, u16 *res);
319 int __must_check kstrtos16_from_user(const char __user *s, size_t count, unsigned int base, s16 *res); 319 int __must_check kstrtos16_from_user(const char __user *s, size_t count, unsigned int base, s16 *res);
320 int __must_check kstrtou8_from_user(const char __user *s, size_t count, unsigned int base, u8 *res); 320 int __must_check kstrtou8_from_user(const char __user *s, size_t count, unsigned int base, u8 *res);
321 int __must_check kstrtos8_from_user(const char __user *s, size_t count, unsigned int base, s8 *res); 321 int __must_check kstrtos8_from_user(const char __user *s, size_t count, unsigned int base, s8 *res);
322 322
323 static inline int __must_check kstrtou64_from_user(const char __user *s, size_t count, unsigned int base, u64 *res) 323 static inline int __must_check kstrtou64_from_user(const char __user *s, size_t count, unsigned int base, u64 *res)
324 { 324 {
325 return kstrtoull_from_user(s, count, base, res); 325 return kstrtoull_from_user(s, count, base, res);
326 } 326 }
327 327
328 static inline int __must_check kstrtos64_from_user(const char __user *s, size_t count, unsigned int base, s64 *res) 328 static inline int __must_check kstrtos64_from_user(const char __user *s, size_t count, unsigned int base, s64 *res)
329 { 329 {
330 return kstrtoll_from_user(s, count, base, res); 330 return kstrtoll_from_user(s, count, base, res);
331 } 331 }
332 332
333 static inline int __must_check kstrtou32_from_user(const char __user *s, size_t count, unsigned int base, u32 *res) 333 static inline int __must_check kstrtou32_from_user(const char __user *s, size_t count, unsigned int base, u32 *res)
334 { 334 {
335 return kstrtouint_from_user(s, count, base, res); 335 return kstrtouint_from_user(s, count, base, res);
336 } 336 }
337 337
338 static inline int __must_check kstrtos32_from_user(const char __user *s, size_t count, unsigned int base, s32 *res) 338 static inline int __must_check kstrtos32_from_user(const char __user *s, size_t count, unsigned int base, s32 *res)
339 { 339 {
340 return kstrtoint_from_user(s, count, base, res); 340 return kstrtoint_from_user(s, count, base, res);
341 } 341 }
342 342
343 /* Obsolete, do not use. Use kstrto<foo> instead */ 343 /* Obsolete, do not use. Use kstrto<foo> instead */
344 344
345 extern unsigned long simple_strtoul(const char *,char **,unsigned int); 345 extern unsigned long simple_strtoul(const char *,char **,unsigned int);
346 extern long simple_strtol(const char *,char **,unsigned int); 346 extern long simple_strtol(const char *,char **,unsigned int);
347 extern unsigned long long simple_strtoull(const char *,char **,unsigned int); 347 extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
348 extern long long simple_strtoll(const char *,char **,unsigned int); 348 extern long long simple_strtoll(const char *,char **,unsigned int);
349 #define strict_strtoul kstrtoul 349 #define strict_strtoul kstrtoul
350 #define strict_strtol kstrtol 350 #define strict_strtol kstrtol
351 #define strict_strtoull kstrtoull 351 #define strict_strtoull kstrtoull
352 #define strict_strtoll kstrtoll 352 #define strict_strtoll kstrtoll
353 353
354 extern int num_to_str(char *buf, int size, unsigned long long num); 354 extern int num_to_str(char *buf, int size, unsigned long long num);
355 355
356 /* lib/printf utilities */ 356 /* lib/printf utilities */
357 357
358 extern __printf(2, 3) int sprintf(char *buf, const char * fmt, ...); 358 extern __printf(2, 3) int sprintf(char *buf, const char * fmt, ...);
359 extern __printf(2, 0) int vsprintf(char *buf, const char *, va_list); 359 extern __printf(2, 0) int vsprintf(char *buf, const char *, va_list);
360 extern __printf(3, 4) 360 extern __printf(3, 4)
361 int snprintf(char *buf, size_t size, const char *fmt, ...); 361 int snprintf(char *buf, size_t size, const char *fmt, ...);
362 extern __printf(3, 0) 362 extern __printf(3, 0)
363 int vsnprintf(char *buf, size_t size, const char *fmt, va_list args); 363 int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
364 extern __printf(3, 4) 364 extern __printf(3, 4)
365 int scnprintf(char *buf, size_t size, const char *fmt, ...); 365 int scnprintf(char *buf, size_t size, const char *fmt, ...);
366 extern __printf(3, 0) 366 extern __printf(3, 0)
367 int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); 367 int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
368 extern __printf(2, 3) 368 extern __printf(2, 3)
369 char *kasprintf(gfp_t gfp, const char *fmt, ...); 369 char *kasprintf(gfp_t gfp, const char *fmt, ...);
370 extern char *kvasprintf(gfp_t gfp, const char *fmt, va_list args); 370 extern char *kvasprintf(gfp_t gfp, const char *fmt, va_list args);
371 371
372 extern __scanf(2, 3) 372 extern __scanf(2, 3)
373 int sscanf(const char *, const char *, ...); 373 int sscanf(const char *, const char *, ...);
374 extern __scanf(2, 0) 374 extern __scanf(2, 0)
375 int vsscanf(const char *, const char *, va_list); 375 int vsscanf(const char *, const char *, va_list);
376 376
377 extern int get_option(char **str, int *pint); 377 extern int get_option(char **str, int *pint);
378 extern char *get_options(const char *str, int nints, int *ints); 378 extern char *get_options(const char *str, int nints, int *ints);
379 extern unsigned long long memparse(const char *ptr, char **retptr); 379 extern unsigned long long memparse(const char *ptr, char **retptr);
380 380
381 extern int core_kernel_text(unsigned long addr); 381 extern int core_kernel_text(unsigned long addr);
382 extern int core_kernel_data(unsigned long addr); 382 extern int core_kernel_data(unsigned long addr);
383 extern int __kernel_text_address(unsigned long addr); 383 extern int __kernel_text_address(unsigned long addr);
384 extern int kernel_text_address(unsigned long addr); 384 extern int kernel_text_address(unsigned long addr);
385 extern int func_ptr_is_kernel_text(void *ptr); 385 extern int func_ptr_is_kernel_text(void *ptr);
386 386
387 struct pid; 387 struct pid;
388 extern struct pid *session_of_pgrp(struct pid *pgrp); 388 extern struct pid *session_of_pgrp(struct pid *pgrp);
389 389
390 unsigned long int_sqrt(unsigned long); 390 unsigned long int_sqrt(unsigned long);
391 391
392 extern void bust_spinlocks(int yes); 392 extern void bust_spinlocks(int yes);
393 extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */ 393 extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */
394 extern int panic_timeout; 394 extern int panic_timeout;
395 extern int panic_on_oops; 395 extern int panic_on_oops;
396 extern int panic_on_unrecovered_nmi; 396 extern int panic_on_unrecovered_nmi;
397 extern int panic_on_io_nmi; 397 extern int panic_on_io_nmi;
398 extern int sysctl_panic_on_stackoverflow; 398 extern int sysctl_panic_on_stackoverflow;
399 extern const char *print_tainted(void); 399 extern const char *print_tainted(void);
400 enum lockdep_ok { 400 enum lockdep_ok {
401 LOCKDEP_STILL_OK, 401 LOCKDEP_STILL_OK,
402 LOCKDEP_NOW_UNRELIABLE 402 LOCKDEP_NOW_UNRELIABLE
403 }; 403 };
404 extern void add_taint(unsigned flag, enum lockdep_ok); 404 extern void add_taint(unsigned flag, enum lockdep_ok);
405 extern int test_taint(unsigned flag); 405 extern int test_taint(unsigned flag);
406 extern unsigned long get_taint(void); 406 extern unsigned long get_taint(void);
407 extern int root_mountflags; 407 extern int root_mountflags;
408 408
409 extern bool early_boot_irqs_disabled; 409 extern bool early_boot_irqs_disabled;
410 410
411 /* Values used for system_state */ 411 /* Values used for system_state */
412 extern enum system_states { 412 extern enum system_states {
413 SYSTEM_BOOTING, 413 SYSTEM_BOOTING,
414 SYSTEM_RUNNING, 414 SYSTEM_RUNNING,
415 SYSTEM_HALT, 415 SYSTEM_HALT,
416 SYSTEM_POWER_OFF, 416 SYSTEM_POWER_OFF,
417 SYSTEM_RESTART, 417 SYSTEM_RESTART,
418 } system_state; 418 } system_state;
419 419
420 #define TAINT_PROPRIETARY_MODULE 0 420 #define TAINT_PROPRIETARY_MODULE 0
421 #define TAINT_FORCED_MODULE 1 421 #define TAINT_FORCED_MODULE 1
422 #define TAINT_UNSAFE_SMP 2 422 #define TAINT_UNSAFE_SMP 2
423 #define TAINT_FORCED_RMMOD 3 423 #define TAINT_FORCED_RMMOD 3
424 #define TAINT_MACHINE_CHECK 4 424 #define TAINT_MACHINE_CHECK 4
425 #define TAINT_BAD_PAGE 5 425 #define TAINT_BAD_PAGE 5
426 #define TAINT_USER 6 426 #define TAINT_USER 6
427 #define TAINT_DIE 7 427 #define TAINT_DIE 7
428 #define TAINT_OVERRIDDEN_ACPI_TABLE 8 428 #define TAINT_OVERRIDDEN_ACPI_TABLE 8
429 #define TAINT_WARN 9 429 #define TAINT_WARN 9
430 #define TAINT_CRAP 10 430 #define TAINT_CRAP 10
431 #define TAINT_FIRMWARE_WORKAROUND 11 431 #define TAINT_FIRMWARE_WORKAROUND 11
432 #define TAINT_OOT_MODULE 12 432 #define TAINT_OOT_MODULE 12
433 433
434 extern const char hex_asc[]; 434 extern const char hex_asc[];
435 #define hex_asc_lo(x) hex_asc[((x) & 0x0f)] 435 #define hex_asc_lo(x) hex_asc[((x) & 0x0f)]
436 #define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4] 436 #define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4]
437 437
438 static inline char *hex_byte_pack(char *buf, u8 byte) 438 static inline char *hex_byte_pack(char *buf, u8 byte)
439 { 439 {
440 *buf++ = hex_asc_hi(byte); 440 *buf++ = hex_asc_hi(byte);
441 *buf++ = hex_asc_lo(byte); 441 *buf++ = hex_asc_lo(byte);
442 return buf; 442 return buf;
443 } 443 }
444 444
445 static inline char * __deprecated pack_hex_byte(char *buf, u8 byte) 445 static inline char * __deprecated pack_hex_byte(char *buf, u8 byte)
446 { 446 {
447 return hex_byte_pack(buf, byte); 447 return hex_byte_pack(buf, byte);
448 } 448 }
449 449
450 extern int hex_to_bin(char ch); 450 extern int hex_to_bin(char ch);
451 extern int __must_check hex2bin(u8 *dst, const char *src, size_t count); 451 extern int __must_check hex2bin(u8 *dst, const char *src, size_t count);
452 452
453 /* 453 /*
454 * General tracing related utility functions - trace_printk(), 454 * General tracing related utility functions - trace_printk(),
455 * tracing_on/tracing_off and tracing_start()/tracing_stop 455 * tracing_on/tracing_off and tracing_start()/tracing_stop
456 * 456 *
457 * Use tracing_on/tracing_off when you want to quickly turn on or off 457 * Use tracing_on/tracing_off when you want to quickly turn on or off
458 * tracing. It simply enables or disables the recording of the trace events. 458 * tracing. It simply enables or disables the recording of the trace events.
459 * This also corresponds to the user space /sys/kernel/debug/tracing/tracing_on 459 * This also corresponds to the user space /sys/kernel/debug/tracing/tracing_on
460 * file, which gives a means for the kernel and userspace to interact. 460 * file, which gives a means for the kernel and userspace to interact.
461 * Place a tracing_off() in the kernel where you want tracing to end. 461 * Place a tracing_off() in the kernel where you want tracing to end.
462 * From user space, examine the trace, and then echo 1 > tracing_on 462 * From user space, examine the trace, and then echo 1 > tracing_on
463 * to continue tracing. 463 * to continue tracing.
464 * 464 *
465 * tracing_stop/tracing_start has slightly more overhead. It is used 465 * tracing_stop/tracing_start has slightly more overhead. It is used
466 * by things like suspend to ram where disabling the recording of the 466 * by things like suspend to ram where disabling the recording of the
467 * trace is not enough, but tracing must actually stop because things 467 * trace is not enough, but tracing must actually stop because things
468 * like calling smp_processor_id() may crash the system. 468 * like calling smp_processor_id() may crash the system.
469 * 469 *
470 * Most likely, you want to use tracing_on/tracing_off. 470 * Most likely, you want to use tracing_on/tracing_off.
471 */ 471 */
472 #ifdef CONFIG_RING_BUFFER 472 #ifdef CONFIG_RING_BUFFER
473 /* trace_off_permanent stops recording with no way to bring it back */ 473 /* trace_off_permanent stops recording with no way to bring it back */
474 void tracing_off_permanent(void); 474 void tracing_off_permanent(void);
475 #else 475 #else
476 static inline void tracing_off_permanent(void) { } 476 static inline void tracing_off_permanent(void) { }
477 #endif 477 #endif
478 478
479 enum ftrace_dump_mode { 479 enum ftrace_dump_mode {
480 DUMP_NONE, 480 DUMP_NONE,
481 DUMP_ALL, 481 DUMP_ALL,
482 DUMP_ORIG, 482 DUMP_ORIG,
483 }; 483 };
484 484
485 #ifdef CONFIG_TRACING 485 #ifdef CONFIG_TRACING
486 void tracing_on(void); 486 void tracing_on(void);
487 void tracing_off(void); 487 void tracing_off(void);
488 int tracing_is_on(void); 488 int tracing_is_on(void);
489 void tracing_snapshot(void); 489 void tracing_snapshot(void);
490 void tracing_snapshot_alloc(void); 490 void tracing_snapshot_alloc(void);
491 491
492 extern void tracing_start(void); 492 extern void tracing_start(void);
493 extern void tracing_stop(void); 493 extern void tracing_stop(void);
494 extern void ftrace_off_permanent(void); 494 extern void ftrace_off_permanent(void);
495 495
496 static inline __printf(1, 2) 496 static inline __printf(1, 2)
497 void ____trace_printk_check_format(const char *fmt, ...) 497 void ____trace_printk_check_format(const char *fmt, ...)
498 { 498 {
499 } 499 }
500 #define __trace_printk_check_format(fmt, args...) \ 500 #define __trace_printk_check_format(fmt, args...) \
501 do { \ 501 do { \
502 if (0) \ 502 if (0) \
503 ____trace_printk_check_format(fmt, ##args); \ 503 ____trace_printk_check_format(fmt, ##args); \
504 } while (0) 504 } while (0)
505 505
506 /** 506 /**
507 * trace_printk - printf formatting in the ftrace buffer 507 * trace_printk - printf formatting in the ftrace buffer
508 * @fmt: the printf format for printing 508 * @fmt: the printf format for printing
509 * 509 *
510 * Note: __trace_printk is an internal function for trace_printk and 510 * Note: __trace_printk is an internal function for trace_printk and
511 * the @ip is passed in via the trace_printk macro. 511 * the @ip is passed in via the trace_printk macro.
512 * 512 *
513 * This function allows a kernel developer to debug fast path sections 513 * This function allows a kernel developer to debug fast path sections
514 * that printk is not appropriate for. By scattering in various 514 * that printk is not appropriate for. By scattering in various
515 * printk like tracing in the code, a developer can quickly see 515 * printk like tracing in the code, a developer can quickly see
516 * where problems are occurring. 516 * where problems are occurring.
517 * 517 *
518 * This is intended as a debugging tool for the developer only. 518 * This is intended as a debugging tool for the developer only.
519 * Please refrain from leaving trace_printks scattered around in 519 * Please refrain from leaving trace_printks scattered around in
520 * your code. (Extra memory is used for special buffers that are 520 * your code. (Extra memory is used for special buffers that are
521 * allocated when trace_printk() is used) 521 * allocated when trace_printk() is used)
522 * 522 *
523 * A little optization trick is done here. If there's only one 523 * A little optization trick is done here. If there's only one
524 * argument, there's no need to scan the string for printf formats. 524 * argument, there's no need to scan the string for printf formats.
525 * The trace_puts() will suffice. But how can we take advantage of 525 * The trace_puts() will suffice. But how can we take advantage of
526 * using trace_puts() when trace_printk() has only one argument? 526 * using trace_puts() when trace_printk() has only one argument?
527 * By stringifying the args and checking the size we can tell 527 * By stringifying the args and checking the size we can tell
528 * whether or not there are args. __stringify((__VA_ARGS__)) will 528 * whether or not there are args. __stringify((__VA_ARGS__)) will
529 * turn into "()\0" with a size of 3 when there are no args, anything 529 * turn into "()\0" with a size of 3 when there are no args, anything
530 * else will be bigger. All we need to do is define a string to this, 530 * else will be bigger. All we need to do is define a string to this,
531 * and then take its size and compare to 3. If it's bigger, use 531 * and then take its size and compare to 3. If it's bigger, use
532 * do_trace_printk() otherwise, optimize it to trace_puts(). Then just 532 * do_trace_printk() otherwise, optimize it to trace_puts(). Then just
533 * let gcc optimize the rest. 533 * let gcc optimize the rest.
534 */ 534 */
535 535
536 #define trace_printk(fmt, ...) \ 536 #define trace_printk(fmt, ...) \
537 do { \ 537 do { \
538 char _______STR[] = __stringify((__VA_ARGS__)); \ 538 char _______STR[] = __stringify((__VA_ARGS__)); \
539 if (sizeof(_______STR) > 3) \ 539 if (sizeof(_______STR) > 3) \
540 do_trace_printk(fmt, ##__VA_ARGS__); \ 540 do_trace_printk(fmt, ##__VA_ARGS__); \
541 else \ 541 else \
542 trace_puts(fmt); \ 542 trace_puts(fmt); \
543 } while (0) 543 } while (0)
544 544
545 #define do_trace_printk(fmt, args...) \ 545 #define do_trace_printk(fmt, args...) \
546 do { \ 546 do { \
547 static const char *trace_printk_fmt \ 547 static const char *trace_printk_fmt \
548 __attribute__((section("__trace_printk_fmt"))) = \ 548 __attribute__((section("__trace_printk_fmt"))) = \
549 __builtin_constant_p(fmt) ? fmt : NULL; \ 549 __builtin_constant_p(fmt) ? fmt : NULL; \
550 \ 550 \
551 __trace_printk_check_format(fmt, ##args); \ 551 __trace_printk_check_format(fmt, ##args); \
552 \ 552 \
553 if (__builtin_constant_p(fmt)) \ 553 if (__builtin_constant_p(fmt)) \
554 __trace_bprintk(_THIS_IP_, trace_printk_fmt, ##args); \ 554 __trace_bprintk(_THIS_IP_, trace_printk_fmt, ##args); \
555 else \ 555 else \
556 __trace_printk(_THIS_IP_, fmt, ##args); \ 556 __trace_printk(_THIS_IP_, fmt, ##args); \
557 } while (0) 557 } while (0)
558 558
559 extern __printf(2, 3) 559 extern __printf(2, 3)
560 int __trace_bprintk(unsigned long ip, const char *fmt, ...); 560 int __trace_bprintk(unsigned long ip, const char *fmt, ...);
561 561
562 extern __printf(2, 3) 562 extern __printf(2, 3)
563 int __trace_printk(unsigned long ip, const char *fmt, ...); 563 int __trace_printk(unsigned long ip, const char *fmt, ...);
564 564
565 /** 565 /**
566 * trace_puts - write a string into the ftrace buffer 566 * trace_puts - write a string into the ftrace buffer
567 * @str: the string to record 567 * @str: the string to record
568 * 568 *
569 * Note: __trace_bputs is an internal function for trace_puts and 569 * Note: __trace_bputs is an internal function for trace_puts and
570 * the @ip is passed in via the trace_puts macro. 570 * the @ip is passed in via the trace_puts macro.
571 * 571 *
572 * This is similar to trace_printk() but is made for those really fast 572 * This is similar to trace_printk() but is made for those really fast
573 * paths that a developer wants the least amount of "Heisenbug" affects, 573 * paths that a developer wants the least amount of "Heisenbug" affects,
574 * where the processing of the print format is still too much. 574 * where the processing of the print format is still too much.
575 * 575 *
576 * This function allows a kernel developer to debug fast path sections 576 * This function allows a kernel developer to debug fast path sections
577 * that printk is not appropriate for. By scattering in various 577 * that printk is not appropriate for. By scattering in various
578 * printk like tracing in the code, a developer can quickly see 578 * printk like tracing in the code, a developer can quickly see
579 * where problems are occurring. 579 * where problems are occurring.
580 * 580 *
581 * This is intended as a debugging tool for the developer only. 581 * This is intended as a debugging tool for the developer only.
582 * Please refrain from leaving trace_puts scattered around in 582 * Please refrain from leaving trace_puts scattered around in
583 * your code. (Extra memory is used for special buffers that are 583 * your code. (Extra memory is used for special buffers that are
584 * allocated when trace_puts() is used) 584 * allocated when trace_puts() is used)
585 * 585 *
586 * Returns: 0 if nothing was written, positive # if string was. 586 * Returns: 0 if nothing was written, positive # if string was.
587 * (1 when __trace_bputs is used, strlen(str) when __trace_puts is used) 587 * (1 when __trace_bputs is used, strlen(str) when __trace_puts is used)
588 */ 588 */
589 589
590 extern int __trace_bputs(unsigned long ip, const char *str); 590 extern int __trace_bputs(unsigned long ip, const char *str);
591 extern int __trace_puts(unsigned long ip, const char *str, int size); 591 extern int __trace_puts(unsigned long ip, const char *str, int size);
592 #define trace_puts(str) ({ \ 592 #define trace_puts(str) ({ \
593 static const char *trace_printk_fmt \ 593 static const char *trace_printk_fmt \
594 __attribute__((section("__trace_printk_fmt"))) = \ 594 __attribute__((section("__trace_printk_fmt"))) = \
595 __builtin_constant_p(str) ? str : NULL; \ 595 __builtin_constant_p(str) ? str : NULL; \
596 \ 596 \
597 if (__builtin_constant_p(str)) \ 597 if (__builtin_constant_p(str)) \
598 __trace_bputs(_THIS_IP_, trace_printk_fmt); \ 598 __trace_bputs(_THIS_IP_, trace_printk_fmt); \
599 else \ 599 else \
600 __trace_puts(_THIS_IP_, str, strlen(str)); \ 600 __trace_puts(_THIS_IP_, str, strlen(str)); \
601 }) 601 })
602 602
603 extern void trace_dump_stack(int skip); 603 extern void trace_dump_stack(int skip);
604 604
605 /* 605 /*
606 * The double __builtin_constant_p is because gcc will give us an error 606 * The double __builtin_constant_p is because gcc will give us an error
607 * if we try to allocate the static variable to fmt if it is not a 607 * if we try to allocate the static variable to fmt if it is not a
608 * constant. Even with the outer if statement. 608 * constant. Even with the outer if statement.
609 */ 609 */
610 #define ftrace_vprintk(fmt, vargs) \ 610 #define ftrace_vprintk(fmt, vargs) \
611 do { \ 611 do { \
612 if (__builtin_constant_p(fmt)) { \ 612 if (__builtin_constant_p(fmt)) { \
613 static const char *trace_printk_fmt \ 613 static const char *trace_printk_fmt \
614 __attribute__((section("__trace_printk_fmt"))) = \ 614 __attribute__((section("__trace_printk_fmt"))) = \
615 __builtin_constant_p(fmt) ? fmt : NULL; \ 615 __builtin_constant_p(fmt) ? fmt : NULL; \
616 \ 616 \
617 __ftrace_vbprintk(_THIS_IP_, trace_printk_fmt, vargs); \ 617 __ftrace_vbprintk(_THIS_IP_, trace_printk_fmt, vargs); \
618 } else \ 618 } else \
619 __ftrace_vprintk(_THIS_IP_, fmt, vargs); \ 619 __ftrace_vprintk(_THIS_IP_, fmt, vargs); \
620 } while (0) 620 } while (0)
621 621
622 extern int 622 extern int
623 __ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap); 623 __ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap);
624 624
625 extern int 625 extern int
626 __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap); 626 __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap);
627 627
628 extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode); 628 extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode);
629 #else 629 #else
630 static inline void tracing_start(void) { } 630 static inline void tracing_start(void) { }
631 static inline void tracing_stop(void) { } 631 static inline void tracing_stop(void) { }
632 static inline void ftrace_off_permanent(void) { } 632 static inline void ftrace_off_permanent(void) { }
633 static inline void trace_dump_stack(void) { } 633 static inline void trace_dump_stack(void) { }
634 634
635 static inline void tracing_on(void) { } 635 static inline void tracing_on(void) { }
636 static inline void tracing_off(void) { } 636 static inline void tracing_off(void) { }
637 static inline int tracing_is_on(void) { return 0; } 637 static inline int tracing_is_on(void) { return 0; }
638 static inline void tracing_snapshot(void) { } 638 static inline void tracing_snapshot(void) { }
639 static inline void tracing_snapshot_alloc(void) { } 639 static inline void tracing_snapshot_alloc(void) { }
640 640
641 static inline __printf(1, 2) 641 static inline __printf(1, 2)
642 int trace_printk(const char *fmt, ...) 642 int trace_printk(const char *fmt, ...)
643 { 643 {
644 return 0; 644 return 0;
645 } 645 }
646 static inline int 646 static inline int
647 ftrace_vprintk(const char *fmt, va_list ap) 647 ftrace_vprintk(const char *fmt, va_list ap)
648 { 648 {
649 return 0; 649 return 0;
650 } 650 }
651 static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { } 651 static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
652 #endif /* CONFIG_TRACING */ 652 #endif /* CONFIG_TRACING */
653 653
654 /* 654 /*
655 * min()/max()/clamp() macros that also do 655 * min()/max()/clamp() macros that also do
656 * strict type-checking.. See the 656 * strict type-checking.. See the
657 * "unnecessary" pointer comparison. 657 * "unnecessary" pointer comparison.
658 */ 658 */
659 #define min(x, y) ({ \ 659 #define min(x, y) ({ \
660 typeof(x) _min1 = (x); \ 660 typeof(x) _min1 = (x); \
661 typeof(y) _min2 = (y); \ 661 typeof(y) _min2 = (y); \
662 (void) (&_min1 == &_min2); \ 662 (void) (&_min1 == &_min2); \
663 _min1 < _min2 ? _min1 : _min2; }) 663 _min1 < _min2 ? _min1 : _min2; })
664 664
665 #define max(x, y) ({ \ 665 #define max(x, y) ({ \
666 typeof(x) _max1 = (x); \ 666 typeof(x) _max1 = (x); \
667 typeof(y) _max2 = (y); \ 667 typeof(y) _max2 = (y); \
668 (void) (&_max1 == &_max2); \ 668 (void) (&_max1 == &_max2); \
669 _max1 > _max2 ? _max1 : _max2; }) 669 _max1 > _max2 ? _max1 : _max2; })
670 670
671 #define min3(x, y, z) ({ \ 671 #define min3(x, y, z) ({ \
672 typeof(x) _min1 = (x); \ 672 typeof(x) _min1 = (x); \
673 typeof(y) _min2 = (y); \ 673 typeof(y) _min2 = (y); \
674 typeof(z) _min3 = (z); \ 674 typeof(z) _min3 = (z); \
675 (void) (&_min1 == &_min2); \ 675 (void) (&_min1 == &_min2); \
676 (void) (&_min1 == &_min3); \ 676 (void) (&_min1 == &_min3); \
677 _min1 < _min2 ? (_min1 < _min3 ? _min1 : _min3) : \ 677 _min1 < _min2 ? (_min1 < _min3 ? _min1 : _min3) : \
678 (_min2 < _min3 ? _min2 : _min3); }) 678 (_min2 < _min3 ? _min2 : _min3); })
679 679
680 #define max3(x, y, z) ({ \ 680 #define max3(x, y, z) ({ \
681 typeof(x) _max1 = (x); \ 681 typeof(x) _max1 = (x); \
682 typeof(y) _max2 = (y); \ 682 typeof(y) _max2 = (y); \
683 typeof(z) _max3 = (z); \ 683 typeof(z) _max3 = (z); \
684 (void) (&_max1 == &_max2); \ 684 (void) (&_max1 == &_max2); \
685 (void) (&_max1 == &_max3); \ 685 (void) (&_max1 == &_max3); \
686 _max1 > _max2 ? (_max1 > _max3 ? _max1 : _max3) : \ 686 _max1 > _max2 ? (_max1 > _max3 ? _max1 : _max3) : \
687 (_max2 > _max3 ? _max2 : _max3); }) 687 (_max2 > _max3 ? _max2 : _max3); })
688 688
689 /** 689 /**
690 * min_not_zero - return the minimum that is _not_ zero, unless both are zero 690 * min_not_zero - return the minimum that is _not_ zero, unless both are zero
691 * @x: value1 691 * @x: value1
692 * @y: value2 692 * @y: value2
693 */ 693 */
694 #define min_not_zero(x, y) ({ \ 694 #define min_not_zero(x, y) ({ \
695 typeof(x) __x = (x); \ 695 typeof(x) __x = (x); \
696 typeof(y) __y = (y); \ 696 typeof(y) __y = (y); \
697 __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); }) 697 __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); })
698 698
699 /** 699 /**
700 * clamp - return a value clamped to a given range with strict typechecking 700 * clamp - return a value clamped to a given range with strict typechecking
701 * @val: current value 701 * @val: current value
702 * @min: minimum allowable value 702 * @min: minimum allowable value
703 * @max: maximum allowable value 703 * @max: maximum allowable value
704 * 704 *
705 * This macro does strict typechecking of min/max to make sure they are of the 705 * This macro does strict typechecking of min/max to make sure they are of the
706 * same type as val. See the unnecessary pointer comparisons. 706 * same type as val. See the unnecessary pointer comparisons.
707 */ 707 */
708 #define clamp(val, min, max) ({ \ 708 #define clamp(val, min, max) ({ \
709 typeof(val) __val = (val); \ 709 typeof(val) __val = (val); \
710 typeof(min) __min = (min); \ 710 typeof(min) __min = (min); \
711 typeof(max) __max = (max); \ 711 typeof(max) __max = (max); \
712 (void) (&__val == &__min); \ 712 (void) (&__val == &__min); \
713 (void) (&__val == &__max); \ 713 (void) (&__val == &__max); \
714 __val = __val < __min ? __min: __val; \ 714 __val = __val < __min ? __min: __val; \
715 __val > __max ? __max: __val; }) 715 __val > __max ? __max: __val; })
716 716
717 /* 717 /*
718 * ..and if you can't take the strict 718 * ..and if you can't take the strict
719 * types, you can specify one yourself. 719 * types, you can specify one yourself.
720 * 720 *
721 * Or not use min/max/clamp at all, of course. 721 * Or not use min/max/clamp at all, of course.
722 */ 722 */
723 #define min_t(type, x, y) ({ \ 723 #define min_t(type, x, y) ({ \
724 type __min1 = (x); \ 724 type __min1 = (x); \
725 type __min2 = (y); \ 725 type __min2 = (y); \
726 __min1 < __min2 ? __min1: __min2; }) 726 __min1 < __min2 ? __min1: __min2; })
727 727
728 #define max_t(type, x, y) ({ \ 728 #define max_t(type, x, y) ({ \
729 type __max1 = (x); \ 729 type __max1 = (x); \
730 type __max2 = (y); \ 730 type __max2 = (y); \
731 __max1 > __max2 ? __max1: __max2; }) 731 __max1 > __max2 ? __max1: __max2; })
732 732
733 /** 733 /**
734 * clamp_t - return a value clamped to a given range using a given type 734 * clamp_t - return a value clamped to a given range using a given type
735 * @type: the type of variable to use 735 * @type: the type of variable to use
736 * @val: current value 736 * @val: current value
737 * @min: minimum allowable value 737 * @min: minimum allowable value
738 * @max: maximum allowable value 738 * @max: maximum allowable value
739 * 739 *
740 * This macro does no typechecking and uses temporary variables of type 740 * This macro does no typechecking and uses temporary variables of type
741 * 'type' to make all the comparisons. 741 * 'type' to make all the comparisons.
742 */ 742 */
743 #define clamp_t(type, val, min, max) ({ \ 743 #define clamp_t(type, val, min, max) ({ \
744 type __val = (val); \ 744 type __val = (val); \
745 type __min = (min); \ 745 type __min = (min); \
746 type __max = (max); \ 746 type __max = (max); \
747 __val = __val < __min ? __min: __val; \ 747 __val = __val < __min ? __min: __val; \
748 __val > __max ? __max: __val; }) 748 __val > __max ? __max: __val; })
749 749
750 /** 750 /**
751 * clamp_val - return a value clamped to a given range using val's type 751 * clamp_val - return a value clamped to a given range using val's type
752 * @val: current value 752 * @val: current value
753 * @min: minimum allowable value 753 * @min: minimum allowable value
754 * @max: maximum allowable value 754 * @max: maximum allowable value
755 * 755 *
756 * This macro does no typechecking and uses temporary variables of whatever 756 * This macro does no typechecking and uses temporary variables of whatever
757 * type the input argument 'val' is. This is useful when val is an unsigned 757 * type the input argument 'val' is. This is useful when val is an unsigned
758 * type and min and max are literals that will otherwise be assigned a signed 758 * type and min and max are literals that will otherwise be assigned a signed
759 * integer type. 759 * integer type.
760 */ 760 */
761 #define clamp_val(val, min, max) ({ \ 761 #define clamp_val(val, min, max) ({ \
762 typeof(val) __val = (val); \ 762 typeof(val) __val = (val); \
763 typeof(val) __min = (min); \ 763 typeof(val) __min = (min); \
764 typeof(val) __max = (max); \ 764 typeof(val) __max = (max); \
765 __val = __val < __min ? __min: __val; \ 765 __val = __val < __min ? __min: __val; \
766 __val > __max ? __max: __val; }) 766 __val > __max ? __max: __val; })
767 767
768 768
769 /* 769 /*
770 * swap - swap value of @a and @b 770 * swap - swap value of @a and @b
771 */ 771 */
772 #define swap(a, b) \ 772 #define swap(a, b) \
773 do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) 773 do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
774 774
775 /** 775 /**
776 * container_of - cast a member of a structure out to the containing structure 776 * container_of - cast a member of a structure out to the containing structure
777 * @ptr: the pointer to the member. 777 * @ptr: the pointer to the member.
778 * @type: the type of the container struct this is embedded in. 778 * @type: the type of the container struct this is embedded in.
779 * @member: the name of the member within the struct. 779 * @member: the name of the member within the struct.
780 * 780 *
781 */ 781 */
782 #define container_of(ptr, type, member) ({ \ 782 #define container_of(ptr, type, member) ({ \
783 const typeof( ((type *)0)->member ) *__mptr = (ptr); \ 783 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
784 (type *)( (char *)__mptr - offsetof(type,member) );}) 784 (type *)( (char *)__mptr - offsetof(type,member) );})
785 785
786 /* Trap pasters of __FUNCTION__ at compile-time */ 786 /* Trap pasters of __FUNCTION__ at compile-time */
787 #define __FUNCTION__ (__func__) 787 #define __FUNCTION__ (__func__)
788 788
789 /* This helps us to avoid #ifdef CONFIG_SYMBOL_PREFIX */
790 #ifdef CONFIG_SYMBOL_PREFIX
791 #define SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX
792 #else
793 #define SYMBOL_PREFIX ""
794 #endif
795
796 /* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */ 789 /* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */
797 #ifdef CONFIG_FTRACE_MCOUNT_RECORD 790 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
798 # define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD 791 # define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD
799 #endif 792 #endif
800 793
801 #endif 794 #endif
802 795
include/linux/linkage.h
1 #ifndef _LINUX_LINKAGE_H 1 #ifndef _LINUX_LINKAGE_H
2 #define _LINUX_LINKAGE_H 2 #define _LINUX_LINKAGE_H
3 3
4 #include <linux/compiler.h> 4 #include <linux/compiler.h>
5 #include <linux/stringify.h> 5 #include <linux/stringify.h>
6 #include <linux/export.h>
6 #include <asm/linkage.h> 7 #include <asm/linkage.h>
7 8
8 #ifdef __cplusplus 9 #ifdef __cplusplus
9 #define CPP_ASMLINKAGE extern "C" 10 #define CPP_ASMLINKAGE extern "C"
10 #else 11 #else
11 #define CPP_ASMLINKAGE 12 #define CPP_ASMLINKAGE
12 #endif 13 #endif
13 14
14 #ifndef asmlinkage 15 #ifndef asmlinkage
15 #define asmlinkage CPP_ASMLINKAGE 16 #define asmlinkage CPP_ASMLINKAGE
16 #endif 17 #endif
17 18
18 #ifdef CONFIG_SYMBOL_PREFIX
19 #define __SYMBOL_NAME(x) CONFIG_SYMBOL_PREFIX __stringify(x)
20 #else
21 #define __SYMBOL_NAME(x) __stringify(x)
22 #endif
23
24 #ifndef cond_syscall 19 #ifndef cond_syscall
25 #define cond_syscall(x) asm(".weak\t" __SYMBOL_NAME(x) \ 20 #define cond_syscall(x) asm( \
26 "\n\t.set\t" __SYMBOL_NAME(x) "," __SYMBOL_NAME(sys_ni_syscall)); 21 ".weak " VMLINUX_SYMBOL_STR(x) "\n\t" \
22 ".set " VMLINUX_SYMBOL_STR(x) "," \
23 VMLINUX_SYMBOL_STR(sys_ni_syscall))
27 #endif 24 #endif
28 25
29 #ifndef SYSCALL_ALIAS 26 #ifndef SYSCALL_ALIAS
30 #define SYSCALL_ALIAS(alias, name) \ 27 #define SYSCALL_ALIAS(alias, name) asm( \
31 asm ("\t.globl " __SYMBOL_NAME(alias) \ 28 ".globl " VMLINUX_SYMBOL_STR(alias) "\n\t" \
32 "\n\t.set\t" __SYMBOL_NAME(alias) "," __SYMBOL_NAME(name)) 29 ".set " VMLINUX_SYMBOL_STR(alias) "," \
30 VMLINUX_SYMBOL_STR(name))
33 #endif 31 #endif
34 32
35 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE) 33 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
36 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE) 34 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
37 35
38 /* 36 /*
39 * For assembly routines. 37 * For assembly routines.
40 * 38 *
41 * Note when using these that you must specify the appropriate 39 * Note when using these that you must specify the appropriate
42 * alignment directives yourself 40 * alignment directives yourself
43 */ 41 */
44 #define __PAGE_ALIGNED_DATA .section ".data..page_aligned", "aw" 42 #define __PAGE_ALIGNED_DATA .section ".data..page_aligned", "aw"
45 #define __PAGE_ALIGNED_BSS .section ".bss..page_aligned", "aw" 43 #define __PAGE_ALIGNED_BSS .section ".bss..page_aligned", "aw"
46 44
47 /* 45 /*
48 * This is used by architectures to keep arguments on the stack 46 * This is used by architectures to keep arguments on the stack
49 * untouched by the compiler by keeping them live until the end. 47 * untouched by the compiler by keeping them live until the end.
50 * The argument stack may be owned by the assembly-language 48 * The argument stack may be owned by the assembly-language
51 * caller, not the callee, and gcc doesn't always understand 49 * caller, not the callee, and gcc doesn't always understand
52 * that. 50 * that.
53 * 51 *
54 * We have the return value, and a maximum of six arguments. 52 * We have the return value, and a maximum of six arguments.
55 * 53 *
56 * This should always be followed by a "return ret" for the 54 * This should always be followed by a "return ret" for the
57 * protection to work (ie no more work that the compiler might 55 * protection to work (ie no more work that the compiler might
58 * end up needing stack temporaries for). 56 * end up needing stack temporaries for).
59 */ 57 */
60 /* Assembly files may be compiled with -traditional .. */ 58 /* Assembly files may be compiled with -traditional .. */
61 #ifndef __ASSEMBLY__ 59 #ifndef __ASSEMBLY__
62 #ifndef asmlinkage_protect 60 #ifndef asmlinkage_protect
63 # define asmlinkage_protect(n, ret, args...) do { } while (0) 61 # define asmlinkage_protect(n, ret, args...) do { } while (0)
64 #endif 62 #endif
65 #endif 63 #endif
66 64
67 #ifndef __ALIGN 65 #ifndef __ALIGN
68 #define __ALIGN .align 4,0x90 66 #define __ALIGN .align 4,0x90
69 #define __ALIGN_STR ".align 4,0x90" 67 #define __ALIGN_STR ".align 4,0x90"
70 #endif 68 #endif
71 69
72 #ifdef __ASSEMBLY__ 70 #ifdef __ASSEMBLY__
73 71
74 #ifndef LINKER_SCRIPT 72 #ifndef LINKER_SCRIPT
75 #define ALIGN __ALIGN 73 #define ALIGN __ALIGN
76 #define ALIGN_STR __ALIGN_STR 74 #define ALIGN_STR __ALIGN_STR
77 75
78 #ifndef ENTRY 76 #ifndef ENTRY
79 #define ENTRY(name) \ 77 #define ENTRY(name) \
80 .globl name; \ 78 .globl name; \
81 ALIGN; \ 79 ALIGN; \
82 name: 80 name:
83 #endif 81 #endif
84 #endif /* LINKER_SCRIPT */ 82 #endif /* LINKER_SCRIPT */
85 83
86 #ifndef WEAK 84 #ifndef WEAK
87 #define WEAK(name) \ 85 #define WEAK(name) \
88 .weak name; \ 86 .weak name; \
89 name: 87 name:
90 #endif 88 #endif
91 89
92 #ifndef END 90 #ifndef END
93 #define END(name) \ 91 #define END(name) \
94 .size name, .-name 92 .size name, .-name
95 #endif 93 #endif
96 94
97 /* If symbol 'name' is treated as a subroutine (gets called, and returns) 95 /* If symbol 'name' is treated as a subroutine (gets called, and returns)
98 * then please use ENDPROC to mark 'name' as STT_FUNC for the benefit of 96 * then please use ENDPROC to mark 'name' as STT_FUNC for the benefit of
99 * static analysis tools such as stack depth analyzer. 97 * static analysis tools such as stack depth analyzer.
100 */ 98 */
101 #ifndef ENDPROC 99 #ifndef ENDPROC
102 #define ENDPROC(name) \ 100 #define ENDPROC(name) \
103 .type name, @function; \ 101 .type name, @function; \
104 END(name) 102 END(name)
105 #endif 103 #endif
106 104
include/linux/module.h
1 #ifndef _LINUX_MODULE_H 1 #ifndef _LINUX_MODULE_H
2 #define _LINUX_MODULE_H 2 #define _LINUX_MODULE_H
3 /* 3 /*
4 * Dynamic loading of modules into the kernel. 4 * Dynamic loading of modules into the kernel.
5 * 5 *
6 * Rewritten by Richard Henderson <rth@tamu.edu> Dec 1996 6 * Rewritten by Richard Henderson <rth@tamu.edu> Dec 1996
7 * Rewritten again by Rusty Russell, 2002 7 * Rewritten again by Rusty Russell, 2002
8 */ 8 */
9 #include <linux/list.h> 9 #include <linux/list.h>
10 #include <linux/stat.h> 10 #include <linux/stat.h>
11 #include <linux/compiler.h> 11 #include <linux/compiler.h>
12 #include <linux/cache.h> 12 #include <linux/cache.h>
13 #include <linux/kmod.h> 13 #include <linux/kmod.h>
14 #include <linux/elf.h> 14 #include <linux/elf.h>
15 #include <linux/stringify.h> 15 #include <linux/stringify.h>
16 #include <linux/kobject.h> 16 #include <linux/kobject.h>
17 #include <linux/moduleparam.h> 17 #include <linux/moduleparam.h>
18 #include <linux/tracepoint.h> 18 #include <linux/tracepoint.h>
19 #include <linux/export.h> 19 #include <linux/export.h>
20 20
21 #include <linux/percpu.h> 21 #include <linux/percpu.h>
22 #include <asm/module.h> 22 #include <asm/module.h>
23 23
24 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */ 24 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
25 #define MODULE_SIG_STRING "~Module signature appended~\n" 25 #define MODULE_SIG_STRING "~Module signature appended~\n"
26 26
27 /* Not Yet Implemented */ 27 /* Not Yet Implemented */
28 #define MODULE_SUPPORTED_DEVICE(name) 28 #define MODULE_SUPPORTED_DEVICE(name)
29 29
30 #define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN 30 #define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN
31 31
32 struct modversion_info 32 struct modversion_info
33 { 33 {
34 unsigned long crc; 34 unsigned long crc;
35 char name[MODULE_NAME_LEN]; 35 char name[MODULE_NAME_LEN];
36 }; 36 };
37 37
38 struct module; 38 struct module;
39 39
40 struct module_kobject { 40 struct module_kobject {
41 struct kobject kobj; 41 struct kobject kobj;
42 struct module *mod; 42 struct module *mod;
43 struct kobject *drivers_dir; 43 struct kobject *drivers_dir;
44 struct module_param_attrs *mp; 44 struct module_param_attrs *mp;
45 }; 45 };
46 46
47 struct module_attribute { 47 struct module_attribute {
48 struct attribute attr; 48 struct attribute attr;
49 ssize_t (*show)(struct module_attribute *, struct module_kobject *, 49 ssize_t (*show)(struct module_attribute *, struct module_kobject *,
50 char *); 50 char *);
51 ssize_t (*store)(struct module_attribute *, struct module_kobject *, 51 ssize_t (*store)(struct module_attribute *, struct module_kobject *,
52 const char *, size_t count); 52 const char *, size_t count);
53 void (*setup)(struct module *, const char *); 53 void (*setup)(struct module *, const char *);
54 int (*test)(struct module *); 54 int (*test)(struct module *);
55 void (*free)(struct module *); 55 void (*free)(struct module *);
56 }; 56 };
57 57
58 struct module_version_attribute { 58 struct module_version_attribute {
59 struct module_attribute mattr; 59 struct module_attribute mattr;
60 const char *module_name; 60 const char *module_name;
61 const char *version; 61 const char *version;
62 } __attribute__ ((__aligned__(sizeof(void *)))); 62 } __attribute__ ((__aligned__(sizeof(void *))));
63 63
64 extern ssize_t __modver_version_show(struct module_attribute *, 64 extern ssize_t __modver_version_show(struct module_attribute *,
65 struct module_kobject *, char *); 65 struct module_kobject *, char *);
66 66
67 extern struct module_attribute module_uevent; 67 extern struct module_attribute module_uevent;
68 68
69 /* These are either module local, or the kernel's dummy ones. */ 69 /* These are either module local, or the kernel's dummy ones. */
70 extern int init_module(void); 70 extern int init_module(void);
71 extern void cleanup_module(void); 71 extern void cleanup_module(void);
72 72
73 /* Archs provide a method of finding the correct exception table. */ 73 /* Archs provide a method of finding the correct exception table. */
74 struct exception_table_entry; 74 struct exception_table_entry;
75 75
76 const struct exception_table_entry * 76 const struct exception_table_entry *
77 search_extable(const struct exception_table_entry *first, 77 search_extable(const struct exception_table_entry *first,
78 const struct exception_table_entry *last, 78 const struct exception_table_entry *last,
79 unsigned long value); 79 unsigned long value);
80 void sort_extable(struct exception_table_entry *start, 80 void sort_extable(struct exception_table_entry *start,
81 struct exception_table_entry *finish); 81 struct exception_table_entry *finish);
82 void sort_main_extable(void); 82 void sort_main_extable(void);
83 void trim_init_extable(struct module *m); 83 void trim_init_extable(struct module *m);
84 84
85 #ifdef MODULE 85 #ifdef MODULE
86 #define MODULE_GENERIC_TABLE(gtype,name) \ 86 #define MODULE_GENERIC_TABLE(gtype,name) \
87 extern const struct gtype##_id __mod_##gtype##_table \ 87 extern const struct gtype##_id __mod_##gtype##_table \
88 __attribute__ ((unused, alias(__stringify(name)))) 88 __attribute__ ((unused, alias(__stringify(name))))
89 89
90 #else /* !MODULE */ 90 #else /* !MODULE */
91 #define MODULE_GENERIC_TABLE(gtype,name) 91 #define MODULE_GENERIC_TABLE(gtype,name)
92 #endif 92 #endif
93 93
94 /* Generic info of form tag = "info" */ 94 /* Generic info of form tag = "info" */
95 #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info) 95 #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
96 96
97 /* For userspace: you can also call me... */ 97 /* For userspace: you can also call me... */
98 #define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias) 98 #define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias)
99 99
100 /* 100 /*
101 * The following license idents are currently accepted as indicating free 101 * The following license idents are currently accepted as indicating free
102 * software modules 102 * software modules
103 * 103 *
104 * "GPL" [GNU Public License v2 or later] 104 * "GPL" [GNU Public License v2 or later]
105 * "GPL v2" [GNU Public License v2] 105 * "GPL v2" [GNU Public License v2]
106 * "GPL and additional rights" [GNU Public License v2 rights and more] 106 * "GPL and additional rights" [GNU Public License v2 rights and more]
107 * "Dual BSD/GPL" [GNU Public License v2 107 * "Dual BSD/GPL" [GNU Public License v2
108 * or BSD license choice] 108 * or BSD license choice]
109 * "Dual MIT/GPL" [GNU Public License v2 109 * "Dual MIT/GPL" [GNU Public License v2
110 * or MIT license choice] 110 * or MIT license choice]
111 * "Dual MPL/GPL" [GNU Public License v2 111 * "Dual MPL/GPL" [GNU Public License v2
112 * or Mozilla license choice] 112 * or Mozilla license choice]
113 * 113 *
114 * The following other idents are available 114 * The following other idents are available
115 * 115 *
116 * "Proprietary" [Non free products] 116 * "Proprietary" [Non free products]
117 * 117 *
118 * There are dual licensed components, but when running with Linux it is the 118 * There are dual licensed components, but when running with Linux it is the
119 * GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL 119 * GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL
120 * is a GPL combined work. 120 * is a GPL combined work.
121 * 121 *
122 * This exists for several reasons 122 * This exists for several reasons
123 * 1. So modinfo can show license info for users wanting to vet their setup 123 * 1. So modinfo can show license info for users wanting to vet their setup
124 * is free 124 * is free
125 * 2. So the community can ignore bug reports including proprietary modules 125 * 2. So the community can ignore bug reports including proprietary modules
126 * 3. So vendors can do likewise based on their own policies 126 * 3. So vendors can do likewise based on their own policies
127 */ 127 */
128 #define MODULE_LICENSE(_license) MODULE_INFO(license, _license) 128 #define MODULE_LICENSE(_license) MODULE_INFO(license, _license)
129 129
130 /* 130 /*
131 * Author(s), use "Name <email>" or just "Name", for multiple 131 * Author(s), use "Name <email>" or just "Name", for multiple
132 * authors use multiple MODULE_AUTHOR() statements/lines. 132 * authors use multiple MODULE_AUTHOR() statements/lines.
133 */ 133 */
134 #define MODULE_AUTHOR(_author) MODULE_INFO(author, _author) 134 #define MODULE_AUTHOR(_author) MODULE_INFO(author, _author)
135 135
136 /* What your module does. */ 136 /* What your module does. */
137 #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description) 137 #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
138 138
139 #define MODULE_DEVICE_TABLE(type,name) \ 139 #define MODULE_DEVICE_TABLE(type,name) \
140 MODULE_GENERIC_TABLE(type##_device,name) 140 MODULE_GENERIC_TABLE(type##_device,name)
141 141
142 /* Version of form [<epoch>:]<version>[-<extra-version>]. 142 /* Version of form [<epoch>:]<version>[-<extra-version>].
143 Or for CVS/RCS ID version, everything but the number is stripped. 143 Or for CVS/RCS ID version, everything but the number is stripped.
144 <epoch>: A (small) unsigned integer which allows you to start versions 144 <epoch>: A (small) unsigned integer which allows you to start versions
145 anew. If not mentioned, it's zero. eg. "2:1.0" is after 145 anew. If not mentioned, it's zero. eg. "2:1.0" is after
146 "1:2.0". 146 "1:2.0".
147 <version>: The <version> may contain only alphanumerics and the 147 <version>: The <version> may contain only alphanumerics and the
148 character `.'. Ordered by numeric sort for numeric parts, 148 character `.'. Ordered by numeric sort for numeric parts,
149 ascii sort for ascii parts (as per RPM or DEB algorithm). 149 ascii sort for ascii parts (as per RPM or DEB algorithm).
150 <extraversion>: Like <version>, but inserted for local 150 <extraversion>: Like <version>, but inserted for local
151 customizations, eg "rh3" or "rusty1". 151 customizations, eg "rh3" or "rusty1".
152 152
153 Using this automatically adds a checksum of the .c files and the 153 Using this automatically adds a checksum of the .c files and the
154 local headers in "srcversion". 154 local headers in "srcversion".
155 */ 155 */
156 156
157 #if defined(MODULE) || !defined(CONFIG_SYSFS) 157 #if defined(MODULE) || !defined(CONFIG_SYSFS)
158 #define MODULE_VERSION(_version) MODULE_INFO(version, _version) 158 #define MODULE_VERSION(_version) MODULE_INFO(version, _version)
159 #else 159 #else
160 #define MODULE_VERSION(_version) \ 160 #define MODULE_VERSION(_version) \
161 static struct module_version_attribute ___modver_attr = { \ 161 static struct module_version_attribute ___modver_attr = { \
162 .mattr = { \ 162 .mattr = { \
163 .attr = { \ 163 .attr = { \
164 .name = "version", \ 164 .name = "version", \
165 .mode = S_IRUGO, \ 165 .mode = S_IRUGO, \
166 }, \ 166 }, \
167 .show = __modver_version_show, \ 167 .show = __modver_version_show, \
168 }, \ 168 }, \
169 .module_name = KBUILD_MODNAME, \ 169 .module_name = KBUILD_MODNAME, \
170 .version = _version, \ 170 .version = _version, \
171 }; \ 171 }; \
172 static const struct module_version_attribute \ 172 static const struct module_version_attribute \
173 __used __attribute__ ((__section__ ("__modver"))) \ 173 __used __attribute__ ((__section__ ("__modver"))) \
174 * __moduleparam_const __modver_attr = &___modver_attr 174 * __moduleparam_const __modver_attr = &___modver_attr
175 #endif 175 #endif
176 176
177 /* Optional firmware file (or files) needed by the module 177 /* Optional firmware file (or files) needed by the module
178 * format is simply firmware file name. Multiple firmware 178 * format is simply firmware file name. Multiple firmware
179 * files require multiple MODULE_FIRMWARE() specifiers */ 179 * files require multiple MODULE_FIRMWARE() specifiers */
180 #define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware) 180 #define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware)
181 181
182 /* Given an address, look for it in the exception tables */ 182 /* Given an address, look for it in the exception tables */
183 const struct exception_table_entry *search_exception_tables(unsigned long add); 183 const struct exception_table_entry *search_exception_tables(unsigned long add);
184 184
185 struct notifier_block; 185 struct notifier_block;
186 186
187 #ifdef CONFIG_MODULES 187 #ifdef CONFIG_MODULES
188 188
189 extern int modules_disabled; /* for sysctl */ 189 extern int modules_disabled; /* for sysctl */
190 /* Get/put a kernel symbol (calls must be symmetric) */ 190 /* Get/put a kernel symbol (calls must be symmetric) */
191 void *__symbol_get(const char *symbol); 191 void *__symbol_get(const char *symbol);
192 void *__symbol_get_gpl(const char *symbol); 192 void *__symbol_get_gpl(const char *symbol);
193 #define symbol_get(x) ((typeof(&x))(__symbol_get(MODULE_SYMBOL_PREFIX #x))) 193 #define symbol_get(x) ((typeof(&x))(__symbol_get(VMLINUX_SYMBOL_STR(x))))
194 194
195 /* modules using other modules: kdb wants to see this. */ 195 /* modules using other modules: kdb wants to see this. */
196 struct module_use { 196 struct module_use {
197 struct list_head source_list; 197 struct list_head source_list;
198 struct list_head target_list; 198 struct list_head target_list;
199 struct module *source, *target; 199 struct module *source, *target;
200 }; 200 };
201 201
202 enum module_state { 202 enum module_state {
203 MODULE_STATE_LIVE, /* Normal state. */ 203 MODULE_STATE_LIVE, /* Normal state. */
204 MODULE_STATE_COMING, /* Full formed, running module_init. */ 204 MODULE_STATE_COMING, /* Full formed, running module_init. */
205 MODULE_STATE_GOING, /* Going away. */ 205 MODULE_STATE_GOING, /* Going away. */
206 MODULE_STATE_UNFORMED, /* Still setting it up. */ 206 MODULE_STATE_UNFORMED, /* Still setting it up. */
207 }; 207 };
208 208
209 /** 209 /**
210 * struct module_ref - per cpu module reference counts 210 * struct module_ref - per cpu module reference counts
211 * @incs: number of module get on this cpu 211 * @incs: number of module get on this cpu
212 * @decs: number of module put on this cpu 212 * @decs: number of module put on this cpu
213 * 213 *
214 * We force an alignment on 8 or 16 bytes, so that alloc_percpu() 214 * We force an alignment on 8 or 16 bytes, so that alloc_percpu()
215 * put @incs/@decs in same cache line, with no extra memory cost, 215 * put @incs/@decs in same cache line, with no extra memory cost,
216 * since alloc_percpu() is fine grained. 216 * since alloc_percpu() is fine grained.
217 */ 217 */
218 struct module_ref { 218 struct module_ref {
219 unsigned long incs; 219 unsigned long incs;
220 unsigned long decs; 220 unsigned long decs;
221 } __attribute((aligned(2 * sizeof(unsigned long)))); 221 } __attribute((aligned(2 * sizeof(unsigned long))));
222 222
223 struct module 223 struct module
224 { 224 {
225 enum module_state state; 225 enum module_state state;
226 226
227 /* Member of list of modules */ 227 /* Member of list of modules */
228 struct list_head list; 228 struct list_head list;
229 229
230 /* Unique handle for this module */ 230 /* Unique handle for this module */
231 char name[MODULE_NAME_LEN]; 231 char name[MODULE_NAME_LEN];
232 232
233 /* Sysfs stuff. */ 233 /* Sysfs stuff. */
234 struct module_kobject mkobj; 234 struct module_kobject mkobj;
235 struct module_attribute *modinfo_attrs; 235 struct module_attribute *modinfo_attrs;
236 const char *version; 236 const char *version;
237 const char *srcversion; 237 const char *srcversion;
238 struct kobject *holders_dir; 238 struct kobject *holders_dir;
239 239
240 /* Exported symbols */ 240 /* Exported symbols */
241 const struct kernel_symbol *syms; 241 const struct kernel_symbol *syms;
242 const unsigned long *crcs; 242 const unsigned long *crcs;
243 unsigned int num_syms; 243 unsigned int num_syms;
244 244
245 /* Kernel parameters. */ 245 /* Kernel parameters. */
246 struct kernel_param *kp; 246 struct kernel_param *kp;
247 unsigned int num_kp; 247 unsigned int num_kp;
248 248
249 /* GPL-only exported symbols. */ 249 /* GPL-only exported symbols. */
250 unsigned int num_gpl_syms; 250 unsigned int num_gpl_syms;
251 const struct kernel_symbol *gpl_syms; 251 const struct kernel_symbol *gpl_syms;
252 const unsigned long *gpl_crcs; 252 const unsigned long *gpl_crcs;
253 253
254 #ifdef CONFIG_UNUSED_SYMBOLS 254 #ifdef CONFIG_UNUSED_SYMBOLS
255 /* unused exported symbols. */ 255 /* unused exported symbols. */
256 const struct kernel_symbol *unused_syms; 256 const struct kernel_symbol *unused_syms;
257 const unsigned long *unused_crcs; 257 const unsigned long *unused_crcs;
258 unsigned int num_unused_syms; 258 unsigned int num_unused_syms;
259 259
260 /* GPL-only, unused exported symbols. */ 260 /* GPL-only, unused exported symbols. */
261 unsigned int num_unused_gpl_syms; 261 unsigned int num_unused_gpl_syms;
262 const struct kernel_symbol *unused_gpl_syms; 262 const struct kernel_symbol *unused_gpl_syms;
263 const unsigned long *unused_gpl_crcs; 263 const unsigned long *unused_gpl_crcs;
264 #endif 264 #endif
265 265
266 #ifdef CONFIG_MODULE_SIG 266 #ifdef CONFIG_MODULE_SIG
267 /* Signature was verified. */ 267 /* Signature was verified. */
268 bool sig_ok; 268 bool sig_ok;
269 #endif 269 #endif
270 270
271 /* symbols that will be GPL-only in the near future. */ 271 /* symbols that will be GPL-only in the near future. */
272 const struct kernel_symbol *gpl_future_syms; 272 const struct kernel_symbol *gpl_future_syms;
273 const unsigned long *gpl_future_crcs; 273 const unsigned long *gpl_future_crcs;
274 unsigned int num_gpl_future_syms; 274 unsigned int num_gpl_future_syms;
275 275
276 /* Exception table */ 276 /* Exception table */
277 unsigned int num_exentries; 277 unsigned int num_exentries;
278 struct exception_table_entry *extable; 278 struct exception_table_entry *extable;
279 279
280 /* Startup function. */ 280 /* Startup function. */
281 int (*init)(void); 281 int (*init)(void);
282 282
283 /* If this is non-NULL, vfree after init() returns */ 283 /* If this is non-NULL, vfree after init() returns */
284 void *module_init; 284 void *module_init;
285 285
286 /* Here is the actual code + data, vfree'd on unload. */ 286 /* Here is the actual code + data, vfree'd on unload. */
287 void *module_core; 287 void *module_core;
288 288
289 /* Here are the sizes of the init and core sections */ 289 /* Here are the sizes of the init and core sections */
290 unsigned int init_size, core_size; 290 unsigned int init_size, core_size;
291 291
292 /* The size of the executable code in each section. */ 292 /* The size of the executable code in each section. */
293 unsigned int init_text_size, core_text_size; 293 unsigned int init_text_size, core_text_size;
294 294
295 /* Size of RO sections of the module (text+rodata) */ 295 /* Size of RO sections of the module (text+rodata) */
296 unsigned int init_ro_size, core_ro_size; 296 unsigned int init_ro_size, core_ro_size;
297 297
298 /* Arch-specific module values */ 298 /* Arch-specific module values */
299 struct mod_arch_specific arch; 299 struct mod_arch_specific arch;
300 300
301 unsigned int taints; /* same bits as kernel:tainted */ 301 unsigned int taints; /* same bits as kernel:tainted */
302 302
303 #ifdef CONFIG_GENERIC_BUG 303 #ifdef CONFIG_GENERIC_BUG
304 /* Support for BUG */ 304 /* Support for BUG */
305 unsigned num_bugs; 305 unsigned num_bugs;
306 struct list_head bug_list; 306 struct list_head bug_list;
307 struct bug_entry *bug_table; 307 struct bug_entry *bug_table;
308 #endif 308 #endif
309 309
310 #ifdef CONFIG_KALLSYMS 310 #ifdef CONFIG_KALLSYMS
311 /* 311 /*
312 * We keep the symbol and string tables for kallsyms. 312 * We keep the symbol and string tables for kallsyms.
313 * The core_* fields below are temporary, loader-only (they 313 * The core_* fields below are temporary, loader-only (they
314 * could really be discarded after module init). 314 * could really be discarded after module init).
315 */ 315 */
316 Elf_Sym *symtab, *core_symtab; 316 Elf_Sym *symtab, *core_symtab;
317 unsigned int num_symtab, core_num_syms; 317 unsigned int num_symtab, core_num_syms;
318 char *strtab, *core_strtab; 318 char *strtab, *core_strtab;
319 319
320 /* Section attributes */ 320 /* Section attributes */
321 struct module_sect_attrs *sect_attrs; 321 struct module_sect_attrs *sect_attrs;
322 322
323 /* Notes attributes */ 323 /* Notes attributes */
324 struct module_notes_attrs *notes_attrs; 324 struct module_notes_attrs *notes_attrs;
325 #endif 325 #endif
326 326
327 /* The command line arguments (may be mangled). People like 327 /* The command line arguments (may be mangled). People like
328 keeping pointers to this stuff */ 328 keeping pointers to this stuff */
329 char *args; 329 char *args;
330 330
331 #ifdef CONFIG_SMP 331 #ifdef CONFIG_SMP
332 /* Per-cpu data. */ 332 /* Per-cpu data. */
333 void __percpu *percpu; 333 void __percpu *percpu;
334 unsigned int percpu_size; 334 unsigned int percpu_size;
335 #endif 335 #endif
336 336
337 #ifdef CONFIG_TRACEPOINTS 337 #ifdef CONFIG_TRACEPOINTS
338 unsigned int num_tracepoints; 338 unsigned int num_tracepoints;
339 struct tracepoint * const *tracepoints_ptrs; 339 struct tracepoint * const *tracepoints_ptrs;
340 #endif 340 #endif
341 #ifdef HAVE_JUMP_LABEL 341 #ifdef HAVE_JUMP_LABEL
342 struct jump_entry *jump_entries; 342 struct jump_entry *jump_entries;
343 unsigned int num_jump_entries; 343 unsigned int num_jump_entries;
344 #endif 344 #endif
345 #ifdef CONFIG_TRACING 345 #ifdef CONFIG_TRACING
346 unsigned int num_trace_bprintk_fmt; 346 unsigned int num_trace_bprintk_fmt;
347 const char **trace_bprintk_fmt_start; 347 const char **trace_bprintk_fmt_start;
348 #endif 348 #endif
349 #ifdef CONFIG_EVENT_TRACING 349 #ifdef CONFIG_EVENT_TRACING
350 struct ftrace_event_call **trace_events; 350 struct ftrace_event_call **trace_events;
351 unsigned int num_trace_events; 351 unsigned int num_trace_events;
352 #endif 352 #endif
353 #ifdef CONFIG_FTRACE_MCOUNT_RECORD 353 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
354 unsigned int num_ftrace_callsites; 354 unsigned int num_ftrace_callsites;
355 unsigned long *ftrace_callsites; 355 unsigned long *ftrace_callsites;
356 #endif 356 #endif
357 357
358 #ifdef CONFIG_MODULE_UNLOAD 358 #ifdef CONFIG_MODULE_UNLOAD
359 /* What modules depend on me? */ 359 /* What modules depend on me? */
360 struct list_head source_list; 360 struct list_head source_list;
361 /* What modules do I depend on? */ 361 /* What modules do I depend on? */
362 struct list_head target_list; 362 struct list_head target_list;
363 363
364 /* Who is waiting for us to be unloaded */ 364 /* Who is waiting for us to be unloaded */
365 struct task_struct *waiter; 365 struct task_struct *waiter;
366 366
367 /* Destruction function. */ 367 /* Destruction function. */
368 void (*exit)(void); 368 void (*exit)(void);
369 369
370 struct module_ref __percpu *refptr; 370 struct module_ref __percpu *refptr;
371 #endif 371 #endif
372 372
373 #ifdef CONFIG_CONSTRUCTORS 373 #ifdef CONFIG_CONSTRUCTORS
374 /* Constructor functions. */ 374 /* Constructor functions. */
375 ctor_fn_t *ctors; 375 ctor_fn_t *ctors;
376 unsigned int num_ctors; 376 unsigned int num_ctors;
377 #endif 377 #endif
378 }; 378 };
379 #ifndef MODULE_ARCH_INIT 379 #ifndef MODULE_ARCH_INIT
380 #define MODULE_ARCH_INIT {} 380 #define MODULE_ARCH_INIT {}
381 #endif 381 #endif
382 382
383 extern struct mutex module_mutex; 383 extern struct mutex module_mutex;
384 384
385 /* FIXME: It'd be nice to isolate modules during init, too, so they 385 /* FIXME: It'd be nice to isolate modules during init, too, so they
386 aren't used before they (may) fail. But presently too much code 386 aren't used before they (may) fail. But presently too much code
387 (IDE & SCSI) require entry into the module during init.*/ 387 (IDE & SCSI) require entry into the module during init.*/
388 static inline int module_is_live(struct module *mod) 388 static inline int module_is_live(struct module *mod)
389 { 389 {
390 return mod->state != MODULE_STATE_GOING; 390 return mod->state != MODULE_STATE_GOING;
391 } 391 }
392 392
393 struct module *__module_text_address(unsigned long addr); 393 struct module *__module_text_address(unsigned long addr);
394 struct module *__module_address(unsigned long addr); 394 struct module *__module_address(unsigned long addr);
395 bool is_module_address(unsigned long addr); 395 bool is_module_address(unsigned long addr);
396 bool is_module_percpu_address(unsigned long addr); 396 bool is_module_percpu_address(unsigned long addr);
397 bool is_module_text_address(unsigned long addr); 397 bool is_module_text_address(unsigned long addr);
398 398
399 static inline int within_module_core(unsigned long addr, const struct module *mod) 399 static inline int within_module_core(unsigned long addr, const struct module *mod)
400 { 400 {
401 return (unsigned long)mod->module_core <= addr && 401 return (unsigned long)mod->module_core <= addr &&
402 addr < (unsigned long)mod->module_core + mod->core_size; 402 addr < (unsigned long)mod->module_core + mod->core_size;
403 } 403 }
404 404
405 static inline int within_module_init(unsigned long addr, const struct module *mod) 405 static inline int within_module_init(unsigned long addr, const struct module *mod)
406 { 406 {
407 return (unsigned long)mod->module_init <= addr && 407 return (unsigned long)mod->module_init <= addr &&
408 addr < (unsigned long)mod->module_init + mod->init_size; 408 addr < (unsigned long)mod->module_init + mod->init_size;
409 } 409 }
410 410
411 /* Search for module by name: must hold module_mutex. */ 411 /* Search for module by name: must hold module_mutex. */
412 struct module *find_module(const char *name); 412 struct module *find_module(const char *name);
413 413
414 struct symsearch { 414 struct symsearch {
415 const struct kernel_symbol *start, *stop; 415 const struct kernel_symbol *start, *stop;
416 const unsigned long *crcs; 416 const unsigned long *crcs;
417 enum { 417 enum {
418 NOT_GPL_ONLY, 418 NOT_GPL_ONLY,
419 GPL_ONLY, 419 GPL_ONLY,
420 WILL_BE_GPL_ONLY, 420 WILL_BE_GPL_ONLY,
421 } licence; 421 } licence;
422 bool unused; 422 bool unused;
423 }; 423 };
424 424
425 /* Search for an exported symbol by name. */ 425 /* Search for an exported symbol by name. */
426 const struct kernel_symbol *find_symbol(const char *name, 426 const struct kernel_symbol *find_symbol(const char *name,
427 struct module **owner, 427 struct module **owner,
428 const unsigned long **crc, 428 const unsigned long **crc,
429 bool gplok, 429 bool gplok,
430 bool warn); 430 bool warn);
431 431
432 /* Walk the exported symbol table */ 432 /* Walk the exported symbol table */
433 bool each_symbol_section(bool (*fn)(const struct symsearch *arr, 433 bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
434 struct module *owner, 434 struct module *owner,
435 void *data), void *data); 435 void *data), void *data);
436 436
437 /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if 437 /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if
438 symnum out of range. */ 438 symnum out of range. */
439 int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, 439 int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
440 char *name, char *module_name, int *exported); 440 char *name, char *module_name, int *exported);
441 441
442 /* Look for this name: can be of form module:name. */ 442 /* Look for this name: can be of form module:name. */
443 unsigned long module_kallsyms_lookup_name(const char *name); 443 unsigned long module_kallsyms_lookup_name(const char *name);
444 444
445 int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *, 445 int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
446 struct module *, unsigned long), 446 struct module *, unsigned long),
447 void *data); 447 void *data);
448 448
449 extern void __module_put_and_exit(struct module *mod, long code) 449 extern void __module_put_and_exit(struct module *mod, long code)
450 __attribute__((noreturn)); 450 __attribute__((noreturn));
451 #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code); 451 #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code);
452 452
453 #ifdef CONFIG_MODULE_UNLOAD 453 #ifdef CONFIG_MODULE_UNLOAD
454 unsigned long module_refcount(struct module *mod); 454 unsigned long module_refcount(struct module *mod);
455 void __symbol_put(const char *symbol); 455 void __symbol_put(const char *symbol);
456 #define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x) 456 #define symbol_put(x) __symbol_put(VMLINUX_SYMBOL_STR(x))
457 void symbol_put_addr(void *addr); 457 void symbol_put_addr(void *addr);
458 458
459 /* Sometimes we know we already have a refcount, and it's easier not 459 /* Sometimes we know we already have a refcount, and it's easier not
460 to handle the error case (which only happens with rmmod --wait). */ 460 to handle the error case (which only happens with rmmod --wait). */
461 extern void __module_get(struct module *module); 461 extern void __module_get(struct module *module);
462 462
463 /* This is the Right Way to get a module: if it fails, it's being removed, 463 /* This is the Right Way to get a module: if it fails, it's being removed,
464 * so pretend it's not there. */ 464 * so pretend it's not there. */
465 extern bool try_module_get(struct module *module); 465 extern bool try_module_get(struct module *module);
466 466
467 extern void module_put(struct module *module); 467 extern void module_put(struct module *module);
468 468
469 #else /*!CONFIG_MODULE_UNLOAD*/ 469 #else /*!CONFIG_MODULE_UNLOAD*/
470 static inline int try_module_get(struct module *module) 470 static inline int try_module_get(struct module *module)
471 { 471 {
472 return !module || module_is_live(module); 472 return !module || module_is_live(module);
473 } 473 }
474 static inline void module_put(struct module *module) 474 static inline void module_put(struct module *module)
475 { 475 {
476 } 476 }
477 static inline void __module_get(struct module *module) 477 static inline void __module_get(struct module *module)
478 { 478 {
479 } 479 }
480 #define symbol_put(x) do { } while(0) 480 #define symbol_put(x) do { } while(0)
481 #define symbol_put_addr(p) do { } while(0) 481 #define symbol_put_addr(p) do { } while(0)
482 482
483 #endif /* CONFIG_MODULE_UNLOAD */ 483 #endif /* CONFIG_MODULE_UNLOAD */
484 int ref_module(struct module *a, struct module *b); 484 int ref_module(struct module *a, struct module *b);
485 485
486 /* This is a #define so the string doesn't get put in every .o file */ 486 /* This is a #define so the string doesn't get put in every .o file */
487 #define module_name(mod) \ 487 #define module_name(mod) \
488 ({ \ 488 ({ \
489 struct module *__mod = (mod); \ 489 struct module *__mod = (mod); \
490 __mod ? __mod->name : "kernel"; \ 490 __mod ? __mod->name : "kernel"; \
491 }) 491 })
492 492
493 /* For kallsyms to ask for address resolution. namebuf should be at 493 /* For kallsyms to ask for address resolution. namebuf should be at
494 * least KSYM_NAME_LEN long: a pointer to namebuf is returned if 494 * least KSYM_NAME_LEN long: a pointer to namebuf is returned if
495 * found, otherwise NULL. */ 495 * found, otherwise NULL. */
496 const char *module_address_lookup(unsigned long addr, 496 const char *module_address_lookup(unsigned long addr,
497 unsigned long *symbolsize, 497 unsigned long *symbolsize,
498 unsigned long *offset, 498 unsigned long *offset,
499 char **modname, 499 char **modname,
500 char *namebuf); 500 char *namebuf);
501 int lookup_module_symbol_name(unsigned long addr, char *symname); 501 int lookup_module_symbol_name(unsigned long addr, char *symname);
502 int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name); 502 int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name);
503 503
504 /* For extable.c to search modules' exception tables. */ 504 /* For extable.c to search modules' exception tables. */
505 const struct exception_table_entry *search_module_extables(unsigned long addr); 505 const struct exception_table_entry *search_module_extables(unsigned long addr);
506 506
507 int register_module_notifier(struct notifier_block * nb); 507 int register_module_notifier(struct notifier_block * nb);
508 int unregister_module_notifier(struct notifier_block * nb); 508 int unregister_module_notifier(struct notifier_block * nb);
509 509
510 extern void print_modules(void); 510 extern void print_modules(void);
511 511
512 #else /* !CONFIG_MODULES... */ 512 #else /* !CONFIG_MODULES... */
513 513
514 /* Given an address, look for it in the exception tables. */ 514 /* Given an address, look for it in the exception tables. */
515 static inline const struct exception_table_entry * 515 static inline const struct exception_table_entry *
516 search_module_extables(unsigned long addr) 516 search_module_extables(unsigned long addr)
517 { 517 {
518 return NULL; 518 return NULL;
519 } 519 }
520 520
521 static inline struct module *__module_address(unsigned long addr) 521 static inline struct module *__module_address(unsigned long addr)
522 { 522 {
523 return NULL; 523 return NULL;
524 } 524 }
525 525
526 static inline struct module *__module_text_address(unsigned long addr) 526 static inline struct module *__module_text_address(unsigned long addr)
527 { 527 {
528 return NULL; 528 return NULL;
529 } 529 }
530 530
531 static inline bool is_module_address(unsigned long addr) 531 static inline bool is_module_address(unsigned long addr)
532 { 532 {
533 return false; 533 return false;
534 } 534 }
535 535
536 static inline bool is_module_percpu_address(unsigned long addr) 536 static inline bool is_module_percpu_address(unsigned long addr)
537 { 537 {
538 return false; 538 return false;
539 } 539 }
540 540
541 static inline bool is_module_text_address(unsigned long addr) 541 static inline bool is_module_text_address(unsigned long addr)
542 { 542 {
543 return false; 543 return false;
544 } 544 }
545 545
546 /* Get/put a kernel symbol (calls should be symmetric) */ 546 /* Get/put a kernel symbol (calls should be symmetric) */
547 #define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); }) 547 #define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); })
548 #define symbol_put(x) do { } while(0) 548 #define symbol_put(x) do { } while(0)
549 #define symbol_put_addr(x) do { } while(0) 549 #define symbol_put_addr(x) do { } while(0)
550 550
551 static inline void __module_get(struct module *module) 551 static inline void __module_get(struct module *module)
552 { 552 {
553 } 553 }
554 554
555 static inline int try_module_get(struct module *module) 555 static inline int try_module_get(struct module *module)
556 { 556 {
557 return 1; 557 return 1;
558 } 558 }
559 559
560 static inline void module_put(struct module *module) 560 static inline void module_put(struct module *module)
561 { 561 {
562 } 562 }
563 563
564 #define module_name(mod) "kernel" 564 #define module_name(mod) "kernel"
565 565
566 /* For kallsyms to ask for address resolution. NULL means not found. */ 566 /* For kallsyms to ask for address resolution. NULL means not found. */
567 static inline const char *module_address_lookup(unsigned long addr, 567 static inline const char *module_address_lookup(unsigned long addr,
568 unsigned long *symbolsize, 568 unsigned long *symbolsize,
569 unsigned long *offset, 569 unsigned long *offset,
570 char **modname, 570 char **modname,
571 char *namebuf) 571 char *namebuf)
572 { 572 {
573 return NULL; 573 return NULL;
574 } 574 }
575 575
576 static inline int lookup_module_symbol_name(unsigned long addr, char *symname) 576 static inline int lookup_module_symbol_name(unsigned long addr, char *symname)
577 { 577 {
578 return -ERANGE; 578 return -ERANGE;
579 } 579 }
580 580
581 static inline int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name) 581 static inline int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long *offset, char *modname, char *name)
582 { 582 {
583 return -ERANGE; 583 return -ERANGE;
584 } 584 }
585 585
586 static inline int module_get_kallsym(unsigned int symnum, unsigned long *value, 586 static inline int module_get_kallsym(unsigned int symnum, unsigned long *value,
587 char *type, char *name, 587 char *type, char *name,
588 char *module_name, int *exported) 588 char *module_name, int *exported)
589 { 589 {
590 return -ERANGE; 590 return -ERANGE;
591 } 591 }
592 592
593 static inline unsigned long module_kallsyms_lookup_name(const char *name) 593 static inline unsigned long module_kallsyms_lookup_name(const char *name)
594 { 594 {
595 return 0; 595 return 0;
596 } 596 }
597 597
598 static inline int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *, 598 static inline int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
599 struct module *, 599 struct module *,
600 unsigned long), 600 unsigned long),
601 void *data) 601 void *data)
602 { 602 {
603 return 0; 603 return 0;
604 } 604 }
605 605
606 static inline int register_module_notifier(struct notifier_block * nb) 606 static inline int register_module_notifier(struct notifier_block * nb)
607 { 607 {
608 /* no events will happen anyway, so this can always succeed */ 608 /* no events will happen anyway, so this can always succeed */
609 return 0; 609 return 0;
610 } 610 }
611 611
612 static inline int unregister_module_notifier(struct notifier_block * nb) 612 static inline int unregister_module_notifier(struct notifier_block * nb)
613 { 613 {
614 return 0; 614 return 0;
615 } 615 }
616 616
617 #define module_put_and_exit(code) do_exit(code) 617 #define module_put_and_exit(code) do_exit(code)
618 618
619 static inline void print_modules(void) 619 static inline void print_modules(void)
620 { 620 {
621 } 621 }
622 #endif /* CONFIG_MODULES */ 622 #endif /* CONFIG_MODULES */
623 623
624 #ifdef CONFIG_SYSFS 624 #ifdef CONFIG_SYSFS
625 extern struct kset *module_kset; 625 extern struct kset *module_kset;
626 extern struct kobj_type module_ktype; 626 extern struct kobj_type module_ktype;
627 extern int module_sysfs_initialized; 627 extern int module_sysfs_initialized;
628 #endif /* CONFIG_SYSFS */ 628 #endif /* CONFIG_SYSFS */
629 629
630 #define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x) 630 #define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x)
631 631
632 /* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */ 632 /* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */
633 633
634 #define __MODULE_STRING(x) __stringify(x) 634 #define __MODULE_STRING(x) __stringify(x)
635 635
636 #ifdef CONFIG_DEBUG_SET_MODULE_RONX 636 #ifdef CONFIG_DEBUG_SET_MODULE_RONX
637 extern void set_all_modules_text_rw(void); 637 extern void set_all_modules_text_rw(void);
638 extern void set_all_modules_text_ro(void); 638 extern void set_all_modules_text_ro(void);
639 #else 639 #else
640 static inline void set_all_modules_text_rw(void) { } 640 static inline void set_all_modules_text_rw(void) { }
641 static inline void set_all_modules_text_ro(void) { } 641 static inline void set_all_modules_text_ro(void) { }
642 #endif 642 #endif
643 643
644 #ifdef CONFIG_GENERIC_BUG 644 #ifdef CONFIG_GENERIC_BUG
645 void module_bug_finalize(const Elf_Ehdr *, const Elf_Shdr *, 645 void module_bug_finalize(const Elf_Ehdr *, const Elf_Shdr *,
646 struct module *); 646 struct module *);
647 void module_bug_cleanup(struct module *); 647 void module_bug_cleanup(struct module *);
648 648
649 #else /* !CONFIG_GENERIC_BUG */ 649 #else /* !CONFIG_GENERIC_BUG */
650 650
651 static inline void module_bug_finalize(const Elf_Ehdr *hdr, 651 static inline void module_bug_finalize(const Elf_Ehdr *hdr,
652 const Elf_Shdr *sechdrs, 652 const Elf_Shdr *sechdrs,
653 struct module *mod) 653 struct module *mod)
654 { 654 {
655 } 655 }
656 static inline void module_bug_cleanup(struct module *mod) {} 656 static inline void module_bug_cleanup(struct module *mod) {}
657 #endif /* CONFIG_GENERIC_BUG */ 657 #endif /* CONFIG_GENERIC_BUG */
658 658
659 #endif /* _LINUX_MODULE_H */ 659 #endif /* _LINUX_MODULE_H */
660 660
1 # 1 #
2 # Makefile for the linux kernel. 2 # Makefile for the linux kernel.
3 # 3 #
4 4
5 obj-y = fork.o exec_domain.o panic.o printk.o \ 5 obj-y = fork.o exec_domain.o panic.o printk.o \
6 cpu.o exit.o itimer.o time.o softirq.o resource.o \ 6 cpu.o exit.o itimer.o time.o softirq.o resource.o \
7 sysctl.o sysctl_binary.o capability.o ptrace.o timer.o user.o \ 7 sysctl.o sysctl_binary.o capability.o ptrace.o timer.o user.o \
8 signal.o sys.o kmod.o workqueue.o pid.o task_work.o \ 8 signal.o sys.o kmod.o workqueue.o pid.o task_work.o \
9 rcupdate.o extable.o params.o posix-timers.o \ 9 rcupdate.o extable.o params.o posix-timers.o \
10 kthread.o wait.o sys_ni.o posix-cpu-timers.o mutex.o \ 10 kthread.o wait.o sys_ni.o posix-cpu-timers.o mutex.o \
11 hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \ 11 hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \
12 notifier.o ksysfs.o cred.o \ 12 notifier.o ksysfs.o cred.o \
13 async.o range.o groups.o lglock.o smpboot.o 13 async.o range.o groups.o lglock.o smpboot.o
14 14
15 ifdef CONFIG_FUNCTION_TRACER 15 ifdef CONFIG_FUNCTION_TRACER
16 # Do not trace debug files and internal ftrace files 16 # Do not trace debug files and internal ftrace files
17 CFLAGS_REMOVE_lockdep.o = -pg 17 CFLAGS_REMOVE_lockdep.o = -pg
18 CFLAGS_REMOVE_lockdep_proc.o = -pg 18 CFLAGS_REMOVE_lockdep_proc.o = -pg
19 CFLAGS_REMOVE_mutex-debug.o = -pg 19 CFLAGS_REMOVE_mutex-debug.o = -pg
20 CFLAGS_REMOVE_rtmutex-debug.o = -pg 20 CFLAGS_REMOVE_rtmutex-debug.o = -pg
21 CFLAGS_REMOVE_cgroup-debug.o = -pg 21 CFLAGS_REMOVE_cgroup-debug.o = -pg
22 CFLAGS_REMOVE_irq_work.o = -pg 22 CFLAGS_REMOVE_irq_work.o = -pg
23 endif 23 endif
24 24
25 obj-y += sched/ 25 obj-y += sched/
26 obj-y += power/ 26 obj-y += power/
27 obj-y += cpu/ 27 obj-y += cpu/
28 28
29 obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o 29 obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
30 obj-$(CONFIG_FREEZER) += freezer.o 30 obj-$(CONFIG_FREEZER) += freezer.o
31 obj-$(CONFIG_PROFILING) += profile.o 31 obj-$(CONFIG_PROFILING) += profile.o
32 obj-$(CONFIG_STACKTRACE) += stacktrace.o 32 obj-$(CONFIG_STACKTRACE) += stacktrace.o
33 obj-y += time/ 33 obj-y += time/
34 obj-$(CONFIG_DEBUG_MUTEXES) += mutex-debug.o 34 obj-$(CONFIG_DEBUG_MUTEXES) += mutex-debug.o
35 obj-$(CONFIG_LOCKDEP) += lockdep.o 35 obj-$(CONFIG_LOCKDEP) += lockdep.o
36 ifeq ($(CONFIG_PROC_FS),y) 36 ifeq ($(CONFIG_PROC_FS),y)
37 obj-$(CONFIG_LOCKDEP) += lockdep_proc.o 37 obj-$(CONFIG_LOCKDEP) += lockdep_proc.o
38 endif 38 endif
39 obj-$(CONFIG_FUTEX) += futex.o 39 obj-$(CONFIG_FUTEX) += futex.o
40 ifeq ($(CONFIG_COMPAT),y) 40 ifeq ($(CONFIG_COMPAT),y)
41 obj-$(CONFIG_FUTEX) += futex_compat.o 41 obj-$(CONFIG_FUTEX) += futex_compat.o
42 endif 42 endif
43 obj-$(CONFIG_RT_MUTEXES) += rtmutex.o 43 obj-$(CONFIG_RT_MUTEXES) += rtmutex.o
44 obj-$(CONFIG_DEBUG_RT_MUTEXES) += rtmutex-debug.o 44 obj-$(CONFIG_DEBUG_RT_MUTEXES) += rtmutex-debug.o
45 obj-$(CONFIG_RT_MUTEX_TESTER) += rtmutex-tester.o 45 obj-$(CONFIG_RT_MUTEX_TESTER) += rtmutex-tester.o
46 obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o 46 obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
47 obj-$(CONFIG_SMP) += smp.o 47 obj-$(CONFIG_SMP) += smp.o
48 ifneq ($(CONFIG_SMP),y) 48 ifneq ($(CONFIG_SMP),y)
49 obj-y += up.o 49 obj-y += up.o
50 endif 50 endif
51 obj-$(CONFIG_SMP) += spinlock.o 51 obj-$(CONFIG_SMP) += spinlock.o
52 obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock.o 52 obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock.o
53 obj-$(CONFIG_PROVE_LOCKING) += spinlock.o 53 obj-$(CONFIG_PROVE_LOCKING) += spinlock.o
54 obj-$(CONFIG_UID16) += uid16.o 54 obj-$(CONFIG_UID16) += uid16.o
55 obj-$(CONFIG_MODULES) += module.o 55 obj-$(CONFIG_MODULES) += module.o
56 obj-$(CONFIG_MODULE_SIG) += module_signing.o modsign_pubkey.o modsign_certificate.o 56 obj-$(CONFIG_MODULE_SIG) += module_signing.o modsign_pubkey.o modsign_certificate.o
57 obj-$(CONFIG_KALLSYMS) += kallsyms.o 57 obj-$(CONFIG_KALLSYMS) += kallsyms.o
58 obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o 58 obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o
59 obj-$(CONFIG_KEXEC) += kexec.o 59 obj-$(CONFIG_KEXEC) += kexec.o
60 obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o 60 obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o
61 obj-$(CONFIG_COMPAT) += compat.o 61 obj-$(CONFIG_COMPAT) += compat.o
62 obj-$(CONFIG_CGROUPS) += cgroup.o 62 obj-$(CONFIG_CGROUPS) += cgroup.o
63 obj-$(CONFIG_CGROUP_FREEZER) += cgroup_freezer.o 63 obj-$(CONFIG_CGROUP_FREEZER) += cgroup_freezer.o
64 obj-$(CONFIG_CPUSETS) += cpuset.o 64 obj-$(CONFIG_CPUSETS) += cpuset.o
65 obj-$(CONFIG_UTS_NS) += utsname.o 65 obj-$(CONFIG_UTS_NS) += utsname.o
66 obj-$(CONFIG_USER_NS) += user_namespace.o 66 obj-$(CONFIG_USER_NS) += user_namespace.o
67 obj-$(CONFIG_PID_NS) += pid_namespace.o 67 obj-$(CONFIG_PID_NS) += pid_namespace.o
68 obj-$(CONFIG_IKCONFIG) += configs.o 68 obj-$(CONFIG_IKCONFIG) += configs.o
69 obj-$(CONFIG_RESOURCE_COUNTERS) += res_counter.o 69 obj-$(CONFIG_RESOURCE_COUNTERS) += res_counter.o
70 obj-$(CONFIG_SMP) += stop_machine.o 70 obj-$(CONFIG_SMP) += stop_machine.o
71 obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o 71 obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o
72 obj-$(CONFIG_AUDIT) += audit.o auditfilter.o 72 obj-$(CONFIG_AUDIT) += audit.o auditfilter.o
73 obj-$(CONFIG_AUDITSYSCALL) += auditsc.o 73 obj-$(CONFIG_AUDITSYSCALL) += auditsc.o
74 obj-$(CONFIG_AUDIT_WATCH) += audit_watch.o 74 obj-$(CONFIG_AUDIT_WATCH) += audit_watch.o
75 obj-$(CONFIG_AUDIT_TREE) += audit_tree.o 75 obj-$(CONFIG_AUDIT_TREE) += audit_tree.o
76 obj-$(CONFIG_GCOV_KERNEL) += gcov/ 76 obj-$(CONFIG_GCOV_KERNEL) += gcov/
77 obj-$(CONFIG_KPROBES) += kprobes.o 77 obj-$(CONFIG_KPROBES) += kprobes.o
78 obj-$(CONFIG_KGDB) += debug/ 78 obj-$(CONFIG_KGDB) += debug/
79 obj-$(CONFIG_DETECT_HUNG_TASK) += hung_task.o 79 obj-$(CONFIG_DETECT_HUNG_TASK) += hung_task.o
80 obj-$(CONFIG_LOCKUP_DETECTOR) += watchdog.o 80 obj-$(CONFIG_LOCKUP_DETECTOR) += watchdog.o
81 obj-$(CONFIG_GENERIC_HARDIRQS) += irq/ 81 obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
82 obj-$(CONFIG_SECCOMP) += seccomp.o 82 obj-$(CONFIG_SECCOMP) += seccomp.o
83 obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o 83 obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o
84 obj-$(CONFIG_TREE_RCU) += rcutree.o 84 obj-$(CONFIG_TREE_RCU) += rcutree.o
85 obj-$(CONFIG_TREE_PREEMPT_RCU) += rcutree.o 85 obj-$(CONFIG_TREE_PREEMPT_RCU) += rcutree.o
86 obj-$(CONFIG_TREE_RCU_TRACE) += rcutree_trace.o 86 obj-$(CONFIG_TREE_RCU_TRACE) += rcutree_trace.o
87 obj-$(CONFIG_TINY_RCU) += rcutiny.o 87 obj-$(CONFIG_TINY_RCU) += rcutiny.o
88 obj-$(CONFIG_TINY_PREEMPT_RCU) += rcutiny.o 88 obj-$(CONFIG_TINY_PREEMPT_RCU) += rcutiny.o
89 obj-$(CONFIG_RELAY) += relay.o 89 obj-$(CONFIG_RELAY) += relay.o
90 obj-$(CONFIG_SYSCTL) += utsname_sysctl.o 90 obj-$(CONFIG_SYSCTL) += utsname_sysctl.o
91 obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o 91 obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o
92 obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o 92 obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o
93 obj-$(CONFIG_TRACEPOINTS) += tracepoint.o 93 obj-$(CONFIG_TRACEPOINTS) += tracepoint.o
94 obj-$(CONFIG_LATENCYTOP) += latencytop.o 94 obj-$(CONFIG_LATENCYTOP) += latencytop.o
95 obj-$(CONFIG_BINFMT_ELF) += elfcore.o 95 obj-$(CONFIG_BINFMT_ELF) += elfcore.o
96 obj-$(CONFIG_COMPAT_BINFMT_ELF) += elfcore.o 96 obj-$(CONFIG_COMPAT_BINFMT_ELF) += elfcore.o
97 obj-$(CONFIG_BINFMT_ELF_FDPIC) += elfcore.o 97 obj-$(CONFIG_BINFMT_ELF_FDPIC) += elfcore.o
98 obj-$(CONFIG_FUNCTION_TRACER) += trace/ 98 obj-$(CONFIG_FUNCTION_TRACER) += trace/
99 obj-$(CONFIG_TRACING) += trace/ 99 obj-$(CONFIG_TRACING) += trace/
100 obj-$(CONFIG_TRACE_CLOCK) += trace/ 100 obj-$(CONFIG_TRACE_CLOCK) += trace/
101 obj-$(CONFIG_RING_BUFFER) += trace/ 101 obj-$(CONFIG_RING_BUFFER) += trace/
102 obj-$(CONFIG_TRACEPOINTS) += trace/ 102 obj-$(CONFIG_TRACEPOINTS) += trace/
103 obj-$(CONFIG_IRQ_WORK) += irq_work.o 103 obj-$(CONFIG_IRQ_WORK) += irq_work.o
104 obj-$(CONFIG_CPU_PM) += cpu_pm.o 104 obj-$(CONFIG_CPU_PM) += cpu_pm.o
105 105
106 obj-$(CONFIG_PERF_EVENTS) += events/ 106 obj-$(CONFIG_PERF_EVENTS) += events/
107 107
108 obj-$(CONFIG_USER_RETURN_NOTIFIER) += user-return-notifier.o 108 obj-$(CONFIG_USER_RETURN_NOTIFIER) += user-return-notifier.o
109 obj-$(CONFIG_PADATA) += padata.o 109 obj-$(CONFIG_PADATA) += padata.o
110 obj-$(CONFIG_CRASH_DUMP) += crash_dump.o 110 obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
111 obj-$(CONFIG_JUMP_LABEL) += jump_label.o 111 obj-$(CONFIG_JUMP_LABEL) += jump_label.o
112 obj-$(CONFIG_CONTEXT_TRACKING) += context_tracking.o 112 obj-$(CONFIG_CONTEXT_TRACKING) += context_tracking.o
113 113
114 $(obj)/configs.o: $(obj)/config_data.h 114 $(obj)/configs.o: $(obj)/config_data.h
115 115
116 # config_data.h contains the same information as ikconfig.h but gzipped. 116 # config_data.h contains the same information as ikconfig.h but gzipped.
117 # Info from config_data can be extracted from /proc/config* 117 # Info from config_data can be extracted from /proc/config*
118 targets += config_data.gz 118 targets += config_data.gz
119 $(obj)/config_data.gz: $(KCONFIG_CONFIG) FORCE 119 $(obj)/config_data.gz: $(KCONFIG_CONFIG) FORCE
120 $(call if_changed,gzip) 120 $(call if_changed,gzip)
121 121
122 filechk_ikconfiggz = (echo "static const char kernel_config_data[] __used = MAGIC_START"; cat $< | scripts/bin2c; echo "MAGIC_END;") 122 filechk_ikconfiggz = (echo "static const char kernel_config_data[] __used = MAGIC_START"; cat $< | scripts/bin2c; echo "MAGIC_END;")
123 targets += config_data.h 123 targets += config_data.h
124 $(obj)/config_data.h: $(obj)/config_data.gz FORCE 124 $(obj)/config_data.h: $(obj)/config_data.gz FORCE
125 $(call filechk,ikconfiggz) 125 $(call filechk,ikconfiggz)
126 126
127 $(obj)/time.o: $(obj)/timeconst.h 127 $(obj)/time.o: $(obj)/timeconst.h
128 128
129 quiet_cmd_hzfile = HZFILE $@ 129 quiet_cmd_hzfile = HZFILE $@
130 cmd_hzfile = echo "hz=$(CONFIG_HZ)" > $@ 130 cmd_hzfile = echo "hz=$(CONFIG_HZ)" > $@
131 131
132 targets += hz.bc 132 targets += hz.bc
133 $(obj)/hz.bc: $(objtree)/include/config/hz.h FORCE 133 $(obj)/hz.bc: $(objtree)/include/config/hz.h FORCE
134 $(call if_changed,hzfile) 134 $(call if_changed,hzfile)
135 135
136 quiet_cmd_bc = BC $@ 136 quiet_cmd_bc = BC $@
137 cmd_bc = bc -q $(filter-out FORCE,$^) > $@ 137 cmd_bc = bc -q $(filter-out FORCE,$^) > $@
138 138
139 targets += timeconst.h 139 targets += timeconst.h
140 $(obj)/timeconst.h: $(obj)/hz.bc $(src)/timeconst.bc FORCE 140 $(obj)/timeconst.h: $(obj)/hz.bc $(src)/timeconst.bc FORCE
141 $(call if_changed,bc) 141 $(call if_changed,bc)
142 142
143 ifeq ($(CONFIG_MODULE_SIG),y) 143 ifeq ($(CONFIG_MODULE_SIG),y)
144 # 144 #
145 # Pull the signing certificate and any extra certificates into the kernel 145 # Pull the signing certificate and any extra certificates into the kernel
146 # 146 #
147 147
148 quiet_cmd_touch = TOUCH $@ 148 quiet_cmd_touch = TOUCH $@
149 cmd_touch = touch $@ 149 cmd_touch = touch $@
150 150
151 extra_certificates: 151 extra_certificates:
152 $(call cmd,touch) 152 $(call cmd,touch)
153 153
154 kernel/modsign_certificate.o: signing_key.x509 extra_certificates 154 kernel/modsign_certificate.o: signing_key.x509 extra_certificates
155 155
156 ############################################################################### 156 ###############################################################################
157 # 157 #
158 # If module signing is requested, say by allyesconfig, but a key has not been 158 # If module signing is requested, say by allyesconfig, but a key has not been
159 # supplied, then one will need to be generated to make sure the build does not 159 # supplied, then one will need to be generated to make sure the build does not
160 # fail and that the kernel may be used afterwards. 160 # fail and that the kernel may be used afterwards.
161 # 161 #
162 ############################################################################### 162 ###############################################################################
163 ifndef CONFIG_MODULE_SIG_HASH 163 ifndef CONFIG_MODULE_SIG_HASH
164 $(error Could not determine digest type to use from kernel config) 164 $(error Could not determine digest type to use from kernel config)
165 endif 165 endif
166 166
167 signing_key.priv signing_key.x509: x509.genkey 167 signing_key.priv signing_key.x509: x509.genkey
168 @echo "###" 168 @echo "###"
169 @echo "### Now generating an X.509 key pair to be used for signing modules." 169 @echo "### Now generating an X.509 key pair to be used for signing modules."
170 @echo "###" 170 @echo "###"
171 @echo "### If this takes a long time, you might wish to run rngd in the" 171 @echo "### If this takes a long time, you might wish to run rngd in the"
172 @echo "### background to keep the supply of entropy topped up. It" 172 @echo "### background to keep the supply of entropy topped up. It"
173 @echo "### needs to be run as root, and uses a hardware random" 173 @echo "### needs to be run as root, and uses a hardware random"
174 @echo "### number generator if one is available." 174 @echo "### number generator if one is available."
175 @echo "###" 175 @echo "###"
176 openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \ 176 openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \
177 -batch -x509 -config x509.genkey \ 177 -batch -x509 -config x509.genkey \
178 -outform DER -out signing_key.x509 \ 178 -outform DER -out signing_key.x509 \
179 -keyout signing_key.priv 179 -keyout signing_key.priv 2>&1
180 @echo "###" 180 @echo "###"
181 @echo "### Key pair generated." 181 @echo "### Key pair generated."
182 @echo "###" 182 @echo "###"
183 183
184 x509.genkey: 184 x509.genkey:
185 @echo Generating X.509 key generation config 185 @echo Generating X.509 key generation config
186 @echo >x509.genkey "[ req ]" 186 @echo >x509.genkey "[ req ]"
187 @echo >>x509.genkey "default_bits = 4096" 187 @echo >>x509.genkey "default_bits = 4096"
188 @echo >>x509.genkey "distinguished_name = req_distinguished_name" 188 @echo >>x509.genkey "distinguished_name = req_distinguished_name"
189 @echo >>x509.genkey "prompt = no" 189 @echo >>x509.genkey "prompt = no"
190 @echo >>x509.genkey "string_mask = utf8only" 190 @echo >>x509.genkey "string_mask = utf8only"
191 @echo >>x509.genkey "x509_extensions = myexts" 191 @echo >>x509.genkey "x509_extensions = myexts"
192 @echo >>x509.genkey 192 @echo >>x509.genkey
193 @echo >>x509.genkey "[ req_distinguished_name ]" 193 @echo >>x509.genkey "[ req_distinguished_name ]"
194 @echo >>x509.genkey "O = Magrathea" 194 @echo >>x509.genkey "O = Magrathea"
195 @echo >>x509.genkey "CN = Glacier signing key" 195 @echo >>x509.genkey "CN = Glacier signing key"
196 @echo >>x509.genkey "emailAddress = slartibartfast@magrathea.h2g2" 196 @echo >>x509.genkey "emailAddress = slartibartfast@magrathea.h2g2"
197 @echo >>x509.genkey 197 @echo >>x509.genkey
198 @echo >>x509.genkey "[ myexts ]" 198 @echo >>x509.genkey "[ myexts ]"
199 @echo >>x509.genkey "basicConstraints=critical,CA:FALSE" 199 @echo >>x509.genkey "basicConstraints=critical,CA:FALSE"
200 @echo >>x509.genkey "keyUsage=digitalSignature" 200 @echo >>x509.genkey "keyUsage=digitalSignature"
201 @echo >>x509.genkey "subjectKeyIdentifier=hash" 201 @echo >>x509.genkey "subjectKeyIdentifier=hash"
202 @echo >>x509.genkey "authorityKeyIdentifier=keyid" 202 @echo >>x509.genkey "authorityKeyIdentifier=keyid"
203 endif 203 endif
204 204
1 /* 1 /*
2 * kallsyms.c: in-kernel printing of symbolic oopses and stack traces. 2 * kallsyms.c: in-kernel printing of symbolic oopses and stack traces.
3 * 3 *
4 * Rewritten and vastly simplified by Rusty Russell for in-kernel 4 * Rewritten and vastly simplified by Rusty Russell for in-kernel
5 * module loader: 5 * module loader:
6 * Copyright 2002 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation 6 * Copyright 2002 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation
7 * 7 *
8 * ChangeLog: 8 * ChangeLog:
9 * 9 *
10 * (25/Aug/2004) Paulo Marques <pmarques@grupopie.com> 10 * (25/Aug/2004) Paulo Marques <pmarques@grupopie.com>
11 * Changed the compression method from stem compression to "table lookup" 11 * Changed the compression method from stem compression to "table lookup"
12 * compression (see scripts/kallsyms.c for a more complete description) 12 * compression (see scripts/kallsyms.c for a more complete description)
13 */ 13 */
14 #include <linux/kallsyms.h> 14 #include <linux/kallsyms.h>
15 #include <linux/module.h> 15 #include <linux/module.h>
16 #include <linux/init.h> 16 #include <linux/init.h>
17 #include <linux/seq_file.h> 17 #include <linux/seq_file.h>
18 #include <linux/fs.h> 18 #include <linux/fs.h>
19 #include <linux/kdb.h> 19 #include <linux/kdb.h>
20 #include <linux/err.h> 20 #include <linux/err.h>
21 #include <linux/proc_fs.h> 21 #include <linux/proc_fs.h>
22 #include <linux/sched.h> /* for cond_resched */ 22 #include <linux/sched.h> /* for cond_resched */
23 #include <linux/mm.h> 23 #include <linux/mm.h>
24 #include <linux/ctype.h> 24 #include <linux/ctype.h>
25 #include <linux/slab.h> 25 #include <linux/slab.h>
26 26
27 #include <asm/sections.h> 27 #include <asm/sections.h>
28 28
29 #ifdef CONFIG_KALLSYMS_ALL 29 #ifdef CONFIG_KALLSYMS_ALL
30 #define all_var 1 30 #define all_var 1
31 #else 31 #else
32 #define all_var 0 32 #define all_var 0
33 #endif 33 #endif
34 34
35 /* 35 /*
36 * These will be re-linked against their real values 36 * These will be re-linked against their real values
37 * during the second link stage. 37 * during the second link stage.
38 */ 38 */
39 extern const unsigned long kallsyms_addresses[] __attribute__((weak)); 39 extern const unsigned long kallsyms_addresses[] __attribute__((weak));
40 extern const u8 kallsyms_names[] __attribute__((weak)); 40 extern const u8 kallsyms_names[] __attribute__((weak));
41 41
42 /* 42 /*
43 * Tell the compiler that the count isn't in the small data section if the arch 43 * Tell the compiler that the count isn't in the small data section if the arch
44 * has one (eg: FRV). 44 * has one (eg: FRV).
45 */ 45 */
46 extern const unsigned long kallsyms_num_syms 46 extern const unsigned long kallsyms_num_syms
47 __attribute__((weak, section(".rodata"))); 47 __attribute__((weak, section(".rodata")));
48 48
49 extern const u8 kallsyms_token_table[] __attribute__((weak)); 49 extern const u8 kallsyms_token_table[] __attribute__((weak));
50 extern const u16 kallsyms_token_index[] __attribute__((weak)); 50 extern const u16 kallsyms_token_index[] __attribute__((weak));
51 51
52 extern const unsigned long kallsyms_markers[] __attribute__((weak)); 52 extern const unsigned long kallsyms_markers[] __attribute__((weak));
53 53
54 static inline int is_kernel_inittext(unsigned long addr) 54 static inline int is_kernel_inittext(unsigned long addr)
55 { 55 {
56 if (addr >= (unsigned long)_sinittext 56 if (addr >= (unsigned long)_sinittext
57 && addr <= (unsigned long)_einittext) 57 && addr <= (unsigned long)_einittext)
58 return 1; 58 return 1;
59 return 0; 59 return 0;
60 } 60 }
61 61
62 static inline int is_kernel_text(unsigned long addr) 62 static inline int is_kernel_text(unsigned long addr)
63 { 63 {
64 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) || 64 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
65 arch_is_kernel_text(addr)) 65 arch_is_kernel_text(addr))
66 return 1; 66 return 1;
67 return in_gate_area_no_mm(addr); 67 return in_gate_area_no_mm(addr);
68 } 68 }
69 69
70 static inline int is_kernel(unsigned long addr) 70 static inline int is_kernel(unsigned long addr)
71 { 71 {
72 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end) 72 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
73 return 1; 73 return 1;
74 return in_gate_area_no_mm(addr); 74 return in_gate_area_no_mm(addr);
75 } 75 }
76 76
77 static int is_ksym_addr(unsigned long addr) 77 static int is_ksym_addr(unsigned long addr)
78 { 78 {
79 if (all_var) 79 if (all_var)
80 return is_kernel(addr); 80 return is_kernel(addr);
81 81
82 return is_kernel_text(addr) || is_kernel_inittext(addr); 82 return is_kernel_text(addr) || is_kernel_inittext(addr);
83 } 83 }
84 84
85 /* 85 /*
86 * Expand a compressed symbol data into the resulting uncompressed string, 86 * Expand a compressed symbol data into the resulting uncompressed string,
87 * if uncompressed string is too long (>= maxlen), it will be truncated,
87 * given the offset to where the symbol is in the compressed stream. 88 * given the offset to where the symbol is in the compressed stream.
88 */ 89 */
89 static unsigned int kallsyms_expand_symbol(unsigned int off, char *result) 90 static unsigned int kallsyms_expand_symbol(unsigned int off,
91 char *result, size_t maxlen)
90 { 92 {
91 int len, skipped_first = 0; 93 int len, skipped_first = 0;
92 const u8 *tptr, *data; 94 const u8 *tptr, *data;
93 95
94 /* Get the compressed symbol length from the first symbol byte. */ 96 /* Get the compressed symbol length from the first symbol byte. */
95 data = &kallsyms_names[off]; 97 data = &kallsyms_names[off];
96 len = *data; 98 len = *data;
97 data++; 99 data++;
98 100
99 /* 101 /*
100 * Update the offset to return the offset for the next symbol on 102 * Update the offset to return the offset for the next symbol on
101 * the compressed stream. 103 * the compressed stream.
102 */ 104 */
103 off += len + 1; 105 off += len + 1;
104 106
105 /* 107 /*
106 * For every byte on the compressed symbol data, copy the table 108 * For every byte on the compressed symbol data, copy the table
107 * entry for that byte. 109 * entry for that byte.
108 */ 110 */
109 while (len) { 111 while (len) {
110 tptr = &kallsyms_token_table[kallsyms_token_index[*data]]; 112 tptr = &kallsyms_token_table[kallsyms_token_index[*data]];
111 data++; 113 data++;
112 len--; 114 len--;
113 115
114 while (*tptr) { 116 while (*tptr) {
115 if (skipped_first) { 117 if (skipped_first) {
118 if (maxlen <= 1)
119 goto tail;
116 *result = *tptr; 120 *result = *tptr;
117 result++; 121 result++;
122 maxlen--;
118 } else 123 } else
119 skipped_first = 1; 124 skipped_first = 1;
120 tptr++; 125 tptr++;
121 } 126 }
122 } 127 }
123 128
124 *result = '\0'; 129 tail:
130 if (maxlen)
131 *result = '\0';
125 132
126 /* Return to offset to the next symbol. */ 133 /* Return to offset to the next symbol. */
127 return off; 134 return off;
128 } 135 }
129 136
130 /* 137 /*
131 * Get symbol type information. This is encoded as a single char at the 138 * Get symbol type information. This is encoded as a single char at the
132 * beginning of the symbol name. 139 * beginning of the symbol name.
133 */ 140 */
134 static char kallsyms_get_symbol_type(unsigned int off) 141 static char kallsyms_get_symbol_type(unsigned int off)
135 { 142 {
136 /* 143 /*
137 * Get just the first code, look it up in the token table, 144 * Get just the first code, look it up in the token table,
138 * and return the first char from this token. 145 * and return the first char from this token.
139 */ 146 */
140 return kallsyms_token_table[kallsyms_token_index[kallsyms_names[off + 1]]]; 147 return kallsyms_token_table[kallsyms_token_index[kallsyms_names[off + 1]]];
141 } 148 }
142 149
143 150
144 /* 151 /*
145 * Find the offset on the compressed stream given and index in the 152 * Find the offset on the compressed stream given and index in the
146 * kallsyms array. 153 * kallsyms array.
147 */ 154 */
148 static unsigned int get_symbol_offset(unsigned long pos) 155 static unsigned int get_symbol_offset(unsigned long pos)
149 { 156 {
150 const u8 *name; 157 const u8 *name;
151 int i; 158 int i;
152 159
153 /* 160 /*
154 * Use the closest marker we have. We have markers every 256 positions, 161 * Use the closest marker we have. We have markers every 256 positions,
155 * so that should be close enough. 162 * so that should be close enough.
156 */ 163 */
157 name = &kallsyms_names[kallsyms_markers[pos >> 8]]; 164 name = &kallsyms_names[kallsyms_markers[pos >> 8]];
158 165
159 /* 166 /*
160 * Sequentially scan all the symbols up to the point we're searching 167 * Sequentially scan all the symbols up to the point we're searching
161 * for. Every symbol is stored in a [<len>][<len> bytes of data] format, 168 * for. Every symbol is stored in a [<len>][<len> bytes of data] format,
162 * so we just need to add the len to the current pointer for every 169 * so we just need to add the len to the current pointer for every
163 * symbol we wish to skip. 170 * symbol we wish to skip.
164 */ 171 */
165 for (i = 0; i < (pos & 0xFF); i++) 172 for (i = 0; i < (pos & 0xFF); i++)
166 name = name + (*name) + 1; 173 name = name + (*name) + 1;
167 174
168 return name - kallsyms_names; 175 return name - kallsyms_names;
169 } 176 }
170 177
171 /* Lookup the address for this symbol. Returns 0 if not found. */ 178 /* Lookup the address for this symbol. Returns 0 if not found. */
172 unsigned long kallsyms_lookup_name(const char *name) 179 unsigned long kallsyms_lookup_name(const char *name)
173 { 180 {
174 char namebuf[KSYM_NAME_LEN]; 181 char namebuf[KSYM_NAME_LEN];
175 unsigned long i; 182 unsigned long i;
176 unsigned int off; 183 unsigned int off;
177 184
178 for (i = 0, off = 0; i < kallsyms_num_syms; i++) { 185 for (i = 0, off = 0; i < kallsyms_num_syms; i++) {
179 off = kallsyms_expand_symbol(off, namebuf); 186 off = kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf));
180 187
181 if (strcmp(namebuf, name) == 0) 188 if (strcmp(namebuf, name) == 0)
182 return kallsyms_addresses[i]; 189 return kallsyms_addresses[i];
183 } 190 }
184 return module_kallsyms_lookup_name(name); 191 return module_kallsyms_lookup_name(name);
185 } 192 }
186 EXPORT_SYMBOL_GPL(kallsyms_lookup_name); 193 EXPORT_SYMBOL_GPL(kallsyms_lookup_name);
187 194
188 int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *, 195 int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
189 unsigned long), 196 unsigned long),
190 void *data) 197 void *data)
191 { 198 {
192 char namebuf[KSYM_NAME_LEN]; 199 char namebuf[KSYM_NAME_LEN];
193 unsigned long i; 200 unsigned long i;
194 unsigned int off; 201 unsigned int off;
195 int ret; 202 int ret;
196 203
197 for (i = 0, off = 0; i < kallsyms_num_syms; i++) { 204 for (i = 0, off = 0; i < kallsyms_num_syms; i++) {
198 off = kallsyms_expand_symbol(off, namebuf); 205 off = kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf));
199 ret = fn(data, namebuf, NULL, kallsyms_addresses[i]); 206 ret = fn(data, namebuf, NULL, kallsyms_addresses[i]);
200 if (ret != 0) 207 if (ret != 0)
201 return ret; 208 return ret;
202 } 209 }
203 return module_kallsyms_on_each_symbol(fn, data); 210 return module_kallsyms_on_each_symbol(fn, data);
204 } 211 }
205 EXPORT_SYMBOL_GPL(kallsyms_on_each_symbol); 212 EXPORT_SYMBOL_GPL(kallsyms_on_each_symbol);
206 213
207 static unsigned long get_symbol_pos(unsigned long addr, 214 static unsigned long get_symbol_pos(unsigned long addr,
208 unsigned long *symbolsize, 215 unsigned long *symbolsize,
209 unsigned long *offset) 216 unsigned long *offset)
210 { 217 {
211 unsigned long symbol_start = 0, symbol_end = 0; 218 unsigned long symbol_start = 0, symbol_end = 0;
212 unsigned long i, low, high, mid; 219 unsigned long i, low, high, mid;
213 220
214 /* This kernel should never had been booted. */ 221 /* This kernel should never had been booted. */
215 BUG_ON(!kallsyms_addresses); 222 BUG_ON(!kallsyms_addresses);
216 223
217 /* Do a binary search on the sorted kallsyms_addresses array. */ 224 /* Do a binary search on the sorted kallsyms_addresses array. */
218 low = 0; 225 low = 0;
219 high = kallsyms_num_syms; 226 high = kallsyms_num_syms;
220 227
221 while (high - low > 1) { 228 while (high - low > 1) {
222 mid = low + (high - low) / 2; 229 mid = low + (high - low) / 2;
223 if (kallsyms_addresses[mid] <= addr) 230 if (kallsyms_addresses[mid] <= addr)
224 low = mid; 231 low = mid;
225 else 232 else
226 high = mid; 233 high = mid;
227 } 234 }
228 235
229 /* 236 /*
230 * Search for the first aliased symbol. Aliased 237 * Search for the first aliased symbol. Aliased
231 * symbols are symbols with the same address. 238 * symbols are symbols with the same address.
232 */ 239 */
233 while (low && kallsyms_addresses[low-1] == kallsyms_addresses[low]) 240 while (low && kallsyms_addresses[low-1] == kallsyms_addresses[low])
234 --low; 241 --low;
235 242
236 symbol_start = kallsyms_addresses[low]; 243 symbol_start = kallsyms_addresses[low];
237 244
238 /* Search for next non-aliased symbol. */ 245 /* Search for next non-aliased symbol. */
239 for (i = low + 1; i < kallsyms_num_syms; i++) { 246 for (i = low + 1; i < kallsyms_num_syms; i++) {
240 if (kallsyms_addresses[i] > symbol_start) { 247 if (kallsyms_addresses[i] > symbol_start) {
241 symbol_end = kallsyms_addresses[i]; 248 symbol_end = kallsyms_addresses[i];
242 break; 249 break;
243 } 250 }
244 } 251 }
245 252
246 /* If we found no next symbol, we use the end of the section. */ 253 /* If we found no next symbol, we use the end of the section. */
247 if (!symbol_end) { 254 if (!symbol_end) {
248 if (is_kernel_inittext(addr)) 255 if (is_kernel_inittext(addr))
249 symbol_end = (unsigned long)_einittext; 256 symbol_end = (unsigned long)_einittext;
250 else if (all_var) 257 else if (all_var)
251 symbol_end = (unsigned long)_end; 258 symbol_end = (unsigned long)_end;
252 else 259 else
253 symbol_end = (unsigned long)_etext; 260 symbol_end = (unsigned long)_etext;
254 } 261 }
255 262
256 if (symbolsize) 263 if (symbolsize)
257 *symbolsize = symbol_end - symbol_start; 264 *symbolsize = symbol_end - symbol_start;
258 if (offset) 265 if (offset)
259 *offset = addr - symbol_start; 266 *offset = addr - symbol_start;
260 267
261 return low; 268 return low;
262 } 269 }
263 270
264 /* 271 /*
265 * Lookup an address but don't bother to find any names. 272 * Lookup an address but don't bother to find any names.
266 */ 273 */
267 int kallsyms_lookup_size_offset(unsigned long addr, unsigned long *symbolsize, 274 int kallsyms_lookup_size_offset(unsigned long addr, unsigned long *symbolsize,
268 unsigned long *offset) 275 unsigned long *offset)
269 { 276 {
270 char namebuf[KSYM_NAME_LEN]; 277 char namebuf[KSYM_NAME_LEN];
271 if (is_ksym_addr(addr)) 278 if (is_ksym_addr(addr))
272 return !!get_symbol_pos(addr, symbolsize, offset); 279 return !!get_symbol_pos(addr, symbolsize, offset);
273 280
274 return !!module_address_lookup(addr, symbolsize, offset, NULL, namebuf); 281 return !!module_address_lookup(addr, symbolsize, offset, NULL, namebuf);
275 } 282 }
276 283
277 /* 284 /*
278 * Lookup an address 285 * Lookup an address
279 * - modname is set to NULL if it's in the kernel. 286 * - modname is set to NULL if it's in the kernel.
280 * - We guarantee that the returned name is valid until we reschedule even if. 287 * - We guarantee that the returned name is valid until we reschedule even if.
281 * It resides in a module. 288 * It resides in a module.
282 * - We also guarantee that modname will be valid until rescheduled. 289 * - We also guarantee that modname will be valid until rescheduled.
283 */ 290 */
284 const char *kallsyms_lookup(unsigned long addr, 291 const char *kallsyms_lookup(unsigned long addr,
285 unsigned long *symbolsize, 292 unsigned long *symbolsize,
286 unsigned long *offset, 293 unsigned long *offset,
287 char **modname, char *namebuf) 294 char **modname, char *namebuf)
288 { 295 {
289 namebuf[KSYM_NAME_LEN - 1] = 0; 296 namebuf[KSYM_NAME_LEN - 1] = 0;
290 namebuf[0] = 0; 297 namebuf[0] = 0;
291 298
292 if (is_ksym_addr(addr)) { 299 if (is_ksym_addr(addr)) {
293 unsigned long pos; 300 unsigned long pos;
294 301
295 pos = get_symbol_pos(addr, symbolsize, offset); 302 pos = get_symbol_pos(addr, symbolsize, offset);
296 /* Grab name */ 303 /* Grab name */
297 kallsyms_expand_symbol(get_symbol_offset(pos), namebuf); 304 kallsyms_expand_symbol(get_symbol_offset(pos),
305 namebuf, KSYM_NAME_LEN);
298 if (modname) 306 if (modname)
299 *modname = NULL; 307 *modname = NULL;
300 return namebuf; 308 return namebuf;
301 } 309 }
302 310
303 /* See if it's in a module. */ 311 /* See if it's in a module. */
304 return module_address_lookup(addr, symbolsize, offset, modname, 312 return module_address_lookup(addr, symbolsize, offset, modname,
305 namebuf); 313 namebuf);
306 } 314 }
307 315
308 int lookup_symbol_name(unsigned long addr, char *symname) 316 int lookup_symbol_name(unsigned long addr, char *symname)
309 { 317 {
310 symname[0] = '\0'; 318 symname[0] = '\0';
311 symname[KSYM_NAME_LEN - 1] = '\0'; 319 symname[KSYM_NAME_LEN - 1] = '\0';
312 320
313 if (is_ksym_addr(addr)) { 321 if (is_ksym_addr(addr)) {
314 unsigned long pos; 322 unsigned long pos;
315 323
316 pos = get_symbol_pos(addr, NULL, NULL); 324 pos = get_symbol_pos(addr, NULL, NULL);
317 /* Grab name */ 325 /* Grab name */
318 kallsyms_expand_symbol(get_symbol_offset(pos), symname); 326 kallsyms_expand_symbol(get_symbol_offset(pos),
327 symname, KSYM_NAME_LEN);
319 return 0; 328 return 0;
320 } 329 }
321 /* See if it's in a module. */ 330 /* See if it's in a module. */
322 return lookup_module_symbol_name(addr, symname); 331 return lookup_module_symbol_name(addr, symname);
323 } 332 }
324 333
325 int lookup_symbol_attrs(unsigned long addr, unsigned long *size, 334 int lookup_symbol_attrs(unsigned long addr, unsigned long *size,
326 unsigned long *offset, char *modname, char *name) 335 unsigned long *offset, char *modname, char *name)
327 { 336 {
328 name[0] = '\0'; 337 name[0] = '\0';
329 name[KSYM_NAME_LEN - 1] = '\0'; 338 name[KSYM_NAME_LEN - 1] = '\0';
330 339
331 if (is_ksym_addr(addr)) { 340 if (is_ksym_addr(addr)) {
332 unsigned long pos; 341 unsigned long pos;
333 342
334 pos = get_symbol_pos(addr, size, offset); 343 pos = get_symbol_pos(addr, size, offset);
335 /* Grab name */ 344 /* Grab name */
336 kallsyms_expand_symbol(get_symbol_offset(pos), name); 345 kallsyms_expand_symbol(get_symbol_offset(pos),
346 name, KSYM_NAME_LEN);
337 modname[0] = '\0'; 347 modname[0] = '\0';
338 return 0; 348 return 0;
339 } 349 }
340 /* See if it's in a module. */ 350 /* See if it's in a module. */
341 return lookup_module_symbol_attrs(addr, size, offset, modname, name); 351 return lookup_module_symbol_attrs(addr, size, offset, modname, name);
342 } 352 }
343 353
344 /* Look up a kernel symbol and return it in a text buffer. */ 354 /* Look up a kernel symbol and return it in a text buffer. */
345 static int __sprint_symbol(char *buffer, unsigned long address, 355 static int __sprint_symbol(char *buffer, unsigned long address,
346 int symbol_offset, int add_offset) 356 int symbol_offset, int add_offset)
347 { 357 {
348 char *modname; 358 char *modname;
349 const char *name; 359 const char *name;
350 unsigned long offset, size; 360 unsigned long offset, size;
351 int len; 361 int len;
352 362
353 address += symbol_offset; 363 address += symbol_offset;
354 name = kallsyms_lookup(address, &size, &offset, &modname, buffer); 364 name = kallsyms_lookup(address, &size, &offset, &modname, buffer);
355 if (!name) 365 if (!name)
356 return sprintf(buffer, "0x%lx", address); 366 return sprintf(buffer, "0x%lx", address);
357 367
358 if (name != buffer) 368 if (name != buffer)
359 strcpy(buffer, name); 369 strcpy(buffer, name);
360 len = strlen(buffer); 370 len = strlen(buffer);
361 offset -= symbol_offset; 371 offset -= symbol_offset;
362 372
363 if (add_offset) 373 if (add_offset)
364 len += sprintf(buffer + len, "+%#lx/%#lx", offset, size); 374 len += sprintf(buffer + len, "+%#lx/%#lx", offset, size);
365 375
366 if (modname) 376 if (modname)
367 len += sprintf(buffer + len, " [%s]", modname); 377 len += sprintf(buffer + len, " [%s]", modname);
368 378
369 return len; 379 return len;
370 } 380 }
371 381
372 /** 382 /**
373 * sprint_symbol - Look up a kernel symbol and return it in a text buffer 383 * sprint_symbol - Look up a kernel symbol and return it in a text buffer
374 * @buffer: buffer to be stored 384 * @buffer: buffer to be stored
375 * @address: address to lookup 385 * @address: address to lookup
376 * 386 *
377 * This function looks up a kernel symbol with @address and stores its name, 387 * This function looks up a kernel symbol with @address and stores its name,
378 * offset, size and module name to @buffer if possible. If no symbol was found, 388 * offset, size and module name to @buffer if possible. If no symbol was found,
379 * just saves its @address as is. 389 * just saves its @address as is.
380 * 390 *
381 * This function returns the number of bytes stored in @buffer. 391 * This function returns the number of bytes stored in @buffer.
382 */ 392 */
383 int sprint_symbol(char *buffer, unsigned long address) 393 int sprint_symbol(char *buffer, unsigned long address)
384 { 394 {
385 return __sprint_symbol(buffer, address, 0, 1); 395 return __sprint_symbol(buffer, address, 0, 1);
386 } 396 }
387 EXPORT_SYMBOL_GPL(sprint_symbol); 397 EXPORT_SYMBOL_GPL(sprint_symbol);
388 398
389 /** 399 /**
390 * sprint_symbol_no_offset - Look up a kernel symbol and return it in a text buffer 400 * sprint_symbol_no_offset - Look up a kernel symbol and return it in a text buffer
391 * @buffer: buffer to be stored 401 * @buffer: buffer to be stored
392 * @address: address to lookup 402 * @address: address to lookup
393 * 403 *
394 * This function looks up a kernel symbol with @address and stores its name 404 * This function looks up a kernel symbol with @address and stores its name
395 * and module name to @buffer if possible. If no symbol was found, just saves 405 * and module name to @buffer if possible. If no symbol was found, just saves
396 * its @address as is. 406 * its @address as is.
397 * 407 *
398 * This function returns the number of bytes stored in @buffer. 408 * This function returns the number of bytes stored in @buffer.
399 */ 409 */
400 int sprint_symbol_no_offset(char *buffer, unsigned long address) 410 int sprint_symbol_no_offset(char *buffer, unsigned long address)
401 { 411 {
402 return __sprint_symbol(buffer, address, 0, 0); 412 return __sprint_symbol(buffer, address, 0, 0);
403 } 413 }
404 EXPORT_SYMBOL_GPL(sprint_symbol_no_offset); 414 EXPORT_SYMBOL_GPL(sprint_symbol_no_offset);
405 415
406 /** 416 /**
407 * sprint_backtrace - Look up a backtrace symbol and return it in a text buffer 417 * sprint_backtrace - Look up a backtrace symbol and return it in a text buffer
408 * @buffer: buffer to be stored 418 * @buffer: buffer to be stored
409 * @address: address to lookup 419 * @address: address to lookup
410 * 420 *
411 * This function is for stack backtrace and does the same thing as 421 * This function is for stack backtrace and does the same thing as
412 * sprint_symbol() but with modified/decreased @address. If there is a 422 * sprint_symbol() but with modified/decreased @address. If there is a
413 * tail-call to the function marked "noreturn", gcc optimized out code after 423 * tail-call to the function marked "noreturn", gcc optimized out code after
414 * the call so that the stack-saved return address could point outside of the 424 * the call so that the stack-saved return address could point outside of the
415 * caller. This function ensures that kallsyms will find the original caller 425 * caller. This function ensures that kallsyms will find the original caller
416 * by decreasing @address. 426 * by decreasing @address.
417 * 427 *
418 * This function returns the number of bytes stored in @buffer. 428 * This function returns the number of bytes stored in @buffer.
419 */ 429 */
420 int sprint_backtrace(char *buffer, unsigned long address) 430 int sprint_backtrace(char *buffer, unsigned long address)
421 { 431 {
422 return __sprint_symbol(buffer, address, -1, 1); 432 return __sprint_symbol(buffer, address, -1, 1);
423 } 433 }
424 434
425 /* Look up a kernel symbol and print it to the kernel messages. */ 435 /* Look up a kernel symbol and print it to the kernel messages. */
426 void __print_symbol(const char *fmt, unsigned long address) 436 void __print_symbol(const char *fmt, unsigned long address)
427 { 437 {
428 char buffer[KSYM_SYMBOL_LEN]; 438 char buffer[KSYM_SYMBOL_LEN];
429 439
430 sprint_symbol(buffer, address); 440 sprint_symbol(buffer, address);
431 441
432 printk(fmt, buffer); 442 printk(fmt, buffer);
433 } 443 }
434 EXPORT_SYMBOL(__print_symbol); 444 EXPORT_SYMBOL(__print_symbol);
435 445
436 /* To avoid using get_symbol_offset for every symbol, we carry prefix along. */ 446 /* To avoid using get_symbol_offset for every symbol, we carry prefix along. */
437 struct kallsym_iter { 447 struct kallsym_iter {
438 loff_t pos; 448 loff_t pos;
439 unsigned long value; 449 unsigned long value;
440 unsigned int nameoff; /* If iterating in core kernel symbols. */ 450 unsigned int nameoff; /* If iterating in core kernel symbols. */
441 char type; 451 char type;
442 char name[KSYM_NAME_LEN]; 452 char name[KSYM_NAME_LEN];
443 char module_name[MODULE_NAME_LEN]; 453 char module_name[MODULE_NAME_LEN];
444 int exported; 454 int exported;
445 }; 455 };
446 456
447 static int get_ksymbol_mod(struct kallsym_iter *iter) 457 static int get_ksymbol_mod(struct kallsym_iter *iter)
448 { 458 {
449 if (module_get_kallsym(iter->pos - kallsyms_num_syms, &iter->value, 459 if (module_get_kallsym(iter->pos - kallsyms_num_syms, &iter->value,
450 &iter->type, iter->name, iter->module_name, 460 &iter->type, iter->name, iter->module_name,
451 &iter->exported) < 0) 461 &iter->exported) < 0)
452 return 0; 462 return 0;
453 return 1; 463 return 1;
454 } 464 }
455 465
456 /* Returns space to next name. */ 466 /* Returns space to next name. */
457 static unsigned long get_ksymbol_core(struct kallsym_iter *iter) 467 static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
458 { 468 {
459 unsigned off = iter->nameoff; 469 unsigned off = iter->nameoff;
460 470
461 iter->module_name[0] = '\0'; 471 iter->module_name[0] = '\0';
462 iter->value = kallsyms_addresses[iter->pos]; 472 iter->value = kallsyms_addresses[iter->pos];
463 473
464 iter->type = kallsyms_get_symbol_type(off); 474 iter->type = kallsyms_get_symbol_type(off);
465 475
466 off = kallsyms_expand_symbol(off, iter->name); 476 off = kallsyms_expand_symbol(off, iter->name, ARRAY_SIZE(iter->name));
467 477
468 return off - iter->nameoff; 478 return off - iter->nameoff;
469 } 479 }
470 480
471 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos) 481 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
472 { 482 {
473 iter->name[0] = '\0'; 483 iter->name[0] = '\0';
474 iter->nameoff = get_symbol_offset(new_pos); 484 iter->nameoff = get_symbol_offset(new_pos);
475 iter->pos = new_pos; 485 iter->pos = new_pos;
476 } 486 }
477 487
478 /* Returns false if pos at or past end of file. */ 488 /* Returns false if pos at or past end of file. */
479 static int update_iter(struct kallsym_iter *iter, loff_t pos) 489 static int update_iter(struct kallsym_iter *iter, loff_t pos)
480 { 490 {
481 /* Module symbols can be accessed randomly. */ 491 /* Module symbols can be accessed randomly. */
482 if (pos >= kallsyms_num_syms) { 492 if (pos >= kallsyms_num_syms) {
483 iter->pos = pos; 493 iter->pos = pos;
484 return get_ksymbol_mod(iter); 494 return get_ksymbol_mod(iter);
485 } 495 }
486 496
487 /* If we're not on the desired position, reset to new position. */ 497 /* If we're not on the desired position, reset to new position. */
488 if (pos != iter->pos) 498 if (pos != iter->pos)
489 reset_iter(iter, pos); 499 reset_iter(iter, pos);
490 500
491 iter->nameoff += get_ksymbol_core(iter); 501 iter->nameoff += get_ksymbol_core(iter);
492 iter->pos++; 502 iter->pos++;
493 503
494 return 1; 504 return 1;
495 } 505 }
496 506
497 static void *s_next(struct seq_file *m, void *p, loff_t *pos) 507 static void *s_next(struct seq_file *m, void *p, loff_t *pos)
498 { 508 {
499 (*pos)++; 509 (*pos)++;
500 510
501 if (!update_iter(m->private, *pos)) 511 if (!update_iter(m->private, *pos))
502 return NULL; 512 return NULL;
503 return p; 513 return p;
504 } 514 }
505 515
506 static void *s_start(struct seq_file *m, loff_t *pos) 516 static void *s_start(struct seq_file *m, loff_t *pos)
507 { 517 {
508 if (!update_iter(m->private, *pos)) 518 if (!update_iter(m->private, *pos))
509 return NULL; 519 return NULL;
510 return m->private; 520 return m->private;
511 } 521 }
512 522
513 static void s_stop(struct seq_file *m, void *p) 523 static void s_stop(struct seq_file *m, void *p)
514 { 524 {
515 } 525 }
516 526
517 static int s_show(struct seq_file *m, void *p) 527 static int s_show(struct seq_file *m, void *p)
518 { 528 {
519 struct kallsym_iter *iter = m->private; 529 struct kallsym_iter *iter = m->private;
520 530
521 /* Some debugging symbols have no name. Ignore them. */ 531 /* Some debugging symbols have no name. Ignore them. */
522 if (!iter->name[0]) 532 if (!iter->name[0])
523 return 0; 533 return 0;
524 534
525 if (iter->module_name[0]) { 535 if (iter->module_name[0]) {
526 char type; 536 char type;
527 537
528 /* 538 /*
529 * Label it "global" if it is exported, 539 * Label it "global" if it is exported,
530 * "local" if not exported. 540 * "local" if not exported.
531 */ 541 */
532 type = iter->exported ? toupper(iter->type) : 542 type = iter->exported ? toupper(iter->type) :
533 tolower(iter->type); 543 tolower(iter->type);
534 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value, 544 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
535 type, iter->name, iter->module_name); 545 type, iter->name, iter->module_name);
536 } else 546 } else
537 seq_printf(m, "%pK %c %s\n", (void *)iter->value, 547 seq_printf(m, "%pK %c %s\n", (void *)iter->value,
538 iter->type, iter->name); 548 iter->type, iter->name);
539 return 0; 549 return 0;
540 } 550 }
541 551
542 static const struct seq_operations kallsyms_op = { 552 static const struct seq_operations kallsyms_op = {
543 .start = s_start, 553 .start = s_start,
544 .next = s_next, 554 .next = s_next,
545 .stop = s_stop, 555 .stop = s_stop,
546 .show = s_show 556 .show = s_show
547 }; 557 };
548 558
549 static int kallsyms_open(struct inode *inode, struct file *file) 559 static int kallsyms_open(struct inode *inode, struct file *file)
550 { 560 {
551 /* 561 /*
552 * We keep iterator in m->private, since normal case is to 562 * We keep iterator in m->private, since normal case is to
553 * s_start from where we left off, so we avoid doing 563 * s_start from where we left off, so we avoid doing
554 * using get_symbol_offset for every symbol. 564 * using get_symbol_offset for every symbol.
555 */ 565 */
556 struct kallsym_iter *iter; 566 struct kallsym_iter *iter;
557 int ret; 567 int ret;
558 568
559 iter = kmalloc(sizeof(*iter), GFP_KERNEL); 569 iter = kmalloc(sizeof(*iter), GFP_KERNEL);
560 if (!iter) 570 if (!iter)
561 return -ENOMEM; 571 return -ENOMEM;
562 reset_iter(iter, 0); 572 reset_iter(iter, 0);
563 573
564 ret = seq_open(file, &kallsyms_op); 574 ret = seq_open(file, &kallsyms_op);
565 if (ret == 0) 575 if (ret == 0)
566 ((struct seq_file *)file->private_data)->private = iter; 576 ((struct seq_file *)file->private_data)->private = iter;
567 else 577 else
568 kfree(iter); 578 kfree(iter);
569 return ret; 579 return ret;
570 } 580 }
571 581
572 #ifdef CONFIG_KGDB_KDB 582 #ifdef CONFIG_KGDB_KDB
573 const char *kdb_walk_kallsyms(loff_t *pos) 583 const char *kdb_walk_kallsyms(loff_t *pos)
574 { 584 {
575 static struct kallsym_iter kdb_walk_kallsyms_iter; 585 static struct kallsym_iter kdb_walk_kallsyms_iter;
576 if (*pos == 0) { 586 if (*pos == 0) {
577 memset(&kdb_walk_kallsyms_iter, 0, 587 memset(&kdb_walk_kallsyms_iter, 0,
578 sizeof(kdb_walk_kallsyms_iter)); 588 sizeof(kdb_walk_kallsyms_iter));
579 reset_iter(&kdb_walk_kallsyms_iter, 0); 589 reset_iter(&kdb_walk_kallsyms_iter, 0);
580 } 590 }
581 while (1) { 591 while (1) {
582 if (!update_iter(&kdb_walk_kallsyms_iter, *pos)) 592 if (!update_iter(&kdb_walk_kallsyms_iter, *pos))
583 return NULL; 593 return NULL;
584 ++*pos; 594 ++*pos;
585 /* Some debugging symbols have no name. Ignore them. */ 595 /* Some debugging symbols have no name. Ignore them. */
586 if (kdb_walk_kallsyms_iter.name[0]) 596 if (kdb_walk_kallsyms_iter.name[0])
587 return kdb_walk_kallsyms_iter.name; 597 return kdb_walk_kallsyms_iter.name;
588 } 598 }
589 } 599 }
590 #endif /* CONFIG_KGDB_KDB */ 600 #endif /* CONFIG_KGDB_KDB */
591 601
592 static const struct file_operations kallsyms_operations = { 602 static const struct file_operations kallsyms_operations = {
593 .open = kallsyms_open, 603 .open = kallsyms_open,
594 .read = seq_read, 604 .read = seq_read,
595 .llseek = seq_lseek, 605 .llseek = seq_lseek,
596 .release = seq_release_private, 606 .release = seq_release_private,
597 }; 607 };
598 608
599 static int __init kallsyms_init(void) 609 static int __init kallsyms_init(void)
600 { 610 {
601 proc_create("kallsyms", 0444, NULL, &kallsyms_operations); 611 proc_create("kallsyms", 0444, NULL, &kallsyms_operations);
602 return 0; 612 return 0;
603 } 613 }
604 device_initcall(kallsyms_init); 614 device_initcall(kallsyms_init);
605 615
kernel/modsign_certificate.S
1 /* SYMBOL_PREFIX defined on commandline from CONFIG_SYMBOL_PREFIX */ 1 #include <linux/export.h>
2 #ifndef SYMBOL_PREFIX
3 #define ASM_SYMBOL(sym) sym
4 #else
5 #define PASTE2(x,y) x##y
6 #define PASTE(x,y) PASTE2(x,y)
7 #define ASM_SYMBOL(sym) PASTE(SYMBOL_PREFIX, sym)
8 #endif
9 2
10 #define GLOBAL(name) \ 3 #define GLOBAL(name) \
11 .globl ASM_SYMBOL(name); \ 4 .globl VMLINUX_SYMBOL(name); \
12 ASM_SYMBOL(name): 5 VMLINUX_SYMBOL(name):
13 6
14 .section ".init.data","aw" 7 .section ".init.data","aw"
15 8
16 GLOBAL(modsign_certificate_list) 9 GLOBAL(modsign_certificate_list)
17 .incbin "signing_key.x509" 10 .incbin "signing_key.x509"
18 .incbin "extra_certificates" 11 .incbin "extra_certificates"
19 GLOBAL(modsign_certificate_list_end) 12 GLOBAL(modsign_certificate_list_end)
20 13
1 /* 1 /*
2 Copyright (C) 2002 Richard Henderson 2 Copyright (C) 2002 Richard Henderson
3 Copyright (C) 2001 Rusty Russell, 2002, 2010 Rusty Russell IBM. 3 Copyright (C) 2001 Rusty Russell, 2002, 2010 Rusty Russell IBM.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 18 */
19 #include <linux/export.h> 19 #include <linux/export.h>
20 #include <linux/moduleloader.h> 20 #include <linux/moduleloader.h>
21 #include <linux/ftrace_event.h> 21 #include <linux/ftrace_event.h>
22 #include <linux/init.h> 22 #include <linux/init.h>
23 #include <linux/kallsyms.h> 23 #include <linux/kallsyms.h>
24 #include <linux/file.h> 24 #include <linux/file.h>
25 #include <linux/fs.h> 25 #include <linux/fs.h>
26 #include <linux/sysfs.h> 26 #include <linux/sysfs.h>
27 #include <linux/kernel.h> 27 #include <linux/kernel.h>
28 #include <linux/slab.h> 28 #include <linux/slab.h>
29 #include <linux/vmalloc.h> 29 #include <linux/vmalloc.h>
30 #include <linux/elf.h> 30 #include <linux/elf.h>
31 #include <linux/proc_fs.h> 31 #include <linux/proc_fs.h>
32 #include <linux/security.h> 32 #include <linux/security.h>
33 #include <linux/seq_file.h> 33 #include <linux/seq_file.h>
34 #include <linux/syscalls.h> 34 #include <linux/syscalls.h>
35 #include <linux/fcntl.h> 35 #include <linux/fcntl.h>
36 #include <linux/rcupdate.h> 36 #include <linux/rcupdate.h>
37 #include <linux/capability.h> 37 #include <linux/capability.h>
38 #include <linux/cpu.h> 38 #include <linux/cpu.h>
39 #include <linux/moduleparam.h> 39 #include <linux/moduleparam.h>
40 #include <linux/errno.h> 40 #include <linux/errno.h>
41 #include <linux/err.h> 41 #include <linux/err.h>
42 #include <linux/vermagic.h> 42 #include <linux/vermagic.h>
43 #include <linux/notifier.h> 43 #include <linux/notifier.h>
44 #include <linux/sched.h> 44 #include <linux/sched.h>
45 #include <linux/stop_machine.h> 45 #include <linux/stop_machine.h>
46 #include <linux/device.h> 46 #include <linux/device.h>
47 #include <linux/string.h> 47 #include <linux/string.h>
48 #include <linux/mutex.h> 48 #include <linux/mutex.h>
49 #include <linux/rculist.h> 49 #include <linux/rculist.h>
50 #include <asm/uaccess.h> 50 #include <asm/uaccess.h>
51 #include <asm/cacheflush.h> 51 #include <asm/cacheflush.h>
52 #include <asm/mmu_context.h> 52 #include <asm/mmu_context.h>
53 #include <linux/license.h> 53 #include <linux/license.h>
54 #include <asm/sections.h> 54 #include <asm/sections.h>
55 #include <linux/tracepoint.h> 55 #include <linux/tracepoint.h>
56 #include <linux/ftrace.h> 56 #include <linux/ftrace.h>
57 #include <linux/async.h> 57 #include <linux/async.h>
58 #include <linux/percpu.h> 58 #include <linux/percpu.h>
59 #include <linux/kmemleak.h> 59 #include <linux/kmemleak.h>
60 #include <linux/jump_label.h> 60 #include <linux/jump_label.h>
61 #include <linux/pfn.h> 61 #include <linux/pfn.h>
62 #include <linux/bsearch.h> 62 #include <linux/bsearch.h>
63 #include <linux/fips.h> 63 #include <linux/fips.h>
64 #include <uapi/linux/module.h> 64 #include <uapi/linux/module.h>
65 #include "module-internal.h" 65 #include "module-internal.h"
66 66
67 #define CREATE_TRACE_POINTS 67 #define CREATE_TRACE_POINTS
68 #include <trace/events/module.h> 68 #include <trace/events/module.h>
69 69
70 #ifndef ARCH_SHF_SMALL 70 #ifndef ARCH_SHF_SMALL
71 #define ARCH_SHF_SMALL 0 71 #define ARCH_SHF_SMALL 0
72 #endif 72 #endif
73 73
74 /* 74 /*
75 * Modules' sections will be aligned on page boundaries 75 * Modules' sections will be aligned on page boundaries
76 * to ensure complete separation of code and data, but 76 * to ensure complete separation of code and data, but
77 * only when CONFIG_DEBUG_SET_MODULE_RONX=y 77 * only when CONFIG_DEBUG_SET_MODULE_RONX=y
78 */ 78 */
79 #ifdef CONFIG_DEBUG_SET_MODULE_RONX 79 #ifdef CONFIG_DEBUG_SET_MODULE_RONX
80 # define debug_align(X) ALIGN(X, PAGE_SIZE) 80 # define debug_align(X) ALIGN(X, PAGE_SIZE)
81 #else 81 #else
82 # define debug_align(X) (X) 82 # define debug_align(X) (X)
83 #endif 83 #endif
84 84
85 /* 85 /*
86 * Given BASE and SIZE this macro calculates the number of pages the 86 * Given BASE and SIZE this macro calculates the number of pages the
87 * memory regions occupies 87 * memory regions occupies
88 */ 88 */
89 #define MOD_NUMBER_OF_PAGES(BASE, SIZE) (((SIZE) > 0) ? \ 89 #define MOD_NUMBER_OF_PAGES(BASE, SIZE) (((SIZE) > 0) ? \
90 (PFN_DOWN((unsigned long)(BASE) + (SIZE) - 1) - \ 90 (PFN_DOWN((unsigned long)(BASE) + (SIZE) - 1) - \
91 PFN_DOWN((unsigned long)BASE) + 1) \ 91 PFN_DOWN((unsigned long)BASE) + 1) \
92 : (0UL)) 92 : (0UL))
93 93
94 /* If this is set, the section belongs in the init part of the module */ 94 /* If this is set, the section belongs in the init part of the module */
95 #define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1)) 95 #define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1))
96 96
97 /* 97 /*
98 * Mutex protects: 98 * Mutex protects:
99 * 1) List of modules (also safely readable with preempt_disable), 99 * 1) List of modules (also safely readable with preempt_disable),
100 * 2) module_use links, 100 * 2) module_use links,
101 * 3) module_addr_min/module_addr_max. 101 * 3) module_addr_min/module_addr_max.
102 * (delete uses stop_machine/add uses RCU list operations). */ 102 * (delete uses stop_machine/add uses RCU list operations). */
103 DEFINE_MUTEX(module_mutex); 103 DEFINE_MUTEX(module_mutex);
104 EXPORT_SYMBOL_GPL(module_mutex); 104 EXPORT_SYMBOL_GPL(module_mutex);
105 static LIST_HEAD(modules); 105 static LIST_HEAD(modules);
106 #ifdef CONFIG_KGDB_KDB 106 #ifdef CONFIG_KGDB_KDB
107 struct list_head *kdb_modules = &modules; /* kdb needs the list of modules */ 107 struct list_head *kdb_modules = &modules; /* kdb needs the list of modules */
108 #endif /* CONFIG_KGDB_KDB */ 108 #endif /* CONFIG_KGDB_KDB */
109 109
110 #ifdef CONFIG_MODULE_SIG 110 #ifdef CONFIG_MODULE_SIG
111 #ifdef CONFIG_MODULE_SIG_FORCE 111 #ifdef CONFIG_MODULE_SIG_FORCE
112 static bool sig_enforce = true; 112 static bool sig_enforce = true;
113 #else 113 #else
114 static bool sig_enforce = false; 114 static bool sig_enforce = false;
115 115
116 static int param_set_bool_enable_only(const char *val, 116 static int param_set_bool_enable_only(const char *val,
117 const struct kernel_param *kp) 117 const struct kernel_param *kp)
118 { 118 {
119 int err; 119 int err;
120 bool test; 120 bool test;
121 struct kernel_param dummy_kp = *kp; 121 struct kernel_param dummy_kp = *kp;
122 122
123 dummy_kp.arg = &test; 123 dummy_kp.arg = &test;
124 124
125 err = param_set_bool(val, &dummy_kp); 125 err = param_set_bool(val, &dummy_kp);
126 if (err) 126 if (err)
127 return err; 127 return err;
128 128
129 /* Don't let them unset it once it's set! */ 129 /* Don't let them unset it once it's set! */
130 if (!test && sig_enforce) 130 if (!test && sig_enforce)
131 return -EROFS; 131 return -EROFS;
132 132
133 if (test) 133 if (test)
134 sig_enforce = true; 134 sig_enforce = true;
135 return 0; 135 return 0;
136 } 136 }
137 137
138 static const struct kernel_param_ops param_ops_bool_enable_only = { 138 static const struct kernel_param_ops param_ops_bool_enable_only = {
139 .set = param_set_bool_enable_only, 139 .set = param_set_bool_enable_only,
140 .get = param_get_bool, 140 .get = param_get_bool,
141 }; 141 };
142 #define param_check_bool_enable_only param_check_bool 142 #define param_check_bool_enable_only param_check_bool
143 143
144 module_param(sig_enforce, bool_enable_only, 0644); 144 module_param(sig_enforce, bool_enable_only, 0644);
145 #endif /* !CONFIG_MODULE_SIG_FORCE */ 145 #endif /* !CONFIG_MODULE_SIG_FORCE */
146 #endif /* CONFIG_MODULE_SIG */ 146 #endif /* CONFIG_MODULE_SIG */
147 147
148 /* Block module loading/unloading? */ 148 /* Block module loading/unloading? */
149 int modules_disabled = 0; 149 int modules_disabled = 0;
150 core_param(nomodule, modules_disabled, bint, 0); 150 core_param(nomodule, modules_disabled, bint, 0);
151 151
152 /* Waiting for a module to finish initializing? */ 152 /* Waiting for a module to finish initializing? */
153 static DECLARE_WAIT_QUEUE_HEAD(module_wq); 153 static DECLARE_WAIT_QUEUE_HEAD(module_wq);
154 154
155 static BLOCKING_NOTIFIER_HEAD(module_notify_list); 155 static BLOCKING_NOTIFIER_HEAD(module_notify_list);
156 156
157 /* Bounds of module allocation, for speeding __module_address. 157 /* Bounds of module allocation, for speeding __module_address.
158 * Protected by module_mutex. */ 158 * Protected by module_mutex. */
159 static unsigned long module_addr_min = -1UL, module_addr_max = 0; 159 static unsigned long module_addr_min = -1UL, module_addr_max = 0;
160 160
161 int register_module_notifier(struct notifier_block * nb) 161 int register_module_notifier(struct notifier_block * nb)
162 { 162 {
163 return blocking_notifier_chain_register(&module_notify_list, nb); 163 return blocking_notifier_chain_register(&module_notify_list, nb);
164 } 164 }
165 EXPORT_SYMBOL(register_module_notifier); 165 EXPORT_SYMBOL(register_module_notifier);
166 166
167 int unregister_module_notifier(struct notifier_block * nb) 167 int unregister_module_notifier(struct notifier_block * nb)
168 { 168 {
169 return blocking_notifier_chain_unregister(&module_notify_list, nb); 169 return blocking_notifier_chain_unregister(&module_notify_list, nb);
170 } 170 }
171 EXPORT_SYMBOL(unregister_module_notifier); 171 EXPORT_SYMBOL(unregister_module_notifier);
172 172
173 struct load_info { 173 struct load_info {
174 Elf_Ehdr *hdr; 174 Elf_Ehdr *hdr;
175 unsigned long len; 175 unsigned long len;
176 Elf_Shdr *sechdrs; 176 Elf_Shdr *sechdrs;
177 char *secstrings, *strtab; 177 char *secstrings, *strtab;
178 unsigned long symoffs, stroffs; 178 unsigned long symoffs, stroffs;
179 struct _ddebug *debug; 179 struct _ddebug *debug;
180 unsigned int num_debug; 180 unsigned int num_debug;
181 bool sig_ok; 181 bool sig_ok;
182 struct { 182 struct {
183 unsigned int sym, str, mod, vers, info, pcpu; 183 unsigned int sym, str, mod, vers, info, pcpu;
184 } index; 184 } index;
185 }; 185 };
186 186
187 /* We require a truly strong try_module_get(): 0 means failure due to 187 /* We require a truly strong try_module_get(): 0 means failure due to
188 ongoing or failed initialization etc. */ 188 ongoing or failed initialization etc. */
189 static inline int strong_try_module_get(struct module *mod) 189 static inline int strong_try_module_get(struct module *mod)
190 { 190 {
191 BUG_ON(mod && mod->state == MODULE_STATE_UNFORMED); 191 BUG_ON(mod && mod->state == MODULE_STATE_UNFORMED);
192 if (mod && mod->state == MODULE_STATE_COMING) 192 if (mod && mod->state == MODULE_STATE_COMING)
193 return -EBUSY; 193 return -EBUSY;
194 if (try_module_get(mod)) 194 if (try_module_get(mod))
195 return 0; 195 return 0;
196 else 196 else
197 return -ENOENT; 197 return -ENOENT;
198 } 198 }
199 199
200 static inline void add_taint_module(struct module *mod, unsigned flag, 200 static inline void add_taint_module(struct module *mod, unsigned flag,
201 enum lockdep_ok lockdep_ok) 201 enum lockdep_ok lockdep_ok)
202 { 202 {
203 add_taint(flag, lockdep_ok); 203 add_taint(flag, lockdep_ok);
204 mod->taints |= (1U << flag); 204 mod->taints |= (1U << flag);
205 } 205 }
206 206
207 /* 207 /*
208 * A thread that wants to hold a reference to a module only while it 208 * A thread that wants to hold a reference to a module only while it
209 * is running can call this to safely exit. nfsd and lockd use this. 209 * is running can call this to safely exit. nfsd and lockd use this.
210 */ 210 */
211 void __module_put_and_exit(struct module *mod, long code) 211 void __module_put_and_exit(struct module *mod, long code)
212 { 212 {
213 module_put(mod); 213 module_put(mod);
214 do_exit(code); 214 do_exit(code);
215 } 215 }
216 EXPORT_SYMBOL(__module_put_and_exit); 216 EXPORT_SYMBOL(__module_put_and_exit);
217 217
218 /* Find a module section: 0 means not found. */ 218 /* Find a module section: 0 means not found. */
219 static unsigned int find_sec(const struct load_info *info, const char *name) 219 static unsigned int find_sec(const struct load_info *info, const char *name)
220 { 220 {
221 unsigned int i; 221 unsigned int i;
222 222
223 for (i = 1; i < info->hdr->e_shnum; i++) { 223 for (i = 1; i < info->hdr->e_shnum; i++) {
224 Elf_Shdr *shdr = &info->sechdrs[i]; 224 Elf_Shdr *shdr = &info->sechdrs[i];
225 /* Alloc bit cleared means "ignore it." */ 225 /* Alloc bit cleared means "ignore it." */
226 if ((shdr->sh_flags & SHF_ALLOC) 226 if ((shdr->sh_flags & SHF_ALLOC)
227 && strcmp(info->secstrings + shdr->sh_name, name) == 0) 227 && strcmp(info->secstrings + shdr->sh_name, name) == 0)
228 return i; 228 return i;
229 } 229 }
230 return 0; 230 return 0;
231 } 231 }
232 232
233 /* Find a module section, or NULL. */ 233 /* Find a module section, or NULL. */
234 static void *section_addr(const struct load_info *info, const char *name) 234 static void *section_addr(const struct load_info *info, const char *name)
235 { 235 {
236 /* Section 0 has sh_addr 0. */ 236 /* Section 0 has sh_addr 0. */
237 return (void *)info->sechdrs[find_sec(info, name)].sh_addr; 237 return (void *)info->sechdrs[find_sec(info, name)].sh_addr;
238 } 238 }
239 239
240 /* Find a module section, or NULL. Fill in number of "objects" in section. */ 240 /* Find a module section, or NULL. Fill in number of "objects" in section. */
241 static void *section_objs(const struct load_info *info, 241 static void *section_objs(const struct load_info *info,
242 const char *name, 242 const char *name,
243 size_t object_size, 243 size_t object_size,
244 unsigned int *num) 244 unsigned int *num)
245 { 245 {
246 unsigned int sec = find_sec(info, name); 246 unsigned int sec = find_sec(info, name);
247 247
248 /* Section 0 has sh_addr 0 and sh_size 0. */ 248 /* Section 0 has sh_addr 0 and sh_size 0. */
249 *num = info->sechdrs[sec].sh_size / object_size; 249 *num = info->sechdrs[sec].sh_size / object_size;
250 return (void *)info->sechdrs[sec].sh_addr; 250 return (void *)info->sechdrs[sec].sh_addr;
251 } 251 }
252 252
253 /* Provided by the linker */ 253 /* Provided by the linker */
254 extern const struct kernel_symbol __start___ksymtab[]; 254 extern const struct kernel_symbol __start___ksymtab[];
255 extern const struct kernel_symbol __stop___ksymtab[]; 255 extern const struct kernel_symbol __stop___ksymtab[];
256 extern const struct kernel_symbol __start___ksymtab_gpl[]; 256 extern const struct kernel_symbol __start___ksymtab_gpl[];
257 extern const struct kernel_symbol __stop___ksymtab_gpl[]; 257 extern const struct kernel_symbol __stop___ksymtab_gpl[];
258 extern const struct kernel_symbol __start___ksymtab_gpl_future[]; 258 extern const struct kernel_symbol __start___ksymtab_gpl_future[];
259 extern const struct kernel_symbol __stop___ksymtab_gpl_future[]; 259 extern const struct kernel_symbol __stop___ksymtab_gpl_future[];
260 extern const unsigned long __start___kcrctab[]; 260 extern const unsigned long __start___kcrctab[];
261 extern const unsigned long __start___kcrctab_gpl[]; 261 extern const unsigned long __start___kcrctab_gpl[];
262 extern const unsigned long __start___kcrctab_gpl_future[]; 262 extern const unsigned long __start___kcrctab_gpl_future[];
263 #ifdef CONFIG_UNUSED_SYMBOLS 263 #ifdef CONFIG_UNUSED_SYMBOLS
264 extern const struct kernel_symbol __start___ksymtab_unused[]; 264 extern const struct kernel_symbol __start___ksymtab_unused[];
265 extern const struct kernel_symbol __stop___ksymtab_unused[]; 265 extern const struct kernel_symbol __stop___ksymtab_unused[];
266 extern const struct kernel_symbol __start___ksymtab_unused_gpl[]; 266 extern const struct kernel_symbol __start___ksymtab_unused_gpl[];
267 extern const struct kernel_symbol __stop___ksymtab_unused_gpl[]; 267 extern const struct kernel_symbol __stop___ksymtab_unused_gpl[];
268 extern const unsigned long __start___kcrctab_unused[]; 268 extern const unsigned long __start___kcrctab_unused[];
269 extern const unsigned long __start___kcrctab_unused_gpl[]; 269 extern const unsigned long __start___kcrctab_unused_gpl[];
270 #endif 270 #endif
271 271
272 #ifndef CONFIG_MODVERSIONS 272 #ifndef CONFIG_MODVERSIONS
273 #define symversion(base, idx) NULL 273 #define symversion(base, idx) NULL
274 #else 274 #else
275 #define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL) 275 #define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL)
276 #endif 276 #endif
277 277
278 static bool each_symbol_in_section(const struct symsearch *arr, 278 static bool each_symbol_in_section(const struct symsearch *arr,
279 unsigned int arrsize, 279 unsigned int arrsize,
280 struct module *owner, 280 struct module *owner,
281 bool (*fn)(const struct symsearch *syms, 281 bool (*fn)(const struct symsearch *syms,
282 struct module *owner, 282 struct module *owner,
283 void *data), 283 void *data),
284 void *data) 284 void *data)
285 { 285 {
286 unsigned int j; 286 unsigned int j;
287 287
288 for (j = 0; j < arrsize; j++) { 288 for (j = 0; j < arrsize; j++) {
289 if (fn(&arr[j], owner, data)) 289 if (fn(&arr[j], owner, data))
290 return true; 290 return true;
291 } 291 }
292 292
293 return false; 293 return false;
294 } 294 }
295 295
296 /* Returns true as soon as fn returns true, otherwise false. */ 296 /* Returns true as soon as fn returns true, otherwise false. */
297 bool each_symbol_section(bool (*fn)(const struct symsearch *arr, 297 bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
298 struct module *owner, 298 struct module *owner,
299 void *data), 299 void *data),
300 void *data) 300 void *data)
301 { 301 {
302 struct module *mod; 302 struct module *mod;
303 static const struct symsearch arr[] = { 303 static const struct symsearch arr[] = {
304 { __start___ksymtab, __stop___ksymtab, __start___kcrctab, 304 { __start___ksymtab, __stop___ksymtab, __start___kcrctab,
305 NOT_GPL_ONLY, false }, 305 NOT_GPL_ONLY, false },
306 { __start___ksymtab_gpl, __stop___ksymtab_gpl, 306 { __start___ksymtab_gpl, __stop___ksymtab_gpl,
307 __start___kcrctab_gpl, 307 __start___kcrctab_gpl,
308 GPL_ONLY, false }, 308 GPL_ONLY, false },
309 { __start___ksymtab_gpl_future, __stop___ksymtab_gpl_future, 309 { __start___ksymtab_gpl_future, __stop___ksymtab_gpl_future,
310 __start___kcrctab_gpl_future, 310 __start___kcrctab_gpl_future,
311 WILL_BE_GPL_ONLY, false }, 311 WILL_BE_GPL_ONLY, false },
312 #ifdef CONFIG_UNUSED_SYMBOLS 312 #ifdef CONFIG_UNUSED_SYMBOLS
313 { __start___ksymtab_unused, __stop___ksymtab_unused, 313 { __start___ksymtab_unused, __stop___ksymtab_unused,
314 __start___kcrctab_unused, 314 __start___kcrctab_unused,
315 NOT_GPL_ONLY, true }, 315 NOT_GPL_ONLY, true },
316 { __start___ksymtab_unused_gpl, __stop___ksymtab_unused_gpl, 316 { __start___ksymtab_unused_gpl, __stop___ksymtab_unused_gpl,
317 __start___kcrctab_unused_gpl, 317 __start___kcrctab_unused_gpl,
318 GPL_ONLY, true }, 318 GPL_ONLY, true },
319 #endif 319 #endif
320 }; 320 };
321 321
322 if (each_symbol_in_section(arr, ARRAY_SIZE(arr), NULL, fn, data)) 322 if (each_symbol_in_section(arr, ARRAY_SIZE(arr), NULL, fn, data))
323 return true; 323 return true;
324 324
325 list_for_each_entry_rcu(mod, &modules, list) { 325 list_for_each_entry_rcu(mod, &modules, list) {
326 struct symsearch arr[] = { 326 struct symsearch arr[] = {
327 { mod->syms, mod->syms + mod->num_syms, mod->crcs, 327 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
328 NOT_GPL_ONLY, false }, 328 NOT_GPL_ONLY, false },
329 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms, 329 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
330 mod->gpl_crcs, 330 mod->gpl_crcs,
331 GPL_ONLY, false }, 331 GPL_ONLY, false },
332 { mod->gpl_future_syms, 332 { mod->gpl_future_syms,
333 mod->gpl_future_syms + mod->num_gpl_future_syms, 333 mod->gpl_future_syms + mod->num_gpl_future_syms,
334 mod->gpl_future_crcs, 334 mod->gpl_future_crcs,
335 WILL_BE_GPL_ONLY, false }, 335 WILL_BE_GPL_ONLY, false },
336 #ifdef CONFIG_UNUSED_SYMBOLS 336 #ifdef CONFIG_UNUSED_SYMBOLS
337 { mod->unused_syms, 337 { mod->unused_syms,
338 mod->unused_syms + mod->num_unused_syms, 338 mod->unused_syms + mod->num_unused_syms,
339 mod->unused_crcs, 339 mod->unused_crcs,
340 NOT_GPL_ONLY, true }, 340 NOT_GPL_ONLY, true },
341 { mod->unused_gpl_syms, 341 { mod->unused_gpl_syms,
342 mod->unused_gpl_syms + mod->num_unused_gpl_syms, 342 mod->unused_gpl_syms + mod->num_unused_gpl_syms,
343 mod->unused_gpl_crcs, 343 mod->unused_gpl_crcs,
344 GPL_ONLY, true }, 344 GPL_ONLY, true },
345 #endif 345 #endif
346 }; 346 };
347 347
348 if (mod->state == MODULE_STATE_UNFORMED) 348 if (mod->state == MODULE_STATE_UNFORMED)
349 continue; 349 continue;
350 350
351 if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data)) 351 if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
352 return true; 352 return true;
353 } 353 }
354 return false; 354 return false;
355 } 355 }
356 EXPORT_SYMBOL_GPL(each_symbol_section); 356 EXPORT_SYMBOL_GPL(each_symbol_section);
357 357
358 struct find_symbol_arg { 358 struct find_symbol_arg {
359 /* Input */ 359 /* Input */
360 const char *name; 360 const char *name;
361 bool gplok; 361 bool gplok;
362 bool warn; 362 bool warn;
363 363
364 /* Output */ 364 /* Output */
365 struct module *owner; 365 struct module *owner;
366 const unsigned long *crc; 366 const unsigned long *crc;
367 const struct kernel_symbol *sym; 367 const struct kernel_symbol *sym;
368 }; 368 };
369 369
370 static bool check_symbol(const struct symsearch *syms, 370 static bool check_symbol(const struct symsearch *syms,
371 struct module *owner, 371 struct module *owner,
372 unsigned int symnum, void *data) 372 unsigned int symnum, void *data)
373 { 373 {
374 struct find_symbol_arg *fsa = data; 374 struct find_symbol_arg *fsa = data;
375 375
376 if (!fsa->gplok) { 376 if (!fsa->gplok) {
377 if (syms->licence == GPL_ONLY) 377 if (syms->licence == GPL_ONLY)
378 return false; 378 return false;
379 if (syms->licence == WILL_BE_GPL_ONLY && fsa->warn) { 379 if (syms->licence == WILL_BE_GPL_ONLY && fsa->warn) {
380 printk(KERN_WARNING "Symbol %s is being used " 380 printk(KERN_WARNING "Symbol %s is being used "
381 "by a non-GPL module, which will not " 381 "by a non-GPL module, which will not "
382 "be allowed in the future\n", fsa->name); 382 "be allowed in the future\n", fsa->name);
383 } 383 }
384 } 384 }
385 385
386 #ifdef CONFIG_UNUSED_SYMBOLS 386 #ifdef CONFIG_UNUSED_SYMBOLS
387 if (syms->unused && fsa->warn) { 387 if (syms->unused && fsa->warn) {
388 printk(KERN_WARNING "Symbol %s is marked as UNUSED, " 388 printk(KERN_WARNING "Symbol %s is marked as UNUSED, "
389 "however this module is using it.\n", fsa->name); 389 "however this module is using it.\n", fsa->name);
390 printk(KERN_WARNING 390 printk(KERN_WARNING
391 "This symbol will go away in the future.\n"); 391 "This symbol will go away in the future.\n");
392 printk(KERN_WARNING 392 printk(KERN_WARNING
393 "Please evalute if this is the right api to use and if " 393 "Please evalute if this is the right api to use and if "
394 "it really is, submit a report the linux kernel " 394 "it really is, submit a report the linux kernel "
395 "mailinglist together with submitting your code for " 395 "mailinglist together with submitting your code for "
396 "inclusion.\n"); 396 "inclusion.\n");
397 } 397 }
398 #endif 398 #endif
399 399
400 fsa->owner = owner; 400 fsa->owner = owner;
401 fsa->crc = symversion(syms->crcs, symnum); 401 fsa->crc = symversion(syms->crcs, symnum);
402 fsa->sym = &syms->start[symnum]; 402 fsa->sym = &syms->start[symnum];
403 return true; 403 return true;
404 } 404 }
405 405
406 static int cmp_name(const void *va, const void *vb) 406 static int cmp_name(const void *va, const void *vb)
407 { 407 {
408 const char *a; 408 const char *a;
409 const struct kernel_symbol *b; 409 const struct kernel_symbol *b;
410 a = va; b = vb; 410 a = va; b = vb;
411 return strcmp(a, b->name); 411 return strcmp(a, b->name);
412 } 412 }
413 413
414 static bool find_symbol_in_section(const struct symsearch *syms, 414 static bool find_symbol_in_section(const struct symsearch *syms,
415 struct module *owner, 415 struct module *owner,
416 void *data) 416 void *data)
417 { 417 {
418 struct find_symbol_arg *fsa = data; 418 struct find_symbol_arg *fsa = data;
419 struct kernel_symbol *sym; 419 struct kernel_symbol *sym;
420 420
421 sym = bsearch(fsa->name, syms->start, syms->stop - syms->start, 421 sym = bsearch(fsa->name, syms->start, syms->stop - syms->start,
422 sizeof(struct kernel_symbol), cmp_name); 422 sizeof(struct kernel_symbol), cmp_name);
423 423
424 if (sym != NULL && check_symbol(syms, owner, sym - syms->start, data)) 424 if (sym != NULL && check_symbol(syms, owner, sym - syms->start, data))
425 return true; 425 return true;
426 426
427 return false; 427 return false;
428 } 428 }
429 429
430 /* Find a symbol and return it, along with, (optional) crc and 430 /* Find a symbol and return it, along with, (optional) crc and
431 * (optional) module which owns it. Needs preempt disabled or module_mutex. */ 431 * (optional) module which owns it. Needs preempt disabled or module_mutex. */
432 const struct kernel_symbol *find_symbol(const char *name, 432 const struct kernel_symbol *find_symbol(const char *name,
433 struct module **owner, 433 struct module **owner,
434 const unsigned long **crc, 434 const unsigned long **crc,
435 bool gplok, 435 bool gplok,
436 bool warn) 436 bool warn)
437 { 437 {
438 struct find_symbol_arg fsa; 438 struct find_symbol_arg fsa;
439 439
440 fsa.name = name; 440 fsa.name = name;
441 fsa.gplok = gplok; 441 fsa.gplok = gplok;
442 fsa.warn = warn; 442 fsa.warn = warn;
443 443
444 if (each_symbol_section(find_symbol_in_section, &fsa)) { 444 if (each_symbol_section(find_symbol_in_section, &fsa)) {
445 if (owner) 445 if (owner)
446 *owner = fsa.owner; 446 *owner = fsa.owner;
447 if (crc) 447 if (crc)
448 *crc = fsa.crc; 448 *crc = fsa.crc;
449 return fsa.sym; 449 return fsa.sym;
450 } 450 }
451 451
452 pr_debug("Failed to find symbol %s\n", name); 452 pr_debug("Failed to find symbol %s\n", name);
453 return NULL; 453 return NULL;
454 } 454 }
455 EXPORT_SYMBOL_GPL(find_symbol); 455 EXPORT_SYMBOL_GPL(find_symbol);
456 456
457 /* Search for module by name: must hold module_mutex. */ 457 /* Search for module by name: must hold module_mutex. */
458 static struct module *find_module_all(const char *name, 458 static struct module *find_module_all(const char *name,
459 bool even_unformed) 459 bool even_unformed)
460 { 460 {
461 struct module *mod; 461 struct module *mod;
462 462
463 list_for_each_entry(mod, &modules, list) { 463 list_for_each_entry(mod, &modules, list) {
464 if (!even_unformed && mod->state == MODULE_STATE_UNFORMED) 464 if (!even_unformed && mod->state == MODULE_STATE_UNFORMED)
465 continue; 465 continue;
466 if (strcmp(mod->name, name) == 0) 466 if (strcmp(mod->name, name) == 0)
467 return mod; 467 return mod;
468 } 468 }
469 return NULL; 469 return NULL;
470 } 470 }
471 471
472 struct module *find_module(const char *name) 472 struct module *find_module(const char *name)
473 { 473 {
474 return find_module_all(name, false); 474 return find_module_all(name, false);
475 } 475 }
476 EXPORT_SYMBOL_GPL(find_module); 476 EXPORT_SYMBOL_GPL(find_module);
477 477
478 #ifdef CONFIG_SMP 478 #ifdef CONFIG_SMP
479 479
480 static inline void __percpu *mod_percpu(struct module *mod) 480 static inline void __percpu *mod_percpu(struct module *mod)
481 { 481 {
482 return mod->percpu; 482 return mod->percpu;
483 } 483 }
484 484
485 static int percpu_modalloc(struct module *mod, 485 static int percpu_modalloc(struct module *mod,
486 unsigned long size, unsigned long align) 486 unsigned long size, unsigned long align)
487 { 487 {
488 if (align > PAGE_SIZE) { 488 if (align > PAGE_SIZE) {
489 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n", 489 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
490 mod->name, align, PAGE_SIZE); 490 mod->name, align, PAGE_SIZE);
491 align = PAGE_SIZE; 491 align = PAGE_SIZE;
492 } 492 }
493 493
494 mod->percpu = __alloc_reserved_percpu(size, align); 494 mod->percpu = __alloc_reserved_percpu(size, align);
495 if (!mod->percpu) { 495 if (!mod->percpu) {
496 printk(KERN_WARNING 496 printk(KERN_WARNING
497 "%s: Could not allocate %lu bytes percpu data\n", 497 "%s: Could not allocate %lu bytes percpu data\n",
498 mod->name, size); 498 mod->name, size);
499 return -ENOMEM; 499 return -ENOMEM;
500 } 500 }
501 mod->percpu_size = size; 501 mod->percpu_size = size;
502 return 0; 502 return 0;
503 } 503 }
504 504
505 static void percpu_modfree(struct module *mod) 505 static void percpu_modfree(struct module *mod)
506 { 506 {
507 free_percpu(mod->percpu); 507 free_percpu(mod->percpu);
508 } 508 }
509 509
510 static unsigned int find_pcpusec(struct load_info *info) 510 static unsigned int find_pcpusec(struct load_info *info)
511 { 511 {
512 return find_sec(info, ".data..percpu"); 512 return find_sec(info, ".data..percpu");
513 } 513 }
514 514
515 static void percpu_modcopy(struct module *mod, 515 static void percpu_modcopy(struct module *mod,
516 const void *from, unsigned long size) 516 const void *from, unsigned long size)
517 { 517 {
518 int cpu; 518 int cpu;
519 519
520 for_each_possible_cpu(cpu) 520 for_each_possible_cpu(cpu)
521 memcpy(per_cpu_ptr(mod->percpu, cpu), from, size); 521 memcpy(per_cpu_ptr(mod->percpu, cpu), from, size);
522 } 522 }
523 523
524 /** 524 /**
525 * is_module_percpu_address - test whether address is from module static percpu 525 * is_module_percpu_address - test whether address is from module static percpu
526 * @addr: address to test 526 * @addr: address to test
527 * 527 *
528 * Test whether @addr belongs to module static percpu area. 528 * Test whether @addr belongs to module static percpu area.
529 * 529 *
530 * RETURNS: 530 * RETURNS:
531 * %true if @addr is from module static percpu area 531 * %true if @addr is from module static percpu area
532 */ 532 */
533 bool is_module_percpu_address(unsigned long addr) 533 bool is_module_percpu_address(unsigned long addr)
534 { 534 {
535 struct module *mod; 535 struct module *mod;
536 unsigned int cpu; 536 unsigned int cpu;
537 537
538 preempt_disable(); 538 preempt_disable();
539 539
540 list_for_each_entry_rcu(mod, &modules, list) { 540 list_for_each_entry_rcu(mod, &modules, list) {
541 if (mod->state == MODULE_STATE_UNFORMED) 541 if (mod->state == MODULE_STATE_UNFORMED)
542 continue; 542 continue;
543 if (!mod->percpu_size) 543 if (!mod->percpu_size)
544 continue; 544 continue;
545 for_each_possible_cpu(cpu) { 545 for_each_possible_cpu(cpu) {
546 void *start = per_cpu_ptr(mod->percpu, cpu); 546 void *start = per_cpu_ptr(mod->percpu, cpu);
547 547
548 if ((void *)addr >= start && 548 if ((void *)addr >= start &&
549 (void *)addr < start + mod->percpu_size) { 549 (void *)addr < start + mod->percpu_size) {
550 preempt_enable(); 550 preempt_enable();
551 return true; 551 return true;
552 } 552 }
553 } 553 }
554 } 554 }
555 555
556 preempt_enable(); 556 preempt_enable();
557 return false; 557 return false;
558 } 558 }
559 559
560 #else /* ... !CONFIG_SMP */ 560 #else /* ... !CONFIG_SMP */
561 561
562 static inline void __percpu *mod_percpu(struct module *mod) 562 static inline void __percpu *mod_percpu(struct module *mod)
563 { 563 {
564 return NULL; 564 return NULL;
565 } 565 }
566 static inline int percpu_modalloc(struct module *mod, 566 static inline int percpu_modalloc(struct module *mod,
567 unsigned long size, unsigned long align) 567 unsigned long size, unsigned long align)
568 { 568 {
569 return -ENOMEM; 569 return -ENOMEM;
570 } 570 }
571 static inline void percpu_modfree(struct module *mod) 571 static inline void percpu_modfree(struct module *mod)
572 { 572 {
573 } 573 }
574 static unsigned int find_pcpusec(struct load_info *info) 574 static unsigned int find_pcpusec(struct load_info *info)
575 { 575 {
576 return 0; 576 return 0;
577 } 577 }
578 static inline void percpu_modcopy(struct module *mod, 578 static inline void percpu_modcopy(struct module *mod,
579 const void *from, unsigned long size) 579 const void *from, unsigned long size)
580 { 580 {
581 /* pcpusec should be 0, and size of that section should be 0. */ 581 /* pcpusec should be 0, and size of that section should be 0. */
582 BUG_ON(size != 0); 582 BUG_ON(size != 0);
583 } 583 }
584 bool is_module_percpu_address(unsigned long addr) 584 bool is_module_percpu_address(unsigned long addr)
585 { 585 {
586 return false; 586 return false;
587 } 587 }
588 588
589 #endif /* CONFIG_SMP */ 589 #endif /* CONFIG_SMP */
590 590
591 #define MODINFO_ATTR(field) \ 591 #define MODINFO_ATTR(field) \
592 static void setup_modinfo_##field(struct module *mod, const char *s) \ 592 static void setup_modinfo_##field(struct module *mod, const char *s) \
593 { \ 593 { \
594 mod->field = kstrdup(s, GFP_KERNEL); \ 594 mod->field = kstrdup(s, GFP_KERNEL); \
595 } \ 595 } \
596 static ssize_t show_modinfo_##field(struct module_attribute *mattr, \ 596 static ssize_t show_modinfo_##field(struct module_attribute *mattr, \
597 struct module_kobject *mk, char *buffer) \ 597 struct module_kobject *mk, char *buffer) \
598 { \ 598 { \
599 return sprintf(buffer, "%s\n", mk->mod->field); \ 599 return sprintf(buffer, "%s\n", mk->mod->field); \
600 } \ 600 } \
601 static int modinfo_##field##_exists(struct module *mod) \ 601 static int modinfo_##field##_exists(struct module *mod) \
602 { \ 602 { \
603 return mod->field != NULL; \ 603 return mod->field != NULL; \
604 } \ 604 } \
605 static void free_modinfo_##field(struct module *mod) \ 605 static void free_modinfo_##field(struct module *mod) \
606 { \ 606 { \
607 kfree(mod->field); \ 607 kfree(mod->field); \
608 mod->field = NULL; \ 608 mod->field = NULL; \
609 } \ 609 } \
610 static struct module_attribute modinfo_##field = { \ 610 static struct module_attribute modinfo_##field = { \
611 .attr = { .name = __stringify(field), .mode = 0444 }, \ 611 .attr = { .name = __stringify(field), .mode = 0444 }, \
612 .show = show_modinfo_##field, \ 612 .show = show_modinfo_##field, \
613 .setup = setup_modinfo_##field, \ 613 .setup = setup_modinfo_##field, \
614 .test = modinfo_##field##_exists, \ 614 .test = modinfo_##field##_exists, \
615 .free = free_modinfo_##field, \ 615 .free = free_modinfo_##field, \
616 }; 616 };
617 617
618 MODINFO_ATTR(version); 618 MODINFO_ATTR(version);
619 MODINFO_ATTR(srcversion); 619 MODINFO_ATTR(srcversion);
620 620
621 static char last_unloaded_module[MODULE_NAME_LEN+1]; 621 static char last_unloaded_module[MODULE_NAME_LEN+1];
622 622
623 #ifdef CONFIG_MODULE_UNLOAD 623 #ifdef CONFIG_MODULE_UNLOAD
624 624
625 EXPORT_TRACEPOINT_SYMBOL(module_get); 625 EXPORT_TRACEPOINT_SYMBOL(module_get);
626 626
627 /* Init the unload section of the module. */ 627 /* Init the unload section of the module. */
628 static int module_unload_init(struct module *mod) 628 static int module_unload_init(struct module *mod)
629 { 629 {
630 mod->refptr = alloc_percpu(struct module_ref); 630 mod->refptr = alloc_percpu(struct module_ref);
631 if (!mod->refptr) 631 if (!mod->refptr)
632 return -ENOMEM; 632 return -ENOMEM;
633 633
634 INIT_LIST_HEAD(&mod->source_list); 634 INIT_LIST_HEAD(&mod->source_list);
635 INIT_LIST_HEAD(&mod->target_list); 635 INIT_LIST_HEAD(&mod->target_list);
636 636
637 /* Hold reference count during initialization. */ 637 /* Hold reference count during initialization. */
638 __this_cpu_write(mod->refptr->incs, 1); 638 __this_cpu_write(mod->refptr->incs, 1);
639 /* Backwards compatibility macros put refcount during init. */ 639 /* Backwards compatibility macros put refcount during init. */
640 mod->waiter = current; 640 mod->waiter = current;
641 641
642 return 0; 642 return 0;
643 } 643 }
644 644
645 /* Does a already use b? */ 645 /* Does a already use b? */
646 static int already_uses(struct module *a, struct module *b) 646 static int already_uses(struct module *a, struct module *b)
647 { 647 {
648 struct module_use *use; 648 struct module_use *use;
649 649
650 list_for_each_entry(use, &b->source_list, source_list) { 650 list_for_each_entry(use, &b->source_list, source_list) {
651 if (use->source == a) { 651 if (use->source == a) {
652 pr_debug("%s uses %s!\n", a->name, b->name); 652 pr_debug("%s uses %s!\n", a->name, b->name);
653 return 1; 653 return 1;
654 } 654 }
655 } 655 }
656 pr_debug("%s does not use %s!\n", a->name, b->name); 656 pr_debug("%s does not use %s!\n", a->name, b->name);
657 return 0; 657 return 0;
658 } 658 }
659 659
660 /* 660 /*
661 * Module a uses b 661 * Module a uses b
662 * - we add 'a' as a "source", 'b' as a "target" of module use 662 * - we add 'a' as a "source", 'b' as a "target" of module use
663 * - the module_use is added to the list of 'b' sources (so 663 * - the module_use is added to the list of 'b' sources (so
664 * 'b' can walk the list to see who sourced them), and of 'a' 664 * 'b' can walk the list to see who sourced them), and of 'a'
665 * targets (so 'a' can see what modules it targets). 665 * targets (so 'a' can see what modules it targets).
666 */ 666 */
667 static int add_module_usage(struct module *a, struct module *b) 667 static int add_module_usage(struct module *a, struct module *b)
668 { 668 {
669 struct module_use *use; 669 struct module_use *use;
670 670
671 pr_debug("Allocating new usage for %s.\n", a->name); 671 pr_debug("Allocating new usage for %s.\n", a->name);
672 use = kmalloc(sizeof(*use), GFP_ATOMIC); 672 use = kmalloc(sizeof(*use), GFP_ATOMIC);
673 if (!use) { 673 if (!use) {
674 printk(KERN_WARNING "%s: out of memory loading\n", a->name); 674 printk(KERN_WARNING "%s: out of memory loading\n", a->name);
675 return -ENOMEM; 675 return -ENOMEM;
676 } 676 }
677 677
678 use->source = a; 678 use->source = a;
679 use->target = b; 679 use->target = b;
680 list_add(&use->source_list, &b->source_list); 680 list_add(&use->source_list, &b->source_list);
681 list_add(&use->target_list, &a->target_list); 681 list_add(&use->target_list, &a->target_list);
682 return 0; 682 return 0;
683 } 683 }
684 684
685 /* Module a uses b: caller needs module_mutex() */ 685 /* Module a uses b: caller needs module_mutex() */
686 int ref_module(struct module *a, struct module *b) 686 int ref_module(struct module *a, struct module *b)
687 { 687 {
688 int err; 688 int err;
689 689
690 if (b == NULL || already_uses(a, b)) 690 if (b == NULL || already_uses(a, b))
691 return 0; 691 return 0;
692 692
693 /* If module isn't available, we fail. */ 693 /* If module isn't available, we fail. */
694 err = strong_try_module_get(b); 694 err = strong_try_module_get(b);
695 if (err) 695 if (err)
696 return err; 696 return err;
697 697
698 err = add_module_usage(a, b); 698 err = add_module_usage(a, b);
699 if (err) { 699 if (err) {
700 module_put(b); 700 module_put(b);
701 return err; 701 return err;
702 } 702 }
703 return 0; 703 return 0;
704 } 704 }
705 EXPORT_SYMBOL_GPL(ref_module); 705 EXPORT_SYMBOL_GPL(ref_module);
706 706
707 /* Clear the unload stuff of the module. */ 707 /* Clear the unload stuff of the module. */
708 static void module_unload_free(struct module *mod) 708 static void module_unload_free(struct module *mod)
709 { 709 {
710 struct module_use *use, *tmp; 710 struct module_use *use, *tmp;
711 711
712 mutex_lock(&module_mutex); 712 mutex_lock(&module_mutex);
713 list_for_each_entry_safe(use, tmp, &mod->target_list, target_list) { 713 list_for_each_entry_safe(use, tmp, &mod->target_list, target_list) {
714 struct module *i = use->target; 714 struct module *i = use->target;
715 pr_debug("%s unusing %s\n", mod->name, i->name); 715 pr_debug("%s unusing %s\n", mod->name, i->name);
716 module_put(i); 716 module_put(i);
717 list_del(&use->source_list); 717 list_del(&use->source_list);
718 list_del(&use->target_list); 718 list_del(&use->target_list);
719 kfree(use); 719 kfree(use);
720 } 720 }
721 mutex_unlock(&module_mutex); 721 mutex_unlock(&module_mutex);
722 722
723 free_percpu(mod->refptr); 723 free_percpu(mod->refptr);
724 } 724 }
725 725
726 #ifdef CONFIG_MODULE_FORCE_UNLOAD 726 #ifdef CONFIG_MODULE_FORCE_UNLOAD
727 static inline int try_force_unload(unsigned int flags) 727 static inline int try_force_unload(unsigned int flags)
728 { 728 {
729 int ret = (flags & O_TRUNC); 729 int ret = (flags & O_TRUNC);
730 if (ret) 730 if (ret)
731 add_taint(TAINT_FORCED_RMMOD, LOCKDEP_NOW_UNRELIABLE); 731 add_taint(TAINT_FORCED_RMMOD, LOCKDEP_NOW_UNRELIABLE);
732 return ret; 732 return ret;
733 } 733 }
734 #else 734 #else
735 static inline int try_force_unload(unsigned int flags) 735 static inline int try_force_unload(unsigned int flags)
736 { 736 {
737 return 0; 737 return 0;
738 } 738 }
739 #endif /* CONFIG_MODULE_FORCE_UNLOAD */ 739 #endif /* CONFIG_MODULE_FORCE_UNLOAD */
740 740
741 struct stopref 741 struct stopref
742 { 742 {
743 struct module *mod; 743 struct module *mod;
744 int flags; 744 int flags;
745 int *forced; 745 int *forced;
746 }; 746 };
747 747
748 /* Whole machine is stopped with interrupts off when this runs. */ 748 /* Whole machine is stopped with interrupts off when this runs. */
749 static int __try_stop_module(void *_sref) 749 static int __try_stop_module(void *_sref)
750 { 750 {
751 struct stopref *sref = _sref; 751 struct stopref *sref = _sref;
752 752
753 /* If it's not unused, quit unless we're forcing. */ 753 /* If it's not unused, quit unless we're forcing. */
754 if (module_refcount(sref->mod) != 0) { 754 if (module_refcount(sref->mod) != 0) {
755 if (!(*sref->forced = try_force_unload(sref->flags))) 755 if (!(*sref->forced = try_force_unload(sref->flags)))
756 return -EWOULDBLOCK; 756 return -EWOULDBLOCK;
757 } 757 }
758 758
759 /* Mark it as dying. */ 759 /* Mark it as dying. */
760 sref->mod->state = MODULE_STATE_GOING; 760 sref->mod->state = MODULE_STATE_GOING;
761 return 0; 761 return 0;
762 } 762 }
763 763
764 static int try_stop_module(struct module *mod, int flags, int *forced) 764 static int try_stop_module(struct module *mod, int flags, int *forced)
765 { 765 {
766 if (flags & O_NONBLOCK) { 766 if (flags & O_NONBLOCK) {
767 struct stopref sref = { mod, flags, forced }; 767 struct stopref sref = { mod, flags, forced };
768 768
769 return stop_machine(__try_stop_module, &sref, NULL); 769 return stop_machine(__try_stop_module, &sref, NULL);
770 } else { 770 } else {
771 /* We don't need to stop the machine for this. */ 771 /* We don't need to stop the machine for this. */
772 mod->state = MODULE_STATE_GOING; 772 mod->state = MODULE_STATE_GOING;
773 synchronize_sched(); 773 synchronize_sched();
774 return 0; 774 return 0;
775 } 775 }
776 } 776 }
777 777
778 unsigned long module_refcount(struct module *mod) 778 unsigned long module_refcount(struct module *mod)
779 { 779 {
780 unsigned long incs = 0, decs = 0; 780 unsigned long incs = 0, decs = 0;
781 int cpu; 781 int cpu;
782 782
783 for_each_possible_cpu(cpu) 783 for_each_possible_cpu(cpu)
784 decs += per_cpu_ptr(mod->refptr, cpu)->decs; 784 decs += per_cpu_ptr(mod->refptr, cpu)->decs;
785 /* 785 /*
786 * ensure the incs are added up after the decs. 786 * ensure the incs are added up after the decs.
787 * module_put ensures incs are visible before decs with smp_wmb. 787 * module_put ensures incs are visible before decs with smp_wmb.
788 * 788 *
789 * This 2-count scheme avoids the situation where the refcount 789 * This 2-count scheme avoids the situation where the refcount
790 * for CPU0 is read, then CPU0 increments the module refcount, 790 * for CPU0 is read, then CPU0 increments the module refcount,
791 * then CPU1 drops that refcount, then the refcount for CPU1 is 791 * then CPU1 drops that refcount, then the refcount for CPU1 is
792 * read. We would record a decrement but not its corresponding 792 * read. We would record a decrement but not its corresponding
793 * increment so we would see a low count (disaster). 793 * increment so we would see a low count (disaster).
794 * 794 *
795 * Rare situation? But module_refcount can be preempted, and we 795 * Rare situation? But module_refcount can be preempted, and we
796 * might be tallying up 4096+ CPUs. So it is not impossible. 796 * might be tallying up 4096+ CPUs. So it is not impossible.
797 */ 797 */
798 smp_rmb(); 798 smp_rmb();
799 for_each_possible_cpu(cpu) 799 for_each_possible_cpu(cpu)
800 incs += per_cpu_ptr(mod->refptr, cpu)->incs; 800 incs += per_cpu_ptr(mod->refptr, cpu)->incs;
801 return incs - decs; 801 return incs - decs;
802 } 802 }
803 EXPORT_SYMBOL(module_refcount); 803 EXPORT_SYMBOL(module_refcount);
804 804
805 /* This exists whether we can unload or not */ 805 /* This exists whether we can unload or not */
806 static void free_module(struct module *mod); 806 static void free_module(struct module *mod);
807 807
808 static void wait_for_zero_refcount(struct module *mod) 808 static void wait_for_zero_refcount(struct module *mod)
809 { 809 {
810 /* Since we might sleep for some time, release the mutex first */ 810 /* Since we might sleep for some time, release the mutex first */
811 mutex_unlock(&module_mutex); 811 mutex_unlock(&module_mutex);
812 for (;;) { 812 for (;;) {
813 pr_debug("Looking at refcount...\n"); 813 pr_debug("Looking at refcount...\n");
814 set_current_state(TASK_UNINTERRUPTIBLE); 814 set_current_state(TASK_UNINTERRUPTIBLE);
815 if (module_refcount(mod) == 0) 815 if (module_refcount(mod) == 0)
816 break; 816 break;
817 schedule(); 817 schedule();
818 } 818 }
819 current->state = TASK_RUNNING; 819 current->state = TASK_RUNNING;
820 mutex_lock(&module_mutex); 820 mutex_lock(&module_mutex);
821 } 821 }
822 822
823 SYSCALL_DEFINE2(delete_module, const char __user *, name_user, 823 SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
824 unsigned int, flags) 824 unsigned int, flags)
825 { 825 {
826 struct module *mod; 826 struct module *mod;
827 char name[MODULE_NAME_LEN]; 827 char name[MODULE_NAME_LEN];
828 int ret, forced = 0; 828 int ret, forced = 0;
829 829
830 if (!capable(CAP_SYS_MODULE) || modules_disabled) 830 if (!capable(CAP_SYS_MODULE) || modules_disabled)
831 return -EPERM; 831 return -EPERM;
832 832
833 if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0) 833 if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
834 return -EFAULT; 834 return -EFAULT;
835 name[MODULE_NAME_LEN-1] = '\0'; 835 name[MODULE_NAME_LEN-1] = '\0';
836 836
837 if (mutex_lock_interruptible(&module_mutex) != 0) 837 if (mutex_lock_interruptible(&module_mutex) != 0)
838 return -EINTR; 838 return -EINTR;
839 839
840 mod = find_module(name); 840 mod = find_module(name);
841 if (!mod) { 841 if (!mod) {
842 ret = -ENOENT; 842 ret = -ENOENT;
843 goto out; 843 goto out;
844 } 844 }
845 845
846 if (!list_empty(&mod->source_list)) { 846 if (!list_empty(&mod->source_list)) {
847 /* Other modules depend on us: get rid of them first. */ 847 /* Other modules depend on us: get rid of them first. */
848 ret = -EWOULDBLOCK; 848 ret = -EWOULDBLOCK;
849 goto out; 849 goto out;
850 } 850 }
851 851
852 /* Doing init or already dying? */ 852 /* Doing init or already dying? */
853 if (mod->state != MODULE_STATE_LIVE) { 853 if (mod->state != MODULE_STATE_LIVE) {
854 /* FIXME: if (force), slam module count and wake up 854 /* FIXME: if (force), slam module count and wake up
855 waiter --RR */ 855 waiter --RR */
856 pr_debug("%s already dying\n", mod->name); 856 pr_debug("%s already dying\n", mod->name);
857 ret = -EBUSY; 857 ret = -EBUSY;
858 goto out; 858 goto out;
859 } 859 }
860 860
861 /* If it has an init func, it must have an exit func to unload */ 861 /* If it has an init func, it must have an exit func to unload */
862 if (mod->init && !mod->exit) { 862 if (mod->init && !mod->exit) {
863 forced = try_force_unload(flags); 863 forced = try_force_unload(flags);
864 if (!forced) { 864 if (!forced) {
865 /* This module can't be removed */ 865 /* This module can't be removed */
866 ret = -EBUSY; 866 ret = -EBUSY;
867 goto out; 867 goto out;
868 } 868 }
869 } 869 }
870 870
871 /* Set this up before setting mod->state */ 871 /* Set this up before setting mod->state */
872 mod->waiter = current; 872 mod->waiter = current;
873 873
874 /* Stop the machine so refcounts can't move and disable module. */ 874 /* Stop the machine so refcounts can't move and disable module. */
875 ret = try_stop_module(mod, flags, &forced); 875 ret = try_stop_module(mod, flags, &forced);
876 if (ret != 0) 876 if (ret != 0)
877 goto out; 877 goto out;
878 878
879 /* Never wait if forced. */ 879 /* Never wait if forced. */
880 if (!forced && module_refcount(mod) != 0) 880 if (!forced && module_refcount(mod) != 0)
881 wait_for_zero_refcount(mod); 881 wait_for_zero_refcount(mod);
882 882
883 mutex_unlock(&module_mutex); 883 mutex_unlock(&module_mutex);
884 /* Final destruction now no one is using it. */ 884 /* Final destruction now no one is using it. */
885 if (mod->exit != NULL) 885 if (mod->exit != NULL)
886 mod->exit(); 886 mod->exit();
887 blocking_notifier_call_chain(&module_notify_list, 887 blocking_notifier_call_chain(&module_notify_list,
888 MODULE_STATE_GOING, mod); 888 MODULE_STATE_GOING, mod);
889 async_synchronize_full(); 889 async_synchronize_full();
890 890
891 /* Store the name of the last unloaded module for diagnostic purposes */ 891 /* Store the name of the last unloaded module for diagnostic purposes */
892 strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module)); 892 strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module));
893 893
894 free_module(mod); 894 free_module(mod);
895 return 0; 895 return 0;
896 out: 896 out:
897 mutex_unlock(&module_mutex); 897 mutex_unlock(&module_mutex);
898 return ret; 898 return ret;
899 } 899 }
900 900
901 static inline void print_unload_info(struct seq_file *m, struct module *mod) 901 static inline void print_unload_info(struct seq_file *m, struct module *mod)
902 { 902 {
903 struct module_use *use; 903 struct module_use *use;
904 int printed_something = 0; 904 int printed_something = 0;
905 905
906 seq_printf(m, " %lu ", module_refcount(mod)); 906 seq_printf(m, " %lu ", module_refcount(mod));
907 907
908 /* Always include a trailing , so userspace can differentiate 908 /* Always include a trailing , so userspace can differentiate
909 between this and the old multi-field proc format. */ 909 between this and the old multi-field proc format. */
910 list_for_each_entry(use, &mod->source_list, source_list) { 910 list_for_each_entry(use, &mod->source_list, source_list) {
911 printed_something = 1; 911 printed_something = 1;
912 seq_printf(m, "%s,", use->source->name); 912 seq_printf(m, "%s,", use->source->name);
913 } 913 }
914 914
915 if (mod->init != NULL && mod->exit == NULL) { 915 if (mod->init != NULL && mod->exit == NULL) {
916 printed_something = 1; 916 printed_something = 1;
917 seq_printf(m, "[permanent],"); 917 seq_printf(m, "[permanent],");
918 } 918 }
919 919
920 if (!printed_something) 920 if (!printed_something)
921 seq_printf(m, "-"); 921 seq_printf(m, "-");
922 } 922 }
923 923
924 void __symbol_put(const char *symbol) 924 void __symbol_put(const char *symbol)
925 { 925 {
926 struct module *owner; 926 struct module *owner;
927 927
928 preempt_disable(); 928 preempt_disable();
929 if (!find_symbol(symbol, &owner, NULL, true, false)) 929 if (!find_symbol(symbol, &owner, NULL, true, false))
930 BUG(); 930 BUG();
931 module_put(owner); 931 module_put(owner);
932 preempt_enable(); 932 preempt_enable();
933 } 933 }
934 EXPORT_SYMBOL(__symbol_put); 934 EXPORT_SYMBOL(__symbol_put);
935 935
936 /* Note this assumes addr is a function, which it currently always is. */ 936 /* Note this assumes addr is a function, which it currently always is. */
937 void symbol_put_addr(void *addr) 937 void symbol_put_addr(void *addr)
938 { 938 {
939 struct module *modaddr; 939 struct module *modaddr;
940 unsigned long a = (unsigned long)dereference_function_descriptor(addr); 940 unsigned long a = (unsigned long)dereference_function_descriptor(addr);
941 941
942 if (core_kernel_text(a)) 942 if (core_kernel_text(a))
943 return; 943 return;
944 944
945 /* module_text_address is safe here: we're supposed to have reference 945 /* module_text_address is safe here: we're supposed to have reference
946 * to module from symbol_get, so it can't go away. */ 946 * to module from symbol_get, so it can't go away. */
947 modaddr = __module_text_address(a); 947 modaddr = __module_text_address(a);
948 BUG_ON(!modaddr); 948 BUG_ON(!modaddr);
949 module_put(modaddr); 949 module_put(modaddr);
950 } 950 }
951 EXPORT_SYMBOL_GPL(symbol_put_addr); 951 EXPORT_SYMBOL_GPL(symbol_put_addr);
952 952
953 static ssize_t show_refcnt(struct module_attribute *mattr, 953 static ssize_t show_refcnt(struct module_attribute *mattr,
954 struct module_kobject *mk, char *buffer) 954 struct module_kobject *mk, char *buffer)
955 { 955 {
956 return sprintf(buffer, "%lu\n", module_refcount(mk->mod)); 956 return sprintf(buffer, "%lu\n", module_refcount(mk->mod));
957 } 957 }
958 958
959 static struct module_attribute modinfo_refcnt = 959 static struct module_attribute modinfo_refcnt =
960 __ATTR(refcnt, 0444, show_refcnt, NULL); 960 __ATTR(refcnt, 0444, show_refcnt, NULL);
961 961
962 void __module_get(struct module *module) 962 void __module_get(struct module *module)
963 { 963 {
964 if (module) { 964 if (module) {
965 preempt_disable(); 965 preempt_disable();
966 __this_cpu_inc(module->refptr->incs); 966 __this_cpu_inc(module->refptr->incs);
967 trace_module_get(module, _RET_IP_); 967 trace_module_get(module, _RET_IP_);
968 preempt_enable(); 968 preempt_enable();
969 } 969 }
970 } 970 }
971 EXPORT_SYMBOL(__module_get); 971 EXPORT_SYMBOL(__module_get);
972 972
973 bool try_module_get(struct module *module) 973 bool try_module_get(struct module *module)
974 { 974 {
975 bool ret = true; 975 bool ret = true;
976 976
977 if (module) { 977 if (module) {
978 preempt_disable(); 978 preempt_disable();
979 979
980 if (likely(module_is_live(module))) { 980 if (likely(module_is_live(module))) {
981 __this_cpu_inc(module->refptr->incs); 981 __this_cpu_inc(module->refptr->incs);
982 trace_module_get(module, _RET_IP_); 982 trace_module_get(module, _RET_IP_);
983 } else 983 } else
984 ret = false; 984 ret = false;
985 985
986 preempt_enable(); 986 preempt_enable();
987 } 987 }
988 return ret; 988 return ret;
989 } 989 }
990 EXPORT_SYMBOL(try_module_get); 990 EXPORT_SYMBOL(try_module_get);
991 991
992 void module_put(struct module *module) 992 void module_put(struct module *module)
993 { 993 {
994 if (module) { 994 if (module) {
995 preempt_disable(); 995 preempt_disable();
996 smp_wmb(); /* see comment in module_refcount */ 996 smp_wmb(); /* see comment in module_refcount */
997 __this_cpu_inc(module->refptr->decs); 997 __this_cpu_inc(module->refptr->decs);
998 998
999 trace_module_put(module, _RET_IP_); 999 trace_module_put(module, _RET_IP_);
1000 /* Maybe they're waiting for us to drop reference? */ 1000 /* Maybe they're waiting for us to drop reference? */
1001 if (unlikely(!module_is_live(module))) 1001 if (unlikely(!module_is_live(module)))
1002 wake_up_process(module->waiter); 1002 wake_up_process(module->waiter);
1003 preempt_enable(); 1003 preempt_enable();
1004 } 1004 }
1005 } 1005 }
1006 EXPORT_SYMBOL(module_put); 1006 EXPORT_SYMBOL(module_put);
1007 1007
1008 #else /* !CONFIG_MODULE_UNLOAD */ 1008 #else /* !CONFIG_MODULE_UNLOAD */
1009 static inline void print_unload_info(struct seq_file *m, struct module *mod) 1009 static inline void print_unload_info(struct seq_file *m, struct module *mod)
1010 { 1010 {
1011 /* We don't know the usage count, or what modules are using. */ 1011 /* We don't know the usage count, or what modules are using. */
1012 seq_printf(m, " - -"); 1012 seq_printf(m, " - -");
1013 } 1013 }
1014 1014
1015 static inline void module_unload_free(struct module *mod) 1015 static inline void module_unload_free(struct module *mod)
1016 { 1016 {
1017 } 1017 }
1018 1018
1019 int ref_module(struct module *a, struct module *b) 1019 int ref_module(struct module *a, struct module *b)
1020 { 1020 {
1021 return strong_try_module_get(b); 1021 return strong_try_module_get(b);
1022 } 1022 }
1023 EXPORT_SYMBOL_GPL(ref_module); 1023 EXPORT_SYMBOL_GPL(ref_module);
1024 1024
1025 static inline int module_unload_init(struct module *mod) 1025 static inline int module_unload_init(struct module *mod)
1026 { 1026 {
1027 return 0; 1027 return 0;
1028 } 1028 }
1029 #endif /* CONFIG_MODULE_UNLOAD */ 1029 #endif /* CONFIG_MODULE_UNLOAD */
1030 1030
1031 static size_t module_flags_taint(struct module *mod, char *buf) 1031 static size_t module_flags_taint(struct module *mod, char *buf)
1032 { 1032 {
1033 size_t l = 0; 1033 size_t l = 0;
1034 1034
1035 if (mod->taints & (1 << TAINT_PROPRIETARY_MODULE)) 1035 if (mod->taints & (1 << TAINT_PROPRIETARY_MODULE))
1036 buf[l++] = 'P'; 1036 buf[l++] = 'P';
1037 if (mod->taints & (1 << TAINT_OOT_MODULE)) 1037 if (mod->taints & (1 << TAINT_OOT_MODULE))
1038 buf[l++] = 'O'; 1038 buf[l++] = 'O';
1039 if (mod->taints & (1 << TAINT_FORCED_MODULE)) 1039 if (mod->taints & (1 << TAINT_FORCED_MODULE))
1040 buf[l++] = 'F'; 1040 buf[l++] = 'F';
1041 if (mod->taints & (1 << TAINT_CRAP)) 1041 if (mod->taints & (1 << TAINT_CRAP))
1042 buf[l++] = 'C'; 1042 buf[l++] = 'C';
1043 /* 1043 /*
1044 * TAINT_FORCED_RMMOD: could be added. 1044 * TAINT_FORCED_RMMOD: could be added.
1045 * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't 1045 * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't
1046 * apply to modules. 1046 * apply to modules.
1047 */ 1047 */
1048 return l; 1048 return l;
1049 } 1049 }
1050 1050
1051 static ssize_t show_initstate(struct module_attribute *mattr, 1051 static ssize_t show_initstate(struct module_attribute *mattr,
1052 struct module_kobject *mk, char *buffer) 1052 struct module_kobject *mk, char *buffer)
1053 { 1053 {
1054 const char *state = "unknown"; 1054 const char *state = "unknown";
1055 1055
1056 switch (mk->mod->state) { 1056 switch (mk->mod->state) {
1057 case MODULE_STATE_LIVE: 1057 case MODULE_STATE_LIVE:
1058 state = "live"; 1058 state = "live";
1059 break; 1059 break;
1060 case MODULE_STATE_COMING: 1060 case MODULE_STATE_COMING:
1061 state = "coming"; 1061 state = "coming";
1062 break; 1062 break;
1063 case MODULE_STATE_GOING: 1063 case MODULE_STATE_GOING:
1064 state = "going"; 1064 state = "going";
1065 break; 1065 break;
1066 default: 1066 default:
1067 BUG(); 1067 BUG();
1068 } 1068 }
1069 return sprintf(buffer, "%s\n", state); 1069 return sprintf(buffer, "%s\n", state);
1070 } 1070 }
1071 1071
1072 static struct module_attribute modinfo_initstate = 1072 static struct module_attribute modinfo_initstate =
1073 __ATTR(initstate, 0444, show_initstate, NULL); 1073 __ATTR(initstate, 0444, show_initstate, NULL);
1074 1074
1075 static ssize_t store_uevent(struct module_attribute *mattr, 1075 static ssize_t store_uevent(struct module_attribute *mattr,
1076 struct module_kobject *mk, 1076 struct module_kobject *mk,
1077 const char *buffer, size_t count) 1077 const char *buffer, size_t count)
1078 { 1078 {
1079 enum kobject_action action; 1079 enum kobject_action action;
1080 1080
1081 if (kobject_action_type(buffer, count, &action) == 0) 1081 if (kobject_action_type(buffer, count, &action) == 0)
1082 kobject_uevent(&mk->kobj, action); 1082 kobject_uevent(&mk->kobj, action);
1083 return count; 1083 return count;
1084 } 1084 }
1085 1085
1086 struct module_attribute module_uevent = 1086 struct module_attribute module_uevent =
1087 __ATTR(uevent, 0200, NULL, store_uevent); 1087 __ATTR(uevent, 0200, NULL, store_uevent);
1088 1088
1089 static ssize_t show_coresize(struct module_attribute *mattr, 1089 static ssize_t show_coresize(struct module_attribute *mattr,
1090 struct module_kobject *mk, char *buffer) 1090 struct module_kobject *mk, char *buffer)
1091 { 1091 {
1092 return sprintf(buffer, "%u\n", mk->mod->core_size); 1092 return sprintf(buffer, "%u\n", mk->mod->core_size);
1093 } 1093 }
1094 1094
1095 static struct module_attribute modinfo_coresize = 1095 static struct module_attribute modinfo_coresize =
1096 __ATTR(coresize, 0444, show_coresize, NULL); 1096 __ATTR(coresize, 0444, show_coresize, NULL);
1097 1097
1098 static ssize_t show_initsize(struct module_attribute *mattr, 1098 static ssize_t show_initsize(struct module_attribute *mattr,
1099 struct module_kobject *mk, char *buffer) 1099 struct module_kobject *mk, char *buffer)
1100 { 1100 {
1101 return sprintf(buffer, "%u\n", mk->mod->init_size); 1101 return sprintf(buffer, "%u\n", mk->mod->init_size);
1102 } 1102 }
1103 1103
1104 static struct module_attribute modinfo_initsize = 1104 static struct module_attribute modinfo_initsize =
1105 __ATTR(initsize, 0444, show_initsize, NULL); 1105 __ATTR(initsize, 0444, show_initsize, NULL);
1106 1106
1107 static ssize_t show_taint(struct module_attribute *mattr, 1107 static ssize_t show_taint(struct module_attribute *mattr,
1108 struct module_kobject *mk, char *buffer) 1108 struct module_kobject *mk, char *buffer)
1109 { 1109 {
1110 size_t l; 1110 size_t l;
1111 1111
1112 l = module_flags_taint(mk->mod, buffer); 1112 l = module_flags_taint(mk->mod, buffer);
1113 buffer[l++] = '\n'; 1113 buffer[l++] = '\n';
1114 return l; 1114 return l;
1115 } 1115 }
1116 1116
1117 static struct module_attribute modinfo_taint = 1117 static struct module_attribute modinfo_taint =
1118 __ATTR(taint, 0444, show_taint, NULL); 1118 __ATTR(taint, 0444, show_taint, NULL);
1119 1119
1120 static struct module_attribute *modinfo_attrs[] = { 1120 static struct module_attribute *modinfo_attrs[] = {
1121 &module_uevent, 1121 &module_uevent,
1122 &modinfo_version, 1122 &modinfo_version,
1123 &modinfo_srcversion, 1123 &modinfo_srcversion,
1124 &modinfo_initstate, 1124 &modinfo_initstate,
1125 &modinfo_coresize, 1125 &modinfo_coresize,
1126 &modinfo_initsize, 1126 &modinfo_initsize,
1127 &modinfo_taint, 1127 &modinfo_taint,
1128 #ifdef CONFIG_MODULE_UNLOAD 1128 #ifdef CONFIG_MODULE_UNLOAD
1129 &modinfo_refcnt, 1129 &modinfo_refcnt,
1130 #endif 1130 #endif
1131 NULL, 1131 NULL,
1132 }; 1132 };
1133 1133
1134 static const char vermagic[] = VERMAGIC_STRING; 1134 static const char vermagic[] = VERMAGIC_STRING;
1135 1135
1136 static int try_to_force_load(struct module *mod, const char *reason) 1136 static int try_to_force_load(struct module *mod, const char *reason)
1137 { 1137 {
1138 #ifdef CONFIG_MODULE_FORCE_LOAD 1138 #ifdef CONFIG_MODULE_FORCE_LOAD
1139 if (!test_taint(TAINT_FORCED_MODULE)) 1139 if (!test_taint(TAINT_FORCED_MODULE))
1140 printk(KERN_WARNING "%s: %s: kernel tainted.\n", 1140 printk(KERN_WARNING "%s: %s: kernel tainted.\n",
1141 mod->name, reason); 1141 mod->name, reason);
1142 add_taint_module(mod, TAINT_FORCED_MODULE, LOCKDEP_NOW_UNRELIABLE); 1142 add_taint_module(mod, TAINT_FORCED_MODULE, LOCKDEP_NOW_UNRELIABLE);
1143 return 0; 1143 return 0;
1144 #else 1144 #else
1145 return -ENOEXEC; 1145 return -ENOEXEC;
1146 #endif 1146 #endif
1147 } 1147 }
1148 1148
1149 #ifdef CONFIG_MODVERSIONS 1149 #ifdef CONFIG_MODVERSIONS
1150 /* If the arch applies (non-zero) relocations to kernel kcrctab, unapply it. */ 1150 /* If the arch applies (non-zero) relocations to kernel kcrctab, unapply it. */
1151 static unsigned long maybe_relocated(unsigned long crc, 1151 static unsigned long maybe_relocated(unsigned long crc,
1152 const struct module *crc_owner) 1152 const struct module *crc_owner)
1153 { 1153 {
1154 #ifdef ARCH_RELOCATES_KCRCTAB 1154 #ifdef ARCH_RELOCATES_KCRCTAB
1155 if (crc_owner == NULL) 1155 if (crc_owner == NULL)
1156 return crc - (unsigned long)reloc_start; 1156 return crc - (unsigned long)reloc_start;
1157 #endif 1157 #endif
1158 return crc; 1158 return crc;
1159 } 1159 }
1160 1160
1161 static int check_version(Elf_Shdr *sechdrs, 1161 static int check_version(Elf_Shdr *sechdrs,
1162 unsigned int versindex, 1162 unsigned int versindex,
1163 const char *symname, 1163 const char *symname,
1164 struct module *mod, 1164 struct module *mod,
1165 const unsigned long *crc, 1165 const unsigned long *crc,
1166 const struct module *crc_owner) 1166 const struct module *crc_owner)
1167 { 1167 {
1168 unsigned int i, num_versions; 1168 unsigned int i, num_versions;
1169 struct modversion_info *versions; 1169 struct modversion_info *versions;
1170 1170
1171 /* Exporting module didn't supply crcs? OK, we're already tainted. */ 1171 /* Exporting module didn't supply crcs? OK, we're already tainted. */
1172 if (!crc) 1172 if (!crc)
1173 return 1; 1173 return 1;
1174 1174
1175 /* No versions at all? modprobe --force does this. */ 1175 /* No versions at all? modprobe --force does this. */
1176 if (versindex == 0) 1176 if (versindex == 0)
1177 return try_to_force_load(mod, symname) == 0; 1177 return try_to_force_load(mod, symname) == 0;
1178 1178
1179 versions = (void *) sechdrs[versindex].sh_addr; 1179 versions = (void *) sechdrs[versindex].sh_addr;
1180 num_versions = sechdrs[versindex].sh_size 1180 num_versions = sechdrs[versindex].sh_size
1181 / sizeof(struct modversion_info); 1181 / sizeof(struct modversion_info);
1182 1182
1183 for (i = 0; i < num_versions; i++) { 1183 for (i = 0; i < num_versions; i++) {
1184 if (strcmp(versions[i].name, symname) != 0) 1184 if (strcmp(versions[i].name, symname) != 0)
1185 continue; 1185 continue;
1186 1186
1187 if (versions[i].crc == maybe_relocated(*crc, crc_owner)) 1187 if (versions[i].crc == maybe_relocated(*crc, crc_owner))
1188 return 1; 1188 return 1;
1189 pr_debug("Found checksum %lX vs module %lX\n", 1189 pr_debug("Found checksum %lX vs module %lX\n",
1190 maybe_relocated(*crc, crc_owner), versions[i].crc); 1190 maybe_relocated(*crc, crc_owner), versions[i].crc);
1191 goto bad_version; 1191 goto bad_version;
1192 } 1192 }
1193 1193
1194 printk(KERN_WARNING "%s: no symbol version for %s\n", 1194 printk(KERN_WARNING "%s: no symbol version for %s\n",
1195 mod->name, symname); 1195 mod->name, symname);
1196 return 0; 1196 return 0;
1197 1197
1198 bad_version: 1198 bad_version:
1199 printk("%s: disagrees about version of symbol %s\n", 1199 printk("%s: disagrees about version of symbol %s\n",
1200 mod->name, symname); 1200 mod->name, symname);
1201 return 0; 1201 return 0;
1202 } 1202 }
1203 1203
1204 static inline int check_modstruct_version(Elf_Shdr *sechdrs, 1204 static inline int check_modstruct_version(Elf_Shdr *sechdrs,
1205 unsigned int versindex, 1205 unsigned int versindex,
1206 struct module *mod) 1206 struct module *mod)
1207 { 1207 {
1208 const unsigned long *crc; 1208 const unsigned long *crc;
1209 1209
1210 /* Since this should be found in kernel (which can't be removed), 1210 /* Since this should be found in kernel (which can't be removed),
1211 * no locking is necessary. */ 1211 * no locking is necessary. */
1212 if (!find_symbol(MODULE_SYMBOL_PREFIX "module_layout", NULL, 1212 if (!find_symbol(VMLINUX_SYMBOL_STR(module_layout), NULL,
1213 &crc, true, false)) 1213 &crc, true, false))
1214 BUG(); 1214 BUG();
1215 return check_version(sechdrs, versindex, "module_layout", mod, crc, 1215 return check_version(sechdrs, versindex,
1216 VMLINUX_SYMBOL_STR(module_layout), mod, crc,
1216 NULL); 1217 NULL);
1217 } 1218 }
1218 1219
1219 /* First part is kernel version, which we ignore if module has crcs. */ 1220 /* First part is kernel version, which we ignore if module has crcs. */
1220 static inline int same_magic(const char *amagic, const char *bmagic, 1221 static inline int same_magic(const char *amagic, const char *bmagic,
1221 bool has_crcs) 1222 bool has_crcs)
1222 { 1223 {
1223 if (has_crcs) { 1224 if (has_crcs) {
1224 amagic += strcspn(amagic, " "); 1225 amagic += strcspn(amagic, " ");
1225 bmagic += strcspn(bmagic, " "); 1226 bmagic += strcspn(bmagic, " ");
1226 } 1227 }
1227 return strcmp(amagic, bmagic) == 0; 1228 return strcmp(amagic, bmagic) == 0;
1228 } 1229 }
1229 #else 1230 #else
1230 static inline int check_version(Elf_Shdr *sechdrs, 1231 static inline int check_version(Elf_Shdr *sechdrs,
1231 unsigned int versindex, 1232 unsigned int versindex,
1232 const char *symname, 1233 const char *symname,
1233 struct module *mod, 1234 struct module *mod,
1234 const unsigned long *crc, 1235 const unsigned long *crc,
1235 const struct module *crc_owner) 1236 const struct module *crc_owner)
1236 { 1237 {
1237 return 1; 1238 return 1;
1238 } 1239 }
1239 1240
1240 static inline int check_modstruct_version(Elf_Shdr *sechdrs, 1241 static inline int check_modstruct_version(Elf_Shdr *sechdrs,
1241 unsigned int versindex, 1242 unsigned int versindex,
1242 struct module *mod) 1243 struct module *mod)
1243 { 1244 {
1244 return 1; 1245 return 1;
1245 } 1246 }
1246 1247
1247 static inline int same_magic(const char *amagic, const char *bmagic, 1248 static inline int same_magic(const char *amagic, const char *bmagic,
1248 bool has_crcs) 1249 bool has_crcs)
1249 { 1250 {
1250 return strcmp(amagic, bmagic) == 0; 1251 return strcmp(amagic, bmagic) == 0;
1251 } 1252 }
1252 #endif /* CONFIG_MODVERSIONS */ 1253 #endif /* CONFIG_MODVERSIONS */
1253 1254
1254 /* Resolve a symbol for this module. I.e. if we find one, record usage. */ 1255 /* Resolve a symbol for this module. I.e. if we find one, record usage. */
1255 static const struct kernel_symbol *resolve_symbol(struct module *mod, 1256 static const struct kernel_symbol *resolve_symbol(struct module *mod,
1256 const struct load_info *info, 1257 const struct load_info *info,
1257 const char *name, 1258 const char *name,
1258 char ownername[]) 1259 char ownername[])
1259 { 1260 {
1260 struct module *owner; 1261 struct module *owner;
1261 const struct kernel_symbol *sym; 1262 const struct kernel_symbol *sym;
1262 const unsigned long *crc; 1263 const unsigned long *crc;
1263 int err; 1264 int err;
1264 1265
1265 mutex_lock(&module_mutex); 1266 mutex_lock(&module_mutex);
1266 sym = find_symbol(name, &owner, &crc, 1267 sym = find_symbol(name, &owner, &crc,
1267 !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true); 1268 !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true);
1268 if (!sym) 1269 if (!sym)
1269 goto unlock; 1270 goto unlock;
1270 1271
1271 if (!check_version(info->sechdrs, info->index.vers, name, mod, crc, 1272 if (!check_version(info->sechdrs, info->index.vers, name, mod, crc,
1272 owner)) { 1273 owner)) {
1273 sym = ERR_PTR(-EINVAL); 1274 sym = ERR_PTR(-EINVAL);
1274 goto getname; 1275 goto getname;
1275 } 1276 }
1276 1277
1277 err = ref_module(mod, owner); 1278 err = ref_module(mod, owner);
1278 if (err) { 1279 if (err) {
1279 sym = ERR_PTR(err); 1280 sym = ERR_PTR(err);
1280 goto getname; 1281 goto getname;
1281 } 1282 }
1282 1283
1283 getname: 1284 getname:
1284 /* We must make copy under the lock if we failed to get ref. */ 1285 /* We must make copy under the lock if we failed to get ref. */
1285 strncpy(ownername, module_name(owner), MODULE_NAME_LEN); 1286 strncpy(ownername, module_name(owner), MODULE_NAME_LEN);
1286 unlock: 1287 unlock:
1287 mutex_unlock(&module_mutex); 1288 mutex_unlock(&module_mutex);
1288 return sym; 1289 return sym;
1289 } 1290 }
1290 1291
1291 static const struct kernel_symbol * 1292 static const struct kernel_symbol *
1292 resolve_symbol_wait(struct module *mod, 1293 resolve_symbol_wait(struct module *mod,
1293 const struct load_info *info, 1294 const struct load_info *info,
1294 const char *name) 1295 const char *name)
1295 { 1296 {
1296 const struct kernel_symbol *ksym; 1297 const struct kernel_symbol *ksym;
1297 char owner[MODULE_NAME_LEN]; 1298 char owner[MODULE_NAME_LEN];
1298 1299
1299 if (wait_event_interruptible_timeout(module_wq, 1300 if (wait_event_interruptible_timeout(module_wq,
1300 !IS_ERR(ksym = resolve_symbol(mod, info, name, owner)) 1301 !IS_ERR(ksym = resolve_symbol(mod, info, name, owner))
1301 || PTR_ERR(ksym) != -EBUSY, 1302 || PTR_ERR(ksym) != -EBUSY,
1302 30 * HZ) <= 0) { 1303 30 * HZ) <= 0) {
1303 printk(KERN_WARNING "%s: gave up waiting for init of module %s.\n", 1304 printk(KERN_WARNING "%s: gave up waiting for init of module %s.\n",
1304 mod->name, owner); 1305 mod->name, owner);
1305 } 1306 }
1306 return ksym; 1307 return ksym;
1307 } 1308 }
1308 1309
1309 /* 1310 /*
1310 * /sys/module/foo/sections stuff 1311 * /sys/module/foo/sections stuff
1311 * J. Corbet <corbet@lwn.net> 1312 * J. Corbet <corbet@lwn.net>
1312 */ 1313 */
1313 #ifdef CONFIG_SYSFS 1314 #ifdef CONFIG_SYSFS
1314 1315
1315 #ifdef CONFIG_KALLSYMS 1316 #ifdef CONFIG_KALLSYMS
1316 static inline bool sect_empty(const Elf_Shdr *sect) 1317 static inline bool sect_empty(const Elf_Shdr *sect)
1317 { 1318 {
1318 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0; 1319 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
1319 } 1320 }
1320 1321
1321 struct module_sect_attr 1322 struct module_sect_attr
1322 { 1323 {
1323 struct module_attribute mattr; 1324 struct module_attribute mattr;
1324 char *name; 1325 char *name;
1325 unsigned long address; 1326 unsigned long address;
1326 }; 1327 };
1327 1328
1328 struct module_sect_attrs 1329 struct module_sect_attrs
1329 { 1330 {
1330 struct attribute_group grp; 1331 struct attribute_group grp;
1331 unsigned int nsections; 1332 unsigned int nsections;
1332 struct module_sect_attr attrs[0]; 1333 struct module_sect_attr attrs[0];
1333 }; 1334 };
1334 1335
1335 static ssize_t module_sect_show(struct module_attribute *mattr, 1336 static ssize_t module_sect_show(struct module_attribute *mattr,
1336 struct module_kobject *mk, char *buf) 1337 struct module_kobject *mk, char *buf)
1337 { 1338 {
1338 struct module_sect_attr *sattr = 1339 struct module_sect_attr *sattr =
1339 container_of(mattr, struct module_sect_attr, mattr); 1340 container_of(mattr, struct module_sect_attr, mattr);
1340 return sprintf(buf, "0x%pK\n", (void *)sattr->address); 1341 return sprintf(buf, "0x%pK\n", (void *)sattr->address);
1341 } 1342 }
1342 1343
1343 static void free_sect_attrs(struct module_sect_attrs *sect_attrs) 1344 static void free_sect_attrs(struct module_sect_attrs *sect_attrs)
1344 { 1345 {
1345 unsigned int section; 1346 unsigned int section;
1346 1347
1347 for (section = 0; section < sect_attrs->nsections; section++) 1348 for (section = 0; section < sect_attrs->nsections; section++)
1348 kfree(sect_attrs->attrs[section].name); 1349 kfree(sect_attrs->attrs[section].name);
1349 kfree(sect_attrs); 1350 kfree(sect_attrs);
1350 } 1351 }
1351 1352
1352 static void add_sect_attrs(struct module *mod, const struct load_info *info) 1353 static void add_sect_attrs(struct module *mod, const struct load_info *info)
1353 { 1354 {
1354 unsigned int nloaded = 0, i, size[2]; 1355 unsigned int nloaded = 0, i, size[2];
1355 struct module_sect_attrs *sect_attrs; 1356 struct module_sect_attrs *sect_attrs;
1356 struct module_sect_attr *sattr; 1357 struct module_sect_attr *sattr;
1357 struct attribute **gattr; 1358 struct attribute **gattr;
1358 1359
1359 /* Count loaded sections and allocate structures */ 1360 /* Count loaded sections and allocate structures */
1360 for (i = 0; i < info->hdr->e_shnum; i++) 1361 for (i = 0; i < info->hdr->e_shnum; i++)
1361 if (!sect_empty(&info->sechdrs[i])) 1362 if (!sect_empty(&info->sechdrs[i]))
1362 nloaded++; 1363 nloaded++;
1363 size[0] = ALIGN(sizeof(*sect_attrs) 1364 size[0] = ALIGN(sizeof(*sect_attrs)
1364 + nloaded * sizeof(sect_attrs->attrs[0]), 1365 + nloaded * sizeof(sect_attrs->attrs[0]),
1365 sizeof(sect_attrs->grp.attrs[0])); 1366 sizeof(sect_attrs->grp.attrs[0]));
1366 size[1] = (nloaded + 1) * sizeof(sect_attrs->grp.attrs[0]); 1367 size[1] = (nloaded + 1) * sizeof(sect_attrs->grp.attrs[0]);
1367 sect_attrs = kzalloc(size[0] + size[1], GFP_KERNEL); 1368 sect_attrs = kzalloc(size[0] + size[1], GFP_KERNEL);
1368 if (sect_attrs == NULL) 1369 if (sect_attrs == NULL)
1369 return; 1370 return;
1370 1371
1371 /* Setup section attributes. */ 1372 /* Setup section attributes. */
1372 sect_attrs->grp.name = "sections"; 1373 sect_attrs->grp.name = "sections";
1373 sect_attrs->grp.attrs = (void *)sect_attrs + size[0]; 1374 sect_attrs->grp.attrs = (void *)sect_attrs + size[0];
1374 1375
1375 sect_attrs->nsections = 0; 1376 sect_attrs->nsections = 0;
1376 sattr = &sect_attrs->attrs[0]; 1377 sattr = &sect_attrs->attrs[0];
1377 gattr = &sect_attrs->grp.attrs[0]; 1378 gattr = &sect_attrs->grp.attrs[0];
1378 for (i = 0; i < info->hdr->e_shnum; i++) { 1379 for (i = 0; i < info->hdr->e_shnum; i++) {
1379 Elf_Shdr *sec = &info->sechdrs[i]; 1380 Elf_Shdr *sec = &info->sechdrs[i];
1380 if (sect_empty(sec)) 1381 if (sect_empty(sec))
1381 continue; 1382 continue;
1382 sattr->address = sec->sh_addr; 1383 sattr->address = sec->sh_addr;
1383 sattr->name = kstrdup(info->secstrings + sec->sh_name, 1384 sattr->name = kstrdup(info->secstrings + sec->sh_name,
1384 GFP_KERNEL); 1385 GFP_KERNEL);
1385 if (sattr->name == NULL) 1386 if (sattr->name == NULL)
1386 goto out; 1387 goto out;
1387 sect_attrs->nsections++; 1388 sect_attrs->nsections++;
1388 sysfs_attr_init(&sattr->mattr.attr); 1389 sysfs_attr_init(&sattr->mattr.attr);
1389 sattr->mattr.show = module_sect_show; 1390 sattr->mattr.show = module_sect_show;
1390 sattr->mattr.store = NULL; 1391 sattr->mattr.store = NULL;
1391 sattr->mattr.attr.name = sattr->name; 1392 sattr->mattr.attr.name = sattr->name;
1392 sattr->mattr.attr.mode = S_IRUGO; 1393 sattr->mattr.attr.mode = S_IRUGO;
1393 *(gattr++) = &(sattr++)->mattr.attr; 1394 *(gattr++) = &(sattr++)->mattr.attr;
1394 } 1395 }
1395 *gattr = NULL; 1396 *gattr = NULL;
1396 1397
1397 if (sysfs_create_group(&mod->mkobj.kobj, &sect_attrs->grp)) 1398 if (sysfs_create_group(&mod->mkobj.kobj, &sect_attrs->grp))
1398 goto out; 1399 goto out;
1399 1400
1400 mod->sect_attrs = sect_attrs; 1401 mod->sect_attrs = sect_attrs;
1401 return; 1402 return;
1402 out: 1403 out:
1403 free_sect_attrs(sect_attrs); 1404 free_sect_attrs(sect_attrs);
1404 } 1405 }
1405 1406
1406 static void remove_sect_attrs(struct module *mod) 1407 static void remove_sect_attrs(struct module *mod)
1407 { 1408 {
1408 if (mod->sect_attrs) { 1409 if (mod->sect_attrs) {
1409 sysfs_remove_group(&mod->mkobj.kobj, 1410 sysfs_remove_group(&mod->mkobj.kobj,
1410 &mod->sect_attrs->grp); 1411 &mod->sect_attrs->grp);
1411 /* We are positive that no one is using any sect attrs 1412 /* We are positive that no one is using any sect attrs
1412 * at this point. Deallocate immediately. */ 1413 * at this point. Deallocate immediately. */
1413 free_sect_attrs(mod->sect_attrs); 1414 free_sect_attrs(mod->sect_attrs);
1414 mod->sect_attrs = NULL; 1415 mod->sect_attrs = NULL;
1415 } 1416 }
1416 } 1417 }
1417 1418
1418 /* 1419 /*
1419 * /sys/module/foo/notes/.section.name gives contents of SHT_NOTE sections. 1420 * /sys/module/foo/notes/.section.name gives contents of SHT_NOTE sections.
1420 */ 1421 */
1421 1422
1422 struct module_notes_attrs { 1423 struct module_notes_attrs {
1423 struct kobject *dir; 1424 struct kobject *dir;
1424 unsigned int notes; 1425 unsigned int notes;
1425 struct bin_attribute attrs[0]; 1426 struct bin_attribute attrs[0];
1426 }; 1427 };
1427 1428
1428 static ssize_t module_notes_read(struct file *filp, struct kobject *kobj, 1429 static ssize_t module_notes_read(struct file *filp, struct kobject *kobj,
1429 struct bin_attribute *bin_attr, 1430 struct bin_attribute *bin_attr,
1430 char *buf, loff_t pos, size_t count) 1431 char *buf, loff_t pos, size_t count)
1431 { 1432 {
1432 /* 1433 /*
1433 * The caller checked the pos and count against our size. 1434 * The caller checked the pos and count against our size.
1434 */ 1435 */
1435 memcpy(buf, bin_attr->private + pos, count); 1436 memcpy(buf, bin_attr->private + pos, count);
1436 return count; 1437 return count;
1437 } 1438 }
1438 1439
1439 static void free_notes_attrs(struct module_notes_attrs *notes_attrs, 1440 static void free_notes_attrs(struct module_notes_attrs *notes_attrs,
1440 unsigned int i) 1441 unsigned int i)
1441 { 1442 {
1442 if (notes_attrs->dir) { 1443 if (notes_attrs->dir) {
1443 while (i-- > 0) 1444 while (i-- > 0)
1444 sysfs_remove_bin_file(notes_attrs->dir, 1445 sysfs_remove_bin_file(notes_attrs->dir,
1445 &notes_attrs->attrs[i]); 1446 &notes_attrs->attrs[i]);
1446 kobject_put(notes_attrs->dir); 1447 kobject_put(notes_attrs->dir);
1447 } 1448 }
1448 kfree(notes_attrs); 1449 kfree(notes_attrs);
1449 } 1450 }
1450 1451
1451 static void add_notes_attrs(struct module *mod, const struct load_info *info) 1452 static void add_notes_attrs(struct module *mod, const struct load_info *info)
1452 { 1453 {
1453 unsigned int notes, loaded, i; 1454 unsigned int notes, loaded, i;
1454 struct module_notes_attrs *notes_attrs; 1455 struct module_notes_attrs *notes_attrs;
1455 struct bin_attribute *nattr; 1456 struct bin_attribute *nattr;
1456 1457
1457 /* failed to create section attributes, so can't create notes */ 1458 /* failed to create section attributes, so can't create notes */
1458 if (!mod->sect_attrs) 1459 if (!mod->sect_attrs)
1459 return; 1460 return;
1460 1461
1461 /* Count notes sections and allocate structures. */ 1462 /* Count notes sections and allocate structures. */
1462 notes = 0; 1463 notes = 0;
1463 for (i = 0; i < info->hdr->e_shnum; i++) 1464 for (i = 0; i < info->hdr->e_shnum; i++)
1464 if (!sect_empty(&info->sechdrs[i]) && 1465 if (!sect_empty(&info->sechdrs[i]) &&
1465 (info->sechdrs[i].sh_type == SHT_NOTE)) 1466 (info->sechdrs[i].sh_type == SHT_NOTE))
1466 ++notes; 1467 ++notes;
1467 1468
1468 if (notes == 0) 1469 if (notes == 0)
1469 return; 1470 return;
1470 1471
1471 notes_attrs = kzalloc(sizeof(*notes_attrs) 1472 notes_attrs = kzalloc(sizeof(*notes_attrs)
1472 + notes * sizeof(notes_attrs->attrs[0]), 1473 + notes * sizeof(notes_attrs->attrs[0]),
1473 GFP_KERNEL); 1474 GFP_KERNEL);
1474 if (notes_attrs == NULL) 1475 if (notes_attrs == NULL)
1475 return; 1476 return;
1476 1477
1477 notes_attrs->notes = notes; 1478 notes_attrs->notes = notes;
1478 nattr = &notes_attrs->attrs[0]; 1479 nattr = &notes_attrs->attrs[0];
1479 for (loaded = i = 0; i < info->hdr->e_shnum; ++i) { 1480 for (loaded = i = 0; i < info->hdr->e_shnum; ++i) {
1480 if (sect_empty(&info->sechdrs[i])) 1481 if (sect_empty(&info->sechdrs[i]))
1481 continue; 1482 continue;
1482 if (info->sechdrs[i].sh_type == SHT_NOTE) { 1483 if (info->sechdrs[i].sh_type == SHT_NOTE) {
1483 sysfs_bin_attr_init(nattr); 1484 sysfs_bin_attr_init(nattr);
1484 nattr->attr.name = mod->sect_attrs->attrs[loaded].name; 1485 nattr->attr.name = mod->sect_attrs->attrs[loaded].name;
1485 nattr->attr.mode = S_IRUGO; 1486 nattr->attr.mode = S_IRUGO;
1486 nattr->size = info->sechdrs[i].sh_size; 1487 nattr->size = info->sechdrs[i].sh_size;
1487 nattr->private = (void *) info->sechdrs[i].sh_addr; 1488 nattr->private = (void *) info->sechdrs[i].sh_addr;
1488 nattr->read = module_notes_read; 1489 nattr->read = module_notes_read;
1489 ++nattr; 1490 ++nattr;
1490 } 1491 }
1491 ++loaded; 1492 ++loaded;
1492 } 1493 }
1493 1494
1494 notes_attrs->dir = kobject_create_and_add("notes", &mod->mkobj.kobj); 1495 notes_attrs->dir = kobject_create_and_add("notes", &mod->mkobj.kobj);
1495 if (!notes_attrs->dir) 1496 if (!notes_attrs->dir)
1496 goto out; 1497 goto out;
1497 1498
1498 for (i = 0; i < notes; ++i) 1499 for (i = 0; i < notes; ++i)
1499 if (sysfs_create_bin_file(notes_attrs->dir, 1500 if (sysfs_create_bin_file(notes_attrs->dir,
1500 &notes_attrs->attrs[i])) 1501 &notes_attrs->attrs[i]))
1501 goto out; 1502 goto out;
1502 1503
1503 mod->notes_attrs = notes_attrs; 1504 mod->notes_attrs = notes_attrs;
1504 return; 1505 return;
1505 1506
1506 out: 1507 out:
1507 free_notes_attrs(notes_attrs, i); 1508 free_notes_attrs(notes_attrs, i);
1508 } 1509 }
1509 1510
1510 static void remove_notes_attrs(struct module *mod) 1511 static void remove_notes_attrs(struct module *mod)
1511 { 1512 {
1512 if (mod->notes_attrs) 1513 if (mod->notes_attrs)
1513 free_notes_attrs(mod->notes_attrs, mod->notes_attrs->notes); 1514 free_notes_attrs(mod->notes_attrs, mod->notes_attrs->notes);
1514 } 1515 }
1515 1516
1516 #else 1517 #else
1517 1518
1518 static inline void add_sect_attrs(struct module *mod, 1519 static inline void add_sect_attrs(struct module *mod,
1519 const struct load_info *info) 1520 const struct load_info *info)
1520 { 1521 {
1521 } 1522 }
1522 1523
1523 static inline void remove_sect_attrs(struct module *mod) 1524 static inline void remove_sect_attrs(struct module *mod)
1524 { 1525 {
1525 } 1526 }
1526 1527
1527 static inline void add_notes_attrs(struct module *mod, 1528 static inline void add_notes_attrs(struct module *mod,
1528 const struct load_info *info) 1529 const struct load_info *info)
1529 { 1530 {
1530 } 1531 }
1531 1532
1532 static inline void remove_notes_attrs(struct module *mod) 1533 static inline void remove_notes_attrs(struct module *mod)
1533 { 1534 {
1534 } 1535 }
1535 #endif /* CONFIG_KALLSYMS */ 1536 #endif /* CONFIG_KALLSYMS */
1536 1537
1537 static void add_usage_links(struct module *mod) 1538 static void add_usage_links(struct module *mod)
1538 { 1539 {
1539 #ifdef CONFIG_MODULE_UNLOAD 1540 #ifdef CONFIG_MODULE_UNLOAD
1540 struct module_use *use; 1541 struct module_use *use;
1541 int nowarn; 1542 int nowarn;
1542 1543
1543 mutex_lock(&module_mutex); 1544 mutex_lock(&module_mutex);
1544 list_for_each_entry(use, &mod->target_list, target_list) { 1545 list_for_each_entry(use, &mod->target_list, target_list) {
1545 nowarn = sysfs_create_link(use->target->holders_dir, 1546 nowarn = sysfs_create_link(use->target->holders_dir,
1546 &mod->mkobj.kobj, mod->name); 1547 &mod->mkobj.kobj, mod->name);
1547 } 1548 }
1548 mutex_unlock(&module_mutex); 1549 mutex_unlock(&module_mutex);
1549 #endif 1550 #endif
1550 } 1551 }
1551 1552
1552 static void del_usage_links(struct module *mod) 1553 static void del_usage_links(struct module *mod)
1553 { 1554 {
1554 #ifdef CONFIG_MODULE_UNLOAD 1555 #ifdef CONFIG_MODULE_UNLOAD
1555 struct module_use *use; 1556 struct module_use *use;
1556 1557
1557 mutex_lock(&module_mutex); 1558 mutex_lock(&module_mutex);
1558 list_for_each_entry(use, &mod->target_list, target_list) 1559 list_for_each_entry(use, &mod->target_list, target_list)
1559 sysfs_remove_link(use->target->holders_dir, mod->name); 1560 sysfs_remove_link(use->target->holders_dir, mod->name);
1560 mutex_unlock(&module_mutex); 1561 mutex_unlock(&module_mutex);
1561 #endif 1562 #endif
1562 } 1563 }
1563 1564
1564 static int module_add_modinfo_attrs(struct module *mod) 1565 static int module_add_modinfo_attrs(struct module *mod)
1565 { 1566 {
1566 struct module_attribute *attr; 1567 struct module_attribute *attr;
1567 struct module_attribute *temp_attr; 1568 struct module_attribute *temp_attr;
1568 int error = 0; 1569 int error = 0;
1569 int i; 1570 int i;
1570 1571
1571 mod->modinfo_attrs = kzalloc((sizeof(struct module_attribute) * 1572 mod->modinfo_attrs = kzalloc((sizeof(struct module_attribute) *
1572 (ARRAY_SIZE(modinfo_attrs) + 1)), 1573 (ARRAY_SIZE(modinfo_attrs) + 1)),
1573 GFP_KERNEL); 1574 GFP_KERNEL);
1574 if (!mod->modinfo_attrs) 1575 if (!mod->modinfo_attrs)
1575 return -ENOMEM; 1576 return -ENOMEM;
1576 1577
1577 temp_attr = mod->modinfo_attrs; 1578 temp_attr = mod->modinfo_attrs;
1578 for (i = 0; (attr = modinfo_attrs[i]) && !error; i++) { 1579 for (i = 0; (attr = modinfo_attrs[i]) && !error; i++) {
1579 if (!attr->test || 1580 if (!attr->test ||
1580 (attr->test && attr->test(mod))) { 1581 (attr->test && attr->test(mod))) {
1581 memcpy(temp_attr, attr, sizeof(*temp_attr)); 1582 memcpy(temp_attr, attr, sizeof(*temp_attr));
1582 sysfs_attr_init(&temp_attr->attr); 1583 sysfs_attr_init(&temp_attr->attr);
1583 error = sysfs_create_file(&mod->mkobj.kobj,&temp_attr->attr); 1584 error = sysfs_create_file(&mod->mkobj.kobj,&temp_attr->attr);
1584 ++temp_attr; 1585 ++temp_attr;
1585 } 1586 }
1586 } 1587 }
1587 return error; 1588 return error;
1588 } 1589 }
1589 1590
1590 static void module_remove_modinfo_attrs(struct module *mod) 1591 static void module_remove_modinfo_attrs(struct module *mod)
1591 { 1592 {
1592 struct module_attribute *attr; 1593 struct module_attribute *attr;
1593 int i; 1594 int i;
1594 1595
1595 for (i = 0; (attr = &mod->modinfo_attrs[i]); i++) { 1596 for (i = 0; (attr = &mod->modinfo_attrs[i]); i++) {
1596 /* pick a field to test for end of list */ 1597 /* pick a field to test for end of list */
1597 if (!attr->attr.name) 1598 if (!attr->attr.name)
1598 break; 1599 break;
1599 sysfs_remove_file(&mod->mkobj.kobj,&attr->attr); 1600 sysfs_remove_file(&mod->mkobj.kobj,&attr->attr);
1600 if (attr->free) 1601 if (attr->free)
1601 attr->free(mod); 1602 attr->free(mod);
1602 } 1603 }
1603 kfree(mod->modinfo_attrs); 1604 kfree(mod->modinfo_attrs);
1604 } 1605 }
1605 1606
1606 static int mod_sysfs_init(struct module *mod) 1607 static int mod_sysfs_init(struct module *mod)
1607 { 1608 {
1608 int err; 1609 int err;
1609 struct kobject *kobj; 1610 struct kobject *kobj;
1610 1611
1611 if (!module_sysfs_initialized) { 1612 if (!module_sysfs_initialized) {
1612 printk(KERN_ERR "%s: module sysfs not initialized\n", 1613 printk(KERN_ERR "%s: module sysfs not initialized\n",
1613 mod->name); 1614 mod->name);
1614 err = -EINVAL; 1615 err = -EINVAL;
1615 goto out; 1616 goto out;
1616 } 1617 }
1617 1618
1618 kobj = kset_find_obj(module_kset, mod->name); 1619 kobj = kset_find_obj(module_kset, mod->name);
1619 if (kobj) { 1620 if (kobj) {
1620 printk(KERN_ERR "%s: module is already loaded\n", mod->name); 1621 printk(KERN_ERR "%s: module is already loaded\n", mod->name);
1621 kobject_put(kobj); 1622 kobject_put(kobj);
1622 err = -EINVAL; 1623 err = -EINVAL;
1623 goto out; 1624 goto out;
1624 } 1625 }
1625 1626
1626 mod->mkobj.mod = mod; 1627 mod->mkobj.mod = mod;
1627 1628
1628 memset(&mod->mkobj.kobj, 0, sizeof(mod->mkobj.kobj)); 1629 memset(&mod->mkobj.kobj, 0, sizeof(mod->mkobj.kobj));
1629 mod->mkobj.kobj.kset = module_kset; 1630 mod->mkobj.kobj.kset = module_kset;
1630 err = kobject_init_and_add(&mod->mkobj.kobj, &module_ktype, NULL, 1631 err = kobject_init_and_add(&mod->mkobj.kobj, &module_ktype, NULL,
1631 "%s", mod->name); 1632 "%s", mod->name);
1632 if (err) 1633 if (err)
1633 kobject_put(&mod->mkobj.kobj); 1634 kobject_put(&mod->mkobj.kobj);
1634 1635
1635 /* delay uevent until full sysfs population */ 1636 /* delay uevent until full sysfs population */
1636 out: 1637 out:
1637 return err; 1638 return err;
1638 } 1639 }
1639 1640
1640 static int mod_sysfs_setup(struct module *mod, 1641 static int mod_sysfs_setup(struct module *mod,
1641 const struct load_info *info, 1642 const struct load_info *info,
1642 struct kernel_param *kparam, 1643 struct kernel_param *kparam,
1643 unsigned int num_params) 1644 unsigned int num_params)
1644 { 1645 {
1645 int err; 1646 int err;
1646 1647
1647 err = mod_sysfs_init(mod); 1648 err = mod_sysfs_init(mod);
1648 if (err) 1649 if (err)
1649 goto out; 1650 goto out;
1650 1651
1651 mod->holders_dir = kobject_create_and_add("holders", &mod->mkobj.kobj); 1652 mod->holders_dir = kobject_create_and_add("holders", &mod->mkobj.kobj);
1652 if (!mod->holders_dir) { 1653 if (!mod->holders_dir) {
1653 err = -ENOMEM; 1654 err = -ENOMEM;
1654 goto out_unreg; 1655 goto out_unreg;
1655 } 1656 }
1656 1657
1657 err = module_param_sysfs_setup(mod, kparam, num_params); 1658 err = module_param_sysfs_setup(mod, kparam, num_params);
1658 if (err) 1659 if (err)
1659 goto out_unreg_holders; 1660 goto out_unreg_holders;
1660 1661
1661 err = module_add_modinfo_attrs(mod); 1662 err = module_add_modinfo_attrs(mod);
1662 if (err) 1663 if (err)
1663 goto out_unreg_param; 1664 goto out_unreg_param;
1664 1665
1665 add_usage_links(mod); 1666 add_usage_links(mod);
1666 add_sect_attrs(mod, info); 1667 add_sect_attrs(mod, info);
1667 add_notes_attrs(mod, info); 1668 add_notes_attrs(mod, info);
1668 1669
1669 kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD); 1670 kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD);
1670 return 0; 1671 return 0;
1671 1672
1672 out_unreg_param: 1673 out_unreg_param:
1673 module_param_sysfs_remove(mod); 1674 module_param_sysfs_remove(mod);
1674 out_unreg_holders: 1675 out_unreg_holders:
1675 kobject_put(mod->holders_dir); 1676 kobject_put(mod->holders_dir);
1676 out_unreg: 1677 out_unreg:
1677 kobject_put(&mod->mkobj.kobj); 1678 kobject_put(&mod->mkobj.kobj);
1678 out: 1679 out:
1679 return err; 1680 return err;
1680 } 1681 }
1681 1682
1682 static void mod_sysfs_fini(struct module *mod) 1683 static void mod_sysfs_fini(struct module *mod)
1683 { 1684 {
1684 remove_notes_attrs(mod); 1685 remove_notes_attrs(mod);
1685 remove_sect_attrs(mod); 1686 remove_sect_attrs(mod);
1686 kobject_put(&mod->mkobj.kobj); 1687 kobject_put(&mod->mkobj.kobj);
1687 } 1688 }
1688 1689
1689 #else /* !CONFIG_SYSFS */ 1690 #else /* !CONFIG_SYSFS */
1690 1691
1691 static int mod_sysfs_setup(struct module *mod, 1692 static int mod_sysfs_setup(struct module *mod,
1692 const struct load_info *info, 1693 const struct load_info *info,
1693 struct kernel_param *kparam, 1694 struct kernel_param *kparam,
1694 unsigned int num_params) 1695 unsigned int num_params)
1695 { 1696 {
1696 return 0; 1697 return 0;
1697 } 1698 }
1698 1699
1699 static void mod_sysfs_fini(struct module *mod) 1700 static void mod_sysfs_fini(struct module *mod)
1700 { 1701 {
1701 } 1702 }
1702 1703
1703 static void module_remove_modinfo_attrs(struct module *mod) 1704 static void module_remove_modinfo_attrs(struct module *mod)
1704 { 1705 {
1705 } 1706 }
1706 1707
1707 static void del_usage_links(struct module *mod) 1708 static void del_usage_links(struct module *mod)
1708 { 1709 {
1709 } 1710 }
1710 1711
1711 #endif /* CONFIG_SYSFS */ 1712 #endif /* CONFIG_SYSFS */
1712 1713
1713 static void mod_sysfs_teardown(struct module *mod) 1714 static void mod_sysfs_teardown(struct module *mod)
1714 { 1715 {
1715 del_usage_links(mod); 1716 del_usage_links(mod);
1716 module_remove_modinfo_attrs(mod); 1717 module_remove_modinfo_attrs(mod);
1717 module_param_sysfs_remove(mod); 1718 module_param_sysfs_remove(mod);
1718 kobject_put(mod->mkobj.drivers_dir); 1719 kobject_put(mod->mkobj.drivers_dir);
1719 kobject_put(mod->holders_dir); 1720 kobject_put(mod->holders_dir);
1720 mod_sysfs_fini(mod); 1721 mod_sysfs_fini(mod);
1721 } 1722 }
1722 1723
1723 /* 1724 /*
1724 * unlink the module with the whole machine is stopped with interrupts off 1725 * unlink the module with the whole machine is stopped with interrupts off
1725 * - this defends against kallsyms not taking locks 1726 * - this defends against kallsyms not taking locks
1726 */ 1727 */
1727 static int __unlink_module(void *_mod) 1728 static int __unlink_module(void *_mod)
1728 { 1729 {
1729 struct module *mod = _mod; 1730 struct module *mod = _mod;
1730 list_del(&mod->list); 1731 list_del(&mod->list);
1731 module_bug_cleanup(mod); 1732 module_bug_cleanup(mod);
1732 return 0; 1733 return 0;
1733 } 1734 }
1734 1735
1735 #ifdef CONFIG_DEBUG_SET_MODULE_RONX 1736 #ifdef CONFIG_DEBUG_SET_MODULE_RONX
1736 /* 1737 /*
1737 * LKM RO/NX protection: protect module's text/ro-data 1738 * LKM RO/NX protection: protect module's text/ro-data
1738 * from modification and any data from execution. 1739 * from modification and any data from execution.
1739 */ 1740 */
1740 void set_page_attributes(void *start, void *end, int (*set)(unsigned long start, int num_pages)) 1741 void set_page_attributes(void *start, void *end, int (*set)(unsigned long start, int num_pages))
1741 { 1742 {
1742 unsigned long begin_pfn = PFN_DOWN((unsigned long)start); 1743 unsigned long begin_pfn = PFN_DOWN((unsigned long)start);
1743 unsigned long end_pfn = PFN_DOWN((unsigned long)end); 1744 unsigned long end_pfn = PFN_DOWN((unsigned long)end);
1744 1745
1745 if (end_pfn > begin_pfn) 1746 if (end_pfn > begin_pfn)
1746 set(begin_pfn << PAGE_SHIFT, end_pfn - begin_pfn); 1747 set(begin_pfn << PAGE_SHIFT, end_pfn - begin_pfn);
1747 } 1748 }
1748 1749
1749 static void set_section_ro_nx(void *base, 1750 static void set_section_ro_nx(void *base,
1750 unsigned long text_size, 1751 unsigned long text_size,
1751 unsigned long ro_size, 1752 unsigned long ro_size,
1752 unsigned long total_size) 1753 unsigned long total_size)
1753 { 1754 {
1754 /* begin and end PFNs of the current subsection */ 1755 /* begin and end PFNs of the current subsection */
1755 unsigned long begin_pfn; 1756 unsigned long begin_pfn;
1756 unsigned long end_pfn; 1757 unsigned long end_pfn;
1757 1758
1758 /* 1759 /*
1759 * Set RO for module text and RO-data: 1760 * Set RO for module text and RO-data:
1760 * - Always protect first page. 1761 * - Always protect first page.
1761 * - Do not protect last partial page. 1762 * - Do not protect last partial page.
1762 */ 1763 */
1763 if (ro_size > 0) 1764 if (ro_size > 0)
1764 set_page_attributes(base, base + ro_size, set_memory_ro); 1765 set_page_attributes(base, base + ro_size, set_memory_ro);
1765 1766
1766 /* 1767 /*
1767 * Set NX permissions for module data: 1768 * Set NX permissions for module data:
1768 * - Do not protect first partial page. 1769 * - Do not protect first partial page.
1769 * - Always protect last page. 1770 * - Always protect last page.
1770 */ 1771 */
1771 if (total_size > text_size) { 1772 if (total_size > text_size) {
1772 begin_pfn = PFN_UP((unsigned long)base + text_size); 1773 begin_pfn = PFN_UP((unsigned long)base + text_size);
1773 end_pfn = PFN_UP((unsigned long)base + total_size); 1774 end_pfn = PFN_UP((unsigned long)base + total_size);
1774 if (end_pfn > begin_pfn) 1775 if (end_pfn > begin_pfn)
1775 set_memory_nx(begin_pfn << PAGE_SHIFT, end_pfn - begin_pfn); 1776 set_memory_nx(begin_pfn << PAGE_SHIFT, end_pfn - begin_pfn);
1776 } 1777 }
1777 } 1778 }
1778 1779
1779 static void unset_module_core_ro_nx(struct module *mod) 1780 static void unset_module_core_ro_nx(struct module *mod)
1780 { 1781 {
1781 set_page_attributes(mod->module_core + mod->core_text_size, 1782 set_page_attributes(mod->module_core + mod->core_text_size,
1782 mod->module_core + mod->core_size, 1783 mod->module_core + mod->core_size,
1783 set_memory_x); 1784 set_memory_x);
1784 set_page_attributes(mod->module_core, 1785 set_page_attributes(mod->module_core,
1785 mod->module_core + mod->core_ro_size, 1786 mod->module_core + mod->core_ro_size,
1786 set_memory_rw); 1787 set_memory_rw);
1787 } 1788 }
1788 1789
1789 static void unset_module_init_ro_nx(struct module *mod) 1790 static void unset_module_init_ro_nx(struct module *mod)
1790 { 1791 {
1791 set_page_attributes(mod->module_init + mod->init_text_size, 1792 set_page_attributes(mod->module_init + mod->init_text_size,
1792 mod->module_init + mod->init_size, 1793 mod->module_init + mod->init_size,
1793 set_memory_x); 1794 set_memory_x);
1794 set_page_attributes(mod->module_init, 1795 set_page_attributes(mod->module_init,
1795 mod->module_init + mod->init_ro_size, 1796 mod->module_init + mod->init_ro_size,
1796 set_memory_rw); 1797 set_memory_rw);
1797 } 1798 }
1798 1799
1799 /* Iterate through all modules and set each module's text as RW */ 1800 /* Iterate through all modules and set each module's text as RW */
1800 void set_all_modules_text_rw(void) 1801 void set_all_modules_text_rw(void)
1801 { 1802 {
1802 struct module *mod; 1803 struct module *mod;
1803 1804
1804 mutex_lock(&module_mutex); 1805 mutex_lock(&module_mutex);
1805 list_for_each_entry_rcu(mod, &modules, list) { 1806 list_for_each_entry_rcu(mod, &modules, list) {
1806 if (mod->state == MODULE_STATE_UNFORMED) 1807 if (mod->state == MODULE_STATE_UNFORMED)
1807 continue; 1808 continue;
1808 if ((mod->module_core) && (mod->core_text_size)) { 1809 if ((mod->module_core) && (mod->core_text_size)) {
1809 set_page_attributes(mod->module_core, 1810 set_page_attributes(mod->module_core,
1810 mod->module_core + mod->core_text_size, 1811 mod->module_core + mod->core_text_size,
1811 set_memory_rw); 1812 set_memory_rw);
1812 } 1813 }
1813 if ((mod->module_init) && (mod->init_text_size)) { 1814 if ((mod->module_init) && (mod->init_text_size)) {
1814 set_page_attributes(mod->module_init, 1815 set_page_attributes(mod->module_init,
1815 mod->module_init + mod->init_text_size, 1816 mod->module_init + mod->init_text_size,
1816 set_memory_rw); 1817 set_memory_rw);
1817 } 1818 }
1818 } 1819 }
1819 mutex_unlock(&module_mutex); 1820 mutex_unlock(&module_mutex);
1820 } 1821 }
1821 1822
1822 /* Iterate through all modules and set each module's text as RO */ 1823 /* Iterate through all modules and set each module's text as RO */
1823 void set_all_modules_text_ro(void) 1824 void set_all_modules_text_ro(void)
1824 { 1825 {
1825 struct module *mod; 1826 struct module *mod;
1826 1827
1827 mutex_lock(&module_mutex); 1828 mutex_lock(&module_mutex);
1828 list_for_each_entry_rcu(mod, &modules, list) { 1829 list_for_each_entry_rcu(mod, &modules, list) {
1829 if (mod->state == MODULE_STATE_UNFORMED) 1830 if (mod->state == MODULE_STATE_UNFORMED)
1830 continue; 1831 continue;
1831 if ((mod->module_core) && (mod->core_text_size)) { 1832 if ((mod->module_core) && (mod->core_text_size)) {
1832 set_page_attributes(mod->module_core, 1833 set_page_attributes(mod->module_core,
1833 mod->module_core + mod->core_text_size, 1834 mod->module_core + mod->core_text_size,
1834 set_memory_ro); 1835 set_memory_ro);
1835 } 1836 }
1836 if ((mod->module_init) && (mod->init_text_size)) { 1837 if ((mod->module_init) && (mod->init_text_size)) {
1837 set_page_attributes(mod->module_init, 1838 set_page_attributes(mod->module_init,
1838 mod->module_init + mod->init_text_size, 1839 mod->module_init + mod->init_text_size,
1839 set_memory_ro); 1840 set_memory_ro);
1840 } 1841 }
1841 } 1842 }
1842 mutex_unlock(&module_mutex); 1843 mutex_unlock(&module_mutex);
1843 } 1844 }
1844 #else 1845 #else
1845 static inline void set_section_ro_nx(void *base, unsigned long text_size, unsigned long ro_size, unsigned long total_size) { } 1846 static inline void set_section_ro_nx(void *base, unsigned long text_size, unsigned long ro_size, unsigned long total_size) { }
1846 static void unset_module_core_ro_nx(struct module *mod) { } 1847 static void unset_module_core_ro_nx(struct module *mod) { }
1847 static void unset_module_init_ro_nx(struct module *mod) { } 1848 static void unset_module_init_ro_nx(struct module *mod) { }
1848 #endif 1849 #endif
1849 1850
1850 void __weak module_free(struct module *mod, void *module_region) 1851 void __weak module_free(struct module *mod, void *module_region)
1851 { 1852 {
1852 vfree(module_region); 1853 vfree(module_region);
1853 } 1854 }
1854 1855
1855 void __weak module_arch_cleanup(struct module *mod) 1856 void __weak module_arch_cleanup(struct module *mod)
1856 { 1857 {
1857 } 1858 }
1858 1859
1859 /* Free a module, remove from lists, etc. */ 1860 /* Free a module, remove from lists, etc. */
1860 static void free_module(struct module *mod) 1861 static void free_module(struct module *mod)
1861 { 1862 {
1862 trace_module_free(mod); 1863 trace_module_free(mod);
1863 1864
1864 /* Delete from various lists */
1865 mutex_lock(&module_mutex);
1866 stop_machine(__unlink_module, mod, NULL);
1867 mutex_unlock(&module_mutex);
1868 mod_sysfs_teardown(mod); 1865 mod_sysfs_teardown(mod);
1869 1866
1867 /* We leave it in list to prevent duplicate loads, but make sure
1868 * that noone uses it while it's being deconstructed. */
1869 mod->state = MODULE_STATE_UNFORMED;
1870
1870 /* Remove dynamic debug info */ 1871 /* Remove dynamic debug info */
1871 ddebug_remove_module(mod->name); 1872 ddebug_remove_module(mod->name);
1872 1873
1873 /* Arch-specific cleanup. */ 1874 /* Arch-specific cleanup. */
1874 module_arch_cleanup(mod); 1875 module_arch_cleanup(mod);
1875 1876
1876 /* Module unload stuff */ 1877 /* Module unload stuff */
1877 module_unload_free(mod); 1878 module_unload_free(mod);
1878 1879
1879 /* Free any allocated parameters. */ 1880 /* Free any allocated parameters. */
1880 destroy_params(mod->kp, mod->num_kp); 1881 destroy_params(mod->kp, mod->num_kp);
1882
1883 /* Now we can delete it from the lists */
1884 mutex_lock(&module_mutex);
1885 stop_machine(__unlink_module, mod, NULL);
1886 mutex_unlock(&module_mutex);
1881 1887
1882 /* This may be NULL, but that's OK */ 1888 /* This may be NULL, but that's OK */
1883 unset_module_init_ro_nx(mod); 1889 unset_module_init_ro_nx(mod);
1884 module_free(mod, mod->module_init); 1890 module_free(mod, mod->module_init);
1885 kfree(mod->args); 1891 kfree(mod->args);
1886 percpu_modfree(mod); 1892 percpu_modfree(mod);
1887 1893
1888 /* Free lock-classes: */ 1894 /* Free lock-classes: */
1889 lockdep_free_key_range(mod->module_core, mod->core_size); 1895 lockdep_free_key_range(mod->module_core, mod->core_size);
1890 1896
1891 /* Finally, free the core (containing the module structure) */ 1897 /* Finally, free the core (containing the module structure) */
1892 unset_module_core_ro_nx(mod); 1898 unset_module_core_ro_nx(mod);
1893 module_free(mod, mod->module_core); 1899 module_free(mod, mod->module_core);
1894 1900
1895 #ifdef CONFIG_MPU 1901 #ifdef CONFIG_MPU
1896 update_protections(current->mm); 1902 update_protections(current->mm);
1897 #endif 1903 #endif
1898 } 1904 }
1899 1905
1900 void *__symbol_get(const char *symbol) 1906 void *__symbol_get(const char *symbol)
1901 { 1907 {
1902 struct module *owner; 1908 struct module *owner;
1903 const struct kernel_symbol *sym; 1909 const struct kernel_symbol *sym;
1904 1910
1905 preempt_disable(); 1911 preempt_disable();
1906 sym = find_symbol(symbol, &owner, NULL, true, true); 1912 sym = find_symbol(symbol, &owner, NULL, true, true);
1907 if (sym && strong_try_module_get(owner)) 1913 if (sym && strong_try_module_get(owner))
1908 sym = NULL; 1914 sym = NULL;
1909 preempt_enable(); 1915 preempt_enable();
1910 1916
1911 return sym ? (void *)sym->value : NULL; 1917 return sym ? (void *)sym->value : NULL;
1912 } 1918 }
1913 EXPORT_SYMBOL_GPL(__symbol_get); 1919 EXPORT_SYMBOL_GPL(__symbol_get);
1914 1920
1915 /* 1921 /*
1916 * Ensure that an exported symbol [global namespace] does not already exist 1922 * Ensure that an exported symbol [global namespace] does not already exist
1917 * in the kernel or in some other module's exported symbol table. 1923 * in the kernel or in some other module's exported symbol table.
1918 * 1924 *
1919 * You must hold the module_mutex. 1925 * You must hold the module_mutex.
1920 */ 1926 */
1921 static int verify_export_symbols(struct module *mod) 1927 static int verify_export_symbols(struct module *mod)
1922 { 1928 {
1923 unsigned int i; 1929 unsigned int i;
1924 struct module *owner; 1930 struct module *owner;
1925 const struct kernel_symbol *s; 1931 const struct kernel_symbol *s;
1926 struct { 1932 struct {
1927 const struct kernel_symbol *sym; 1933 const struct kernel_symbol *sym;
1928 unsigned int num; 1934 unsigned int num;
1929 } arr[] = { 1935 } arr[] = {
1930 { mod->syms, mod->num_syms }, 1936 { mod->syms, mod->num_syms },
1931 { mod->gpl_syms, mod->num_gpl_syms }, 1937 { mod->gpl_syms, mod->num_gpl_syms },
1932 { mod->gpl_future_syms, mod->num_gpl_future_syms }, 1938 { mod->gpl_future_syms, mod->num_gpl_future_syms },
1933 #ifdef CONFIG_UNUSED_SYMBOLS 1939 #ifdef CONFIG_UNUSED_SYMBOLS
1934 { mod->unused_syms, mod->num_unused_syms }, 1940 { mod->unused_syms, mod->num_unused_syms },
1935 { mod->unused_gpl_syms, mod->num_unused_gpl_syms }, 1941 { mod->unused_gpl_syms, mod->num_unused_gpl_syms },
1936 #endif 1942 #endif
1937 }; 1943 };
1938 1944
1939 for (i = 0; i < ARRAY_SIZE(arr); i++) { 1945 for (i = 0; i < ARRAY_SIZE(arr); i++) {
1940 for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) { 1946 for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) {
1941 if (find_symbol(s->name, &owner, NULL, true, false)) { 1947 if (find_symbol(s->name, &owner, NULL, true, false)) {
1942 printk(KERN_ERR 1948 printk(KERN_ERR
1943 "%s: exports duplicate symbol %s" 1949 "%s: exports duplicate symbol %s"
1944 " (owned by %s)\n", 1950 " (owned by %s)\n",
1945 mod->name, s->name, module_name(owner)); 1951 mod->name, s->name, module_name(owner));
1946 return -ENOEXEC; 1952 return -ENOEXEC;
1947 } 1953 }
1948 } 1954 }
1949 } 1955 }
1950 return 0; 1956 return 0;
1951 } 1957 }
1952 1958
1953 /* Change all symbols so that st_value encodes the pointer directly. */ 1959 /* Change all symbols so that st_value encodes the pointer directly. */
1954 static int simplify_symbols(struct module *mod, const struct load_info *info) 1960 static int simplify_symbols(struct module *mod, const struct load_info *info)
1955 { 1961 {
1956 Elf_Shdr *symsec = &info->sechdrs[info->index.sym]; 1962 Elf_Shdr *symsec = &info->sechdrs[info->index.sym];
1957 Elf_Sym *sym = (void *)symsec->sh_addr; 1963 Elf_Sym *sym = (void *)symsec->sh_addr;
1958 unsigned long secbase; 1964 unsigned long secbase;
1959 unsigned int i; 1965 unsigned int i;
1960 int ret = 0; 1966 int ret = 0;
1961 const struct kernel_symbol *ksym; 1967 const struct kernel_symbol *ksym;
1962 1968
1963 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) { 1969 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
1964 const char *name = info->strtab + sym[i].st_name; 1970 const char *name = info->strtab + sym[i].st_name;
1965 1971
1966 switch (sym[i].st_shndx) { 1972 switch (sym[i].st_shndx) {
1967 case SHN_COMMON: 1973 case SHN_COMMON:
1968 /* We compiled with -fno-common. These are not 1974 /* We compiled with -fno-common. These are not
1969 supposed to happen. */ 1975 supposed to happen. */
1970 pr_debug("Common symbol: %s\n", name); 1976 pr_debug("Common symbol: %s\n", name);
1971 printk("%s: please compile with -fno-common\n", 1977 printk("%s: please compile with -fno-common\n",
1972 mod->name); 1978 mod->name);
1973 ret = -ENOEXEC; 1979 ret = -ENOEXEC;
1974 break; 1980 break;
1975 1981
1976 case SHN_ABS: 1982 case SHN_ABS:
1977 /* Don't need to do anything */ 1983 /* Don't need to do anything */
1978 pr_debug("Absolute symbol: 0x%08lx\n", 1984 pr_debug("Absolute symbol: 0x%08lx\n",
1979 (long)sym[i].st_value); 1985 (long)sym[i].st_value);
1980 break; 1986 break;
1981 1987
1982 case SHN_UNDEF: 1988 case SHN_UNDEF:
1983 ksym = resolve_symbol_wait(mod, info, name); 1989 ksym = resolve_symbol_wait(mod, info, name);
1984 /* Ok if resolved. */ 1990 /* Ok if resolved. */
1985 if (ksym && !IS_ERR(ksym)) { 1991 if (ksym && !IS_ERR(ksym)) {
1986 sym[i].st_value = ksym->value; 1992 sym[i].st_value = ksym->value;
1987 break; 1993 break;
1988 } 1994 }
1989 1995
1990 /* Ok if weak. */ 1996 /* Ok if weak. */
1991 if (!ksym && ELF_ST_BIND(sym[i].st_info) == STB_WEAK) 1997 if (!ksym && ELF_ST_BIND(sym[i].st_info) == STB_WEAK)
1992 break; 1998 break;
1993 1999
1994 printk(KERN_WARNING "%s: Unknown symbol %s (err %li)\n", 2000 printk(KERN_WARNING "%s: Unknown symbol %s (err %li)\n",
1995 mod->name, name, PTR_ERR(ksym)); 2001 mod->name, name, PTR_ERR(ksym));
1996 ret = PTR_ERR(ksym) ?: -ENOENT; 2002 ret = PTR_ERR(ksym) ?: -ENOENT;
1997 break; 2003 break;
1998 2004
1999 default: 2005 default:
2000 /* Divert to percpu allocation if a percpu var. */ 2006 /* Divert to percpu allocation if a percpu var. */
2001 if (sym[i].st_shndx == info->index.pcpu) 2007 if (sym[i].st_shndx == info->index.pcpu)
2002 secbase = (unsigned long)mod_percpu(mod); 2008 secbase = (unsigned long)mod_percpu(mod);
2003 else 2009 else
2004 secbase = info->sechdrs[sym[i].st_shndx].sh_addr; 2010 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
2005 sym[i].st_value += secbase; 2011 sym[i].st_value += secbase;
2006 break; 2012 break;
2007 } 2013 }
2008 } 2014 }
2009 2015
2010 return ret; 2016 return ret;
2011 } 2017 }
2012 2018
2013 static int apply_relocations(struct module *mod, const struct load_info *info) 2019 static int apply_relocations(struct module *mod, const struct load_info *info)
2014 { 2020 {
2015 unsigned int i; 2021 unsigned int i;
2016 int err = 0; 2022 int err = 0;
2017 2023
2018 /* Now do relocations. */ 2024 /* Now do relocations. */
2019 for (i = 1; i < info->hdr->e_shnum; i++) { 2025 for (i = 1; i < info->hdr->e_shnum; i++) {
2020 unsigned int infosec = info->sechdrs[i].sh_info; 2026 unsigned int infosec = info->sechdrs[i].sh_info;
2021 2027
2022 /* Not a valid relocation section? */ 2028 /* Not a valid relocation section? */
2023 if (infosec >= info->hdr->e_shnum) 2029 if (infosec >= info->hdr->e_shnum)
2024 continue; 2030 continue;
2025 2031
2026 /* Don't bother with non-allocated sections */ 2032 /* Don't bother with non-allocated sections */
2027 if (!(info->sechdrs[infosec].sh_flags & SHF_ALLOC)) 2033 if (!(info->sechdrs[infosec].sh_flags & SHF_ALLOC))
2028 continue; 2034 continue;
2029 2035
2030 if (info->sechdrs[i].sh_type == SHT_REL) 2036 if (info->sechdrs[i].sh_type == SHT_REL)
2031 err = apply_relocate(info->sechdrs, info->strtab, 2037 err = apply_relocate(info->sechdrs, info->strtab,
2032 info->index.sym, i, mod); 2038 info->index.sym, i, mod);
2033 else if (info->sechdrs[i].sh_type == SHT_RELA) 2039 else if (info->sechdrs[i].sh_type == SHT_RELA)
2034 err = apply_relocate_add(info->sechdrs, info->strtab, 2040 err = apply_relocate_add(info->sechdrs, info->strtab,
2035 info->index.sym, i, mod); 2041 info->index.sym, i, mod);
2036 if (err < 0) 2042 if (err < 0)
2037 break; 2043 break;
2038 } 2044 }
2039 return err; 2045 return err;
2040 } 2046 }
2041 2047
2042 /* Additional bytes needed by arch in front of individual sections */ 2048 /* Additional bytes needed by arch in front of individual sections */
2043 unsigned int __weak arch_mod_section_prepend(struct module *mod, 2049 unsigned int __weak arch_mod_section_prepend(struct module *mod,
2044 unsigned int section) 2050 unsigned int section)
2045 { 2051 {
2046 /* default implementation just returns zero */ 2052 /* default implementation just returns zero */
2047 return 0; 2053 return 0;
2048 } 2054 }
2049 2055
2050 /* Update size with this section: return offset. */ 2056 /* Update size with this section: return offset. */
2051 static long get_offset(struct module *mod, unsigned int *size, 2057 static long get_offset(struct module *mod, unsigned int *size,
2052 Elf_Shdr *sechdr, unsigned int section) 2058 Elf_Shdr *sechdr, unsigned int section)
2053 { 2059 {
2054 long ret; 2060 long ret;
2055 2061
2056 *size += arch_mod_section_prepend(mod, section); 2062 *size += arch_mod_section_prepend(mod, section);
2057 ret = ALIGN(*size, sechdr->sh_addralign ?: 1); 2063 ret = ALIGN(*size, sechdr->sh_addralign ?: 1);
2058 *size = ret + sechdr->sh_size; 2064 *size = ret + sechdr->sh_size;
2059 return ret; 2065 return ret;
2060 } 2066 }
2061 2067
2062 /* Lay out the SHF_ALLOC sections in a way not dissimilar to how ld 2068 /* Lay out the SHF_ALLOC sections in a way not dissimilar to how ld
2063 might -- code, read-only data, read-write data, small data. Tally 2069 might -- code, read-only data, read-write data, small data. Tally
2064 sizes, and place the offsets into sh_entsize fields: high bit means it 2070 sizes, and place the offsets into sh_entsize fields: high bit means it
2065 belongs in init. */ 2071 belongs in init. */
2066 static void layout_sections(struct module *mod, struct load_info *info) 2072 static void layout_sections(struct module *mod, struct load_info *info)
2067 { 2073 {
2068 static unsigned long const masks[][2] = { 2074 static unsigned long const masks[][2] = {
2069 /* NOTE: all executable code must be the first section 2075 /* NOTE: all executable code must be the first section
2070 * in this array; otherwise modify the text_size 2076 * in this array; otherwise modify the text_size
2071 * finder in the two loops below */ 2077 * finder in the two loops below */
2072 { SHF_EXECINSTR | SHF_ALLOC, ARCH_SHF_SMALL }, 2078 { SHF_EXECINSTR | SHF_ALLOC, ARCH_SHF_SMALL },
2073 { SHF_ALLOC, SHF_WRITE | ARCH_SHF_SMALL }, 2079 { SHF_ALLOC, SHF_WRITE | ARCH_SHF_SMALL },
2074 { SHF_WRITE | SHF_ALLOC, ARCH_SHF_SMALL }, 2080 { SHF_WRITE | SHF_ALLOC, ARCH_SHF_SMALL },
2075 { ARCH_SHF_SMALL | SHF_ALLOC, 0 } 2081 { ARCH_SHF_SMALL | SHF_ALLOC, 0 }
2076 }; 2082 };
2077 unsigned int m, i; 2083 unsigned int m, i;
2078 2084
2079 for (i = 0; i < info->hdr->e_shnum; i++) 2085 for (i = 0; i < info->hdr->e_shnum; i++)
2080 info->sechdrs[i].sh_entsize = ~0UL; 2086 info->sechdrs[i].sh_entsize = ~0UL;
2081 2087
2082 pr_debug("Core section allocation order:\n"); 2088 pr_debug("Core section allocation order:\n");
2083 for (m = 0; m < ARRAY_SIZE(masks); ++m) { 2089 for (m = 0; m < ARRAY_SIZE(masks); ++m) {
2084 for (i = 0; i < info->hdr->e_shnum; ++i) { 2090 for (i = 0; i < info->hdr->e_shnum; ++i) {
2085 Elf_Shdr *s = &info->sechdrs[i]; 2091 Elf_Shdr *s = &info->sechdrs[i];
2086 const char *sname = info->secstrings + s->sh_name; 2092 const char *sname = info->secstrings + s->sh_name;
2087 2093
2088 if ((s->sh_flags & masks[m][0]) != masks[m][0] 2094 if ((s->sh_flags & masks[m][0]) != masks[m][0]
2089 || (s->sh_flags & masks[m][1]) 2095 || (s->sh_flags & masks[m][1])
2090 || s->sh_entsize != ~0UL 2096 || s->sh_entsize != ~0UL
2091 || strstarts(sname, ".init")) 2097 || strstarts(sname, ".init"))
2092 continue; 2098 continue;
2093 s->sh_entsize = get_offset(mod, &mod->core_size, s, i); 2099 s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
2094 pr_debug("\t%s\n", sname); 2100 pr_debug("\t%s\n", sname);
2095 } 2101 }
2096 switch (m) { 2102 switch (m) {
2097 case 0: /* executable */ 2103 case 0: /* executable */
2098 mod->core_size = debug_align(mod->core_size); 2104 mod->core_size = debug_align(mod->core_size);
2099 mod->core_text_size = mod->core_size; 2105 mod->core_text_size = mod->core_size;
2100 break; 2106 break;
2101 case 1: /* RO: text and ro-data */ 2107 case 1: /* RO: text and ro-data */
2102 mod->core_size = debug_align(mod->core_size); 2108 mod->core_size = debug_align(mod->core_size);
2103 mod->core_ro_size = mod->core_size; 2109 mod->core_ro_size = mod->core_size;
2104 break; 2110 break;
2105 case 3: /* whole core */ 2111 case 3: /* whole core */
2106 mod->core_size = debug_align(mod->core_size); 2112 mod->core_size = debug_align(mod->core_size);
2107 break; 2113 break;
2108 } 2114 }
2109 } 2115 }
2110 2116
2111 pr_debug("Init section allocation order:\n"); 2117 pr_debug("Init section allocation order:\n");
2112 for (m = 0; m < ARRAY_SIZE(masks); ++m) { 2118 for (m = 0; m < ARRAY_SIZE(masks); ++m) {
2113 for (i = 0; i < info->hdr->e_shnum; ++i) { 2119 for (i = 0; i < info->hdr->e_shnum; ++i) {
2114 Elf_Shdr *s = &info->sechdrs[i]; 2120 Elf_Shdr *s = &info->sechdrs[i];
2115 const char *sname = info->secstrings + s->sh_name; 2121 const char *sname = info->secstrings + s->sh_name;
2116 2122
2117 if ((s->sh_flags & masks[m][0]) != masks[m][0] 2123 if ((s->sh_flags & masks[m][0]) != masks[m][0]
2118 || (s->sh_flags & masks[m][1]) 2124 || (s->sh_flags & masks[m][1])
2119 || s->sh_entsize != ~0UL 2125 || s->sh_entsize != ~0UL
2120 || !strstarts(sname, ".init")) 2126 || !strstarts(sname, ".init"))
2121 continue; 2127 continue;
2122 s->sh_entsize = (get_offset(mod, &mod->init_size, s, i) 2128 s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
2123 | INIT_OFFSET_MASK); 2129 | INIT_OFFSET_MASK);
2124 pr_debug("\t%s\n", sname); 2130 pr_debug("\t%s\n", sname);
2125 } 2131 }
2126 switch (m) { 2132 switch (m) {
2127 case 0: /* executable */ 2133 case 0: /* executable */
2128 mod->init_size = debug_align(mod->init_size); 2134 mod->init_size = debug_align(mod->init_size);
2129 mod->init_text_size = mod->init_size; 2135 mod->init_text_size = mod->init_size;
2130 break; 2136 break;
2131 case 1: /* RO: text and ro-data */ 2137 case 1: /* RO: text and ro-data */
2132 mod->init_size = debug_align(mod->init_size); 2138 mod->init_size = debug_align(mod->init_size);
2133 mod->init_ro_size = mod->init_size; 2139 mod->init_ro_size = mod->init_size;
2134 break; 2140 break;
2135 case 3: /* whole init */ 2141 case 3: /* whole init */
2136 mod->init_size = debug_align(mod->init_size); 2142 mod->init_size = debug_align(mod->init_size);
2137 break; 2143 break;
2138 } 2144 }
2139 } 2145 }
2140 } 2146 }
2141 2147
2142 static void set_license(struct module *mod, const char *license) 2148 static void set_license(struct module *mod, const char *license)
2143 { 2149 {
2144 if (!license) 2150 if (!license)
2145 license = "unspecified"; 2151 license = "unspecified";
2146 2152
2147 if (!license_is_gpl_compatible(license)) { 2153 if (!license_is_gpl_compatible(license)) {
2148 if (!test_taint(TAINT_PROPRIETARY_MODULE)) 2154 if (!test_taint(TAINT_PROPRIETARY_MODULE))
2149 printk(KERN_WARNING "%s: module license '%s' taints " 2155 printk(KERN_WARNING "%s: module license '%s' taints "
2150 "kernel.\n", mod->name, license); 2156 "kernel.\n", mod->name, license);
2151 add_taint_module(mod, TAINT_PROPRIETARY_MODULE, 2157 add_taint_module(mod, TAINT_PROPRIETARY_MODULE,
2152 LOCKDEP_NOW_UNRELIABLE); 2158 LOCKDEP_NOW_UNRELIABLE);
2153 } 2159 }
2154 } 2160 }
2155 2161
2156 /* Parse tag=value strings from .modinfo section */ 2162 /* Parse tag=value strings from .modinfo section */
2157 static char *next_string(char *string, unsigned long *secsize) 2163 static char *next_string(char *string, unsigned long *secsize)
2158 { 2164 {
2159 /* Skip non-zero chars */ 2165 /* Skip non-zero chars */
2160 while (string[0]) { 2166 while (string[0]) {
2161 string++; 2167 string++;
2162 if ((*secsize)-- <= 1) 2168 if ((*secsize)-- <= 1)
2163 return NULL; 2169 return NULL;
2164 } 2170 }
2165 2171
2166 /* Skip any zero padding. */ 2172 /* Skip any zero padding. */
2167 while (!string[0]) { 2173 while (!string[0]) {
2168 string++; 2174 string++;
2169 if ((*secsize)-- <= 1) 2175 if ((*secsize)-- <= 1)
2170 return NULL; 2176 return NULL;
2171 } 2177 }
2172 return string; 2178 return string;
2173 } 2179 }
2174 2180
2175 static char *get_modinfo(struct load_info *info, const char *tag) 2181 static char *get_modinfo(struct load_info *info, const char *tag)
2176 { 2182 {
2177 char *p; 2183 char *p;
2178 unsigned int taglen = strlen(tag); 2184 unsigned int taglen = strlen(tag);
2179 Elf_Shdr *infosec = &info->sechdrs[info->index.info]; 2185 Elf_Shdr *infosec = &info->sechdrs[info->index.info];
2180 unsigned long size = infosec->sh_size; 2186 unsigned long size = infosec->sh_size;
2181 2187
2182 for (p = (char *)infosec->sh_addr; p; p = next_string(p, &size)) { 2188 for (p = (char *)infosec->sh_addr; p; p = next_string(p, &size)) {
2183 if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=') 2189 if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=')
2184 return p + taglen + 1; 2190 return p + taglen + 1;
2185 } 2191 }
2186 return NULL; 2192 return NULL;
2187 } 2193 }
2188 2194
2189 static void setup_modinfo(struct module *mod, struct load_info *info) 2195 static void setup_modinfo(struct module *mod, struct load_info *info)
2190 { 2196 {
2191 struct module_attribute *attr; 2197 struct module_attribute *attr;
2192 int i; 2198 int i;
2193 2199
2194 for (i = 0; (attr = modinfo_attrs[i]); i++) { 2200 for (i = 0; (attr = modinfo_attrs[i]); i++) {
2195 if (attr->setup) 2201 if (attr->setup)
2196 attr->setup(mod, get_modinfo(info, attr->attr.name)); 2202 attr->setup(mod, get_modinfo(info, attr->attr.name));
2197 } 2203 }
2198 } 2204 }
2199 2205
2200 static void free_modinfo(struct module *mod) 2206 static void free_modinfo(struct module *mod)
2201 { 2207 {
2202 struct module_attribute *attr; 2208 struct module_attribute *attr;
2203 int i; 2209 int i;
2204 2210
2205 for (i = 0; (attr = modinfo_attrs[i]); i++) { 2211 for (i = 0; (attr = modinfo_attrs[i]); i++) {
2206 if (attr->free) 2212 if (attr->free)
2207 attr->free(mod); 2213 attr->free(mod);
2208 } 2214 }
2209 } 2215 }
2210 2216
2211 #ifdef CONFIG_KALLSYMS 2217 #ifdef CONFIG_KALLSYMS
2212 2218
2213 /* lookup symbol in given range of kernel_symbols */ 2219 /* lookup symbol in given range of kernel_symbols */
2214 static const struct kernel_symbol *lookup_symbol(const char *name, 2220 static const struct kernel_symbol *lookup_symbol(const char *name,
2215 const struct kernel_symbol *start, 2221 const struct kernel_symbol *start,
2216 const struct kernel_symbol *stop) 2222 const struct kernel_symbol *stop)
2217 { 2223 {
2218 return bsearch(name, start, stop - start, 2224 return bsearch(name, start, stop - start,
2219 sizeof(struct kernel_symbol), cmp_name); 2225 sizeof(struct kernel_symbol), cmp_name);
2220 } 2226 }
2221 2227
2222 static int is_exported(const char *name, unsigned long value, 2228 static int is_exported(const char *name, unsigned long value,
2223 const struct module *mod) 2229 const struct module *mod)
2224 { 2230 {
2225 const struct kernel_symbol *ks; 2231 const struct kernel_symbol *ks;
2226 if (!mod) 2232 if (!mod)
2227 ks = lookup_symbol(name, __start___ksymtab, __stop___ksymtab); 2233 ks = lookup_symbol(name, __start___ksymtab, __stop___ksymtab);
2228 else 2234 else
2229 ks = lookup_symbol(name, mod->syms, mod->syms + mod->num_syms); 2235 ks = lookup_symbol(name, mod->syms, mod->syms + mod->num_syms);
2230 return ks != NULL && ks->value == value; 2236 return ks != NULL && ks->value == value;
2231 } 2237 }
2232 2238
2233 /* As per nm */ 2239 /* As per nm */
2234 static char elf_type(const Elf_Sym *sym, const struct load_info *info) 2240 static char elf_type(const Elf_Sym *sym, const struct load_info *info)
2235 { 2241 {
2236 const Elf_Shdr *sechdrs = info->sechdrs; 2242 const Elf_Shdr *sechdrs = info->sechdrs;
2237 2243
2238 if (ELF_ST_BIND(sym->st_info) == STB_WEAK) { 2244 if (ELF_ST_BIND(sym->st_info) == STB_WEAK) {
2239 if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT) 2245 if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT)
2240 return 'v'; 2246 return 'v';
2241 else 2247 else
2242 return 'w'; 2248 return 'w';
2243 } 2249 }
2244 if (sym->st_shndx == SHN_UNDEF) 2250 if (sym->st_shndx == SHN_UNDEF)
2245 return 'U'; 2251 return 'U';
2246 if (sym->st_shndx == SHN_ABS) 2252 if (sym->st_shndx == SHN_ABS)
2247 return 'a'; 2253 return 'a';
2248 if (sym->st_shndx >= SHN_LORESERVE) 2254 if (sym->st_shndx >= SHN_LORESERVE)
2249 return '?'; 2255 return '?';
2250 if (sechdrs[sym->st_shndx].sh_flags & SHF_EXECINSTR) 2256 if (sechdrs[sym->st_shndx].sh_flags & SHF_EXECINSTR)
2251 return 't'; 2257 return 't';
2252 if (sechdrs[sym->st_shndx].sh_flags & SHF_ALLOC 2258 if (sechdrs[sym->st_shndx].sh_flags & SHF_ALLOC
2253 && sechdrs[sym->st_shndx].sh_type != SHT_NOBITS) { 2259 && sechdrs[sym->st_shndx].sh_type != SHT_NOBITS) {
2254 if (!(sechdrs[sym->st_shndx].sh_flags & SHF_WRITE)) 2260 if (!(sechdrs[sym->st_shndx].sh_flags & SHF_WRITE))
2255 return 'r'; 2261 return 'r';
2256 else if (sechdrs[sym->st_shndx].sh_flags & ARCH_SHF_SMALL) 2262 else if (sechdrs[sym->st_shndx].sh_flags & ARCH_SHF_SMALL)
2257 return 'g'; 2263 return 'g';
2258 else 2264 else
2259 return 'd'; 2265 return 'd';
2260 } 2266 }
2261 if (sechdrs[sym->st_shndx].sh_type == SHT_NOBITS) { 2267 if (sechdrs[sym->st_shndx].sh_type == SHT_NOBITS) {
2262 if (sechdrs[sym->st_shndx].sh_flags & ARCH_SHF_SMALL) 2268 if (sechdrs[sym->st_shndx].sh_flags & ARCH_SHF_SMALL)
2263 return 's'; 2269 return 's';
2264 else 2270 else
2265 return 'b'; 2271 return 'b';
2266 } 2272 }
2267 if (strstarts(info->secstrings + sechdrs[sym->st_shndx].sh_name, 2273 if (strstarts(info->secstrings + sechdrs[sym->st_shndx].sh_name,
2268 ".debug")) { 2274 ".debug")) {
2269 return 'n'; 2275 return 'n';
2270 } 2276 }
2271 return '?'; 2277 return '?';
2272 } 2278 }
2273 2279
2274 static bool is_core_symbol(const Elf_Sym *src, const Elf_Shdr *sechdrs, 2280 static bool is_core_symbol(const Elf_Sym *src, const Elf_Shdr *sechdrs,
2275 unsigned int shnum) 2281 unsigned int shnum)
2276 { 2282 {
2277 const Elf_Shdr *sec; 2283 const Elf_Shdr *sec;
2278 2284
2279 if (src->st_shndx == SHN_UNDEF 2285 if (src->st_shndx == SHN_UNDEF
2280 || src->st_shndx >= shnum 2286 || src->st_shndx >= shnum
2281 || !src->st_name) 2287 || !src->st_name)
2282 return false; 2288 return false;
2283 2289
2284 sec = sechdrs + src->st_shndx; 2290 sec = sechdrs + src->st_shndx;
2285 if (!(sec->sh_flags & SHF_ALLOC) 2291 if (!(sec->sh_flags & SHF_ALLOC)
2286 #ifndef CONFIG_KALLSYMS_ALL 2292 #ifndef CONFIG_KALLSYMS_ALL
2287 || !(sec->sh_flags & SHF_EXECINSTR) 2293 || !(sec->sh_flags & SHF_EXECINSTR)
2288 #endif 2294 #endif
2289 || (sec->sh_entsize & INIT_OFFSET_MASK)) 2295 || (sec->sh_entsize & INIT_OFFSET_MASK))
2290 return false; 2296 return false;
2291 2297
2292 return true; 2298 return true;
2293 } 2299 }
2294 2300
2295 /* 2301 /*
2296 * We only allocate and copy the strings needed by the parts of symtab 2302 * We only allocate and copy the strings needed by the parts of symtab
2297 * we keep. This is simple, but has the effect of making multiple 2303 * we keep. This is simple, but has the effect of making multiple
2298 * copies of duplicates. We could be more sophisticated, see 2304 * copies of duplicates. We could be more sophisticated, see
2299 * linux-kernel thread starting with 2305 * linux-kernel thread starting with
2300 * <73defb5e4bca04a6431392cc341112b1@localhost>. 2306 * <73defb5e4bca04a6431392cc341112b1@localhost>.
2301 */ 2307 */
2302 static void layout_symtab(struct module *mod, struct load_info *info) 2308 static void layout_symtab(struct module *mod, struct load_info *info)
2303 { 2309 {
2304 Elf_Shdr *symsect = info->sechdrs + info->index.sym; 2310 Elf_Shdr *symsect = info->sechdrs + info->index.sym;
2305 Elf_Shdr *strsect = info->sechdrs + info->index.str; 2311 Elf_Shdr *strsect = info->sechdrs + info->index.str;
2306 const Elf_Sym *src; 2312 const Elf_Sym *src;
2307 unsigned int i, nsrc, ndst, strtab_size = 0; 2313 unsigned int i, nsrc, ndst, strtab_size = 0;
2308 2314
2309 /* Put symbol section at end of init part of module. */ 2315 /* Put symbol section at end of init part of module. */
2310 symsect->sh_flags |= SHF_ALLOC; 2316 symsect->sh_flags |= SHF_ALLOC;
2311 symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect, 2317 symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
2312 info->index.sym) | INIT_OFFSET_MASK; 2318 info->index.sym) | INIT_OFFSET_MASK;
2313 pr_debug("\t%s\n", info->secstrings + symsect->sh_name); 2319 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
2314 2320
2315 src = (void *)info->hdr + symsect->sh_offset; 2321 src = (void *)info->hdr + symsect->sh_offset;
2316 nsrc = symsect->sh_size / sizeof(*src); 2322 nsrc = symsect->sh_size / sizeof(*src);
2317 2323
2318 /* Compute total space required for the core symbols' strtab. */ 2324 /* Compute total space required for the core symbols' strtab. */
2319 for (ndst = i = 0; i < nsrc; i++) { 2325 for (ndst = i = 0; i < nsrc; i++) {
2320 if (i == 0 || 2326 if (i == 0 ||
2321 is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum)) { 2327 is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum)) {
2322 strtab_size += strlen(&info->strtab[src[i].st_name])+1; 2328 strtab_size += strlen(&info->strtab[src[i].st_name])+1;
2323 ndst++; 2329 ndst++;
2324 } 2330 }
2325 } 2331 }
2326 2332
2327 /* Append room for core symbols at end of core part. */ 2333 /* Append room for core symbols at end of core part. */
2328 info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1); 2334 info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
2329 info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym); 2335 info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
2330 mod->core_size += strtab_size; 2336 mod->core_size += strtab_size;
2331 2337
2332 /* Put string table section at end of init part of module. */ 2338 /* Put string table section at end of init part of module. */
2333 strsect->sh_flags |= SHF_ALLOC; 2339 strsect->sh_flags |= SHF_ALLOC;
2334 strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect, 2340 strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
2335 info->index.str) | INIT_OFFSET_MASK; 2341 info->index.str) | INIT_OFFSET_MASK;
2336 pr_debug("\t%s\n", info->secstrings + strsect->sh_name); 2342 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
2337 } 2343 }
2338 2344
2339 static void add_kallsyms(struct module *mod, const struct load_info *info) 2345 static void add_kallsyms(struct module *mod, const struct load_info *info)
2340 { 2346 {
2341 unsigned int i, ndst; 2347 unsigned int i, ndst;
2342 const Elf_Sym *src; 2348 const Elf_Sym *src;
2343 Elf_Sym *dst; 2349 Elf_Sym *dst;
2344 char *s; 2350 char *s;
2345 Elf_Shdr *symsec = &info->sechdrs[info->index.sym]; 2351 Elf_Shdr *symsec = &info->sechdrs[info->index.sym];
2346 2352
2347 mod->symtab = (void *)symsec->sh_addr; 2353 mod->symtab = (void *)symsec->sh_addr;
2348 mod->num_symtab = symsec->sh_size / sizeof(Elf_Sym); 2354 mod->num_symtab = symsec->sh_size / sizeof(Elf_Sym);
2349 /* Make sure we get permanent strtab: don't use info->strtab. */ 2355 /* Make sure we get permanent strtab: don't use info->strtab. */
2350 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr; 2356 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
2351 2357
2352 /* Set types up while we still have access to sections. */ 2358 /* Set types up while we still have access to sections. */
2353 for (i = 0; i < mod->num_symtab; i++) 2359 for (i = 0; i < mod->num_symtab; i++)
2354 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info); 2360 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
2355 2361
2356 mod->core_symtab = dst = mod->module_core + info->symoffs; 2362 mod->core_symtab = dst = mod->module_core + info->symoffs;
2357 mod->core_strtab = s = mod->module_core + info->stroffs; 2363 mod->core_strtab = s = mod->module_core + info->stroffs;
2358 src = mod->symtab; 2364 src = mod->symtab;
2359 for (ndst = i = 0; i < mod->num_symtab; i++) { 2365 for (ndst = i = 0; i < mod->num_symtab; i++) {
2360 if (i == 0 || 2366 if (i == 0 ||
2361 is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum)) { 2367 is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum)) {
2362 dst[ndst] = src[i]; 2368 dst[ndst] = src[i];
2363 dst[ndst++].st_name = s - mod->core_strtab; 2369 dst[ndst++].st_name = s - mod->core_strtab;
2364 s += strlcpy(s, &mod->strtab[src[i].st_name], 2370 s += strlcpy(s, &mod->strtab[src[i].st_name],
2365 KSYM_NAME_LEN) + 1; 2371 KSYM_NAME_LEN) + 1;
2366 } 2372 }
2367 } 2373 }
2368 mod->core_num_syms = ndst; 2374 mod->core_num_syms = ndst;
2369 } 2375 }
2370 #else 2376 #else
2371 static inline void layout_symtab(struct module *mod, struct load_info *info) 2377 static inline void layout_symtab(struct module *mod, struct load_info *info)
2372 { 2378 {
2373 } 2379 }
2374 2380
2375 static void add_kallsyms(struct module *mod, const struct load_info *info) 2381 static void add_kallsyms(struct module *mod, const struct load_info *info)
2376 { 2382 {
2377 } 2383 }
2378 #endif /* CONFIG_KALLSYMS */ 2384 #endif /* CONFIG_KALLSYMS */
2379 2385
2380 static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num) 2386 static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num)
2381 { 2387 {
2382 if (!debug) 2388 if (!debug)
2383 return; 2389 return;
2384 #ifdef CONFIG_DYNAMIC_DEBUG 2390 #ifdef CONFIG_DYNAMIC_DEBUG
2385 if (ddebug_add_module(debug, num, debug->modname)) 2391 if (ddebug_add_module(debug, num, debug->modname))
2386 printk(KERN_ERR "dynamic debug error adding module: %s\n", 2392 printk(KERN_ERR "dynamic debug error adding module: %s\n",
2387 debug->modname); 2393 debug->modname);
2388 #endif 2394 #endif
2389 } 2395 }
2390 2396
2391 static void dynamic_debug_remove(struct _ddebug *debug) 2397 static void dynamic_debug_remove(struct _ddebug *debug)
2392 { 2398 {
2393 if (debug) 2399 if (debug)
2394 ddebug_remove_module(debug->modname); 2400 ddebug_remove_module(debug->modname);
2395 } 2401 }
2396 2402
2397 void * __weak module_alloc(unsigned long size) 2403 void * __weak module_alloc(unsigned long size)
2398 { 2404 {
2399 return vmalloc_exec(size); 2405 return vmalloc_exec(size);
2400 } 2406 }
2401 2407
2402 static void *module_alloc_update_bounds(unsigned long size) 2408 static void *module_alloc_update_bounds(unsigned long size)
2403 { 2409 {
2404 void *ret = module_alloc(size); 2410 void *ret = module_alloc(size);
2405 2411
2406 if (ret) { 2412 if (ret) {
2407 mutex_lock(&module_mutex); 2413 mutex_lock(&module_mutex);
2408 /* Update module bounds. */ 2414 /* Update module bounds. */
2409 if ((unsigned long)ret < module_addr_min) 2415 if ((unsigned long)ret < module_addr_min)
2410 module_addr_min = (unsigned long)ret; 2416 module_addr_min = (unsigned long)ret;
2411 if ((unsigned long)ret + size > module_addr_max) 2417 if ((unsigned long)ret + size > module_addr_max)
2412 module_addr_max = (unsigned long)ret + size; 2418 module_addr_max = (unsigned long)ret + size;
2413 mutex_unlock(&module_mutex); 2419 mutex_unlock(&module_mutex);
2414 } 2420 }
2415 return ret; 2421 return ret;
2416 } 2422 }
2417 2423
2418 #ifdef CONFIG_DEBUG_KMEMLEAK 2424 #ifdef CONFIG_DEBUG_KMEMLEAK
2419 static void kmemleak_load_module(const struct module *mod, 2425 static void kmemleak_load_module(const struct module *mod,
2420 const struct load_info *info) 2426 const struct load_info *info)
2421 { 2427 {
2422 unsigned int i; 2428 unsigned int i;
2423 2429
2424 /* only scan the sections containing data */ 2430 /* only scan the sections containing data */
2425 kmemleak_scan_area(mod, sizeof(struct module), GFP_KERNEL); 2431 kmemleak_scan_area(mod, sizeof(struct module), GFP_KERNEL);
2426 2432
2427 for (i = 1; i < info->hdr->e_shnum; i++) { 2433 for (i = 1; i < info->hdr->e_shnum; i++) {
2428 const char *name = info->secstrings + info->sechdrs[i].sh_name; 2434 const char *name = info->secstrings + info->sechdrs[i].sh_name;
2429 if (!(info->sechdrs[i].sh_flags & SHF_ALLOC)) 2435 if (!(info->sechdrs[i].sh_flags & SHF_ALLOC))
2430 continue; 2436 continue;
2431 if (!strstarts(name, ".data") && !strstarts(name, ".bss")) 2437 if (!strstarts(name, ".data") && !strstarts(name, ".bss"))
2432 continue; 2438 continue;
2433 2439
2434 kmemleak_scan_area((void *)info->sechdrs[i].sh_addr, 2440 kmemleak_scan_area((void *)info->sechdrs[i].sh_addr,
2435 info->sechdrs[i].sh_size, GFP_KERNEL); 2441 info->sechdrs[i].sh_size, GFP_KERNEL);
2436 } 2442 }
2437 } 2443 }
2438 #else 2444 #else
2439 static inline void kmemleak_load_module(const struct module *mod, 2445 static inline void kmemleak_load_module(const struct module *mod,
2440 const struct load_info *info) 2446 const struct load_info *info)
2441 { 2447 {
2442 } 2448 }
2443 #endif 2449 #endif
2444 2450
2445 #ifdef CONFIG_MODULE_SIG 2451 #ifdef CONFIG_MODULE_SIG
2446 static int module_sig_check(struct load_info *info) 2452 static int module_sig_check(struct load_info *info)
2447 { 2453 {
2448 int err = -ENOKEY; 2454 int err = -ENOKEY;
2449 const unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1; 2455 const unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1;
2450 const void *mod = info->hdr; 2456 const void *mod = info->hdr;
2451 2457
2452 if (info->len > markerlen && 2458 if (info->len > markerlen &&
2453 memcmp(mod + info->len - markerlen, MODULE_SIG_STRING, markerlen) == 0) { 2459 memcmp(mod + info->len - markerlen, MODULE_SIG_STRING, markerlen) == 0) {
2454 /* We truncate the module to discard the signature */ 2460 /* We truncate the module to discard the signature */
2455 info->len -= markerlen; 2461 info->len -= markerlen;
2456 err = mod_verify_sig(mod, &info->len); 2462 err = mod_verify_sig(mod, &info->len);
2457 } 2463 }
2458 2464
2459 if (!err) { 2465 if (!err) {
2460 info->sig_ok = true; 2466 info->sig_ok = true;
2461 return 0; 2467 return 0;
2462 } 2468 }
2463 2469
2464 /* Not having a signature is only an error if we're strict. */ 2470 /* Not having a signature is only an error if we're strict. */
2465 if (err < 0 && fips_enabled) 2471 if (err < 0 && fips_enabled)
2466 panic("Module verification failed with error %d in FIPS mode\n", 2472 panic("Module verification failed with error %d in FIPS mode\n",
2467 err); 2473 err);
2468 if (err == -ENOKEY && !sig_enforce) 2474 if (err == -ENOKEY && !sig_enforce)
2469 err = 0; 2475 err = 0;
2470 2476
2471 return err; 2477 return err;
2472 } 2478 }
2473 #else /* !CONFIG_MODULE_SIG */ 2479 #else /* !CONFIG_MODULE_SIG */
2474 static int module_sig_check(struct load_info *info) 2480 static int module_sig_check(struct load_info *info)
2475 { 2481 {
2476 return 0; 2482 return 0;
2477 } 2483 }
2478 #endif /* !CONFIG_MODULE_SIG */ 2484 #endif /* !CONFIG_MODULE_SIG */
2479 2485
2480 /* Sanity checks against invalid binaries, wrong arch, weird elf version. */ 2486 /* Sanity checks against invalid binaries, wrong arch, weird elf version. */
2481 static int elf_header_check(struct load_info *info) 2487 static int elf_header_check(struct load_info *info)
2482 { 2488 {
2483 if (info->len < sizeof(*(info->hdr))) 2489 if (info->len < sizeof(*(info->hdr)))
2484 return -ENOEXEC; 2490 return -ENOEXEC;
2485 2491
2486 if (memcmp(info->hdr->e_ident, ELFMAG, SELFMAG) != 0 2492 if (memcmp(info->hdr->e_ident, ELFMAG, SELFMAG) != 0
2487 || info->hdr->e_type != ET_REL 2493 || info->hdr->e_type != ET_REL
2488 || !elf_check_arch(info->hdr) 2494 || !elf_check_arch(info->hdr)
2489 || info->hdr->e_shentsize != sizeof(Elf_Shdr)) 2495 || info->hdr->e_shentsize != sizeof(Elf_Shdr))
2490 return -ENOEXEC; 2496 return -ENOEXEC;
2491 2497
2492 if (info->hdr->e_shoff >= info->len 2498 if (info->hdr->e_shoff >= info->len
2493 || (info->hdr->e_shnum * sizeof(Elf_Shdr) > 2499 || (info->hdr->e_shnum * sizeof(Elf_Shdr) >
2494 info->len - info->hdr->e_shoff)) 2500 info->len - info->hdr->e_shoff))
2495 return -ENOEXEC; 2501 return -ENOEXEC;
2496 2502
2497 return 0; 2503 return 0;
2498 } 2504 }
2499 2505
2500 /* Sets info->hdr and info->len. */ 2506 /* Sets info->hdr and info->len. */
2501 static int copy_module_from_user(const void __user *umod, unsigned long len, 2507 static int copy_module_from_user(const void __user *umod, unsigned long len,
2502 struct load_info *info) 2508 struct load_info *info)
2503 { 2509 {
2504 int err; 2510 int err;
2505 2511
2506 info->len = len; 2512 info->len = len;
2507 if (info->len < sizeof(*(info->hdr))) 2513 if (info->len < sizeof(*(info->hdr)))
2508 return -ENOEXEC; 2514 return -ENOEXEC;
2509 2515
2510 err = security_kernel_module_from_file(NULL); 2516 err = security_kernel_module_from_file(NULL);
2511 if (err) 2517 if (err)
2512 return err; 2518 return err;
2513 2519
2514 /* Suck in entire file: we'll want most of it. */ 2520 /* Suck in entire file: we'll want most of it. */
2515 info->hdr = vmalloc(info->len); 2521 info->hdr = vmalloc(info->len);
2516 if (!info->hdr) 2522 if (!info->hdr)
2517 return -ENOMEM; 2523 return -ENOMEM;
2518 2524
2519 if (copy_from_user(info->hdr, umod, info->len) != 0) { 2525 if (copy_from_user(info->hdr, umod, info->len) != 0) {
2520 vfree(info->hdr); 2526 vfree(info->hdr);
2521 return -EFAULT; 2527 return -EFAULT;
2522 } 2528 }
2523 2529
2524 return 0; 2530 return 0;
2525 } 2531 }
2526 2532
2527 /* Sets info->hdr and info->len. */ 2533 /* Sets info->hdr and info->len. */
2528 static int copy_module_from_fd(int fd, struct load_info *info) 2534 static int copy_module_from_fd(int fd, struct load_info *info)
2529 { 2535 {
2530 struct file *file; 2536 struct file *file;
2531 int err; 2537 int err;
2532 struct kstat stat; 2538 struct kstat stat;
2533 loff_t pos; 2539 loff_t pos;
2534 ssize_t bytes = 0; 2540 ssize_t bytes = 0;
2535 2541
2536 file = fget(fd); 2542 file = fget(fd);
2537 if (!file) 2543 if (!file)
2538 return -ENOEXEC; 2544 return -ENOEXEC;
2539 2545
2540 err = security_kernel_module_from_file(file); 2546 err = security_kernel_module_from_file(file);
2541 if (err) 2547 if (err)
2542 goto out; 2548 goto out;
2543 2549
2544 err = vfs_getattr(&file->f_path, &stat); 2550 err = vfs_getattr(&file->f_path, &stat);
2545 if (err) 2551 if (err)
2546 goto out; 2552 goto out;
2547 2553
2548 if (stat.size > INT_MAX) { 2554 if (stat.size > INT_MAX) {
2549 err = -EFBIG; 2555 err = -EFBIG;
2550 goto out; 2556 goto out;
2551 } 2557 }
2552 2558
2553 /* Don't hand 0 to vmalloc, it whines. */ 2559 /* Don't hand 0 to vmalloc, it whines. */
2554 if (stat.size == 0) { 2560 if (stat.size == 0) {
2555 err = -EINVAL; 2561 err = -EINVAL;
2556 goto out; 2562 goto out;
2557 } 2563 }
2558 2564
2559 info->hdr = vmalloc(stat.size); 2565 info->hdr = vmalloc(stat.size);
2560 if (!info->hdr) { 2566 if (!info->hdr) {
2561 err = -ENOMEM; 2567 err = -ENOMEM;
2562 goto out; 2568 goto out;
2563 } 2569 }
2564 2570
2565 pos = 0; 2571 pos = 0;
2566 while (pos < stat.size) { 2572 while (pos < stat.size) {
2567 bytes = kernel_read(file, pos, (char *)(info->hdr) + pos, 2573 bytes = kernel_read(file, pos, (char *)(info->hdr) + pos,
2568 stat.size - pos); 2574 stat.size - pos);
2569 if (bytes < 0) { 2575 if (bytes < 0) {
2570 vfree(info->hdr); 2576 vfree(info->hdr);
2571 err = bytes; 2577 err = bytes;
2572 goto out; 2578 goto out;
2573 } 2579 }
2574 if (bytes == 0) 2580 if (bytes == 0)
2575 break; 2581 break;
2576 pos += bytes; 2582 pos += bytes;
2577 } 2583 }
2578 info->len = pos; 2584 info->len = pos;
2579 2585
2580 out: 2586 out:
2581 fput(file); 2587 fput(file);
2582 return err; 2588 return err;
2583 } 2589 }
2584 2590
2585 static void free_copy(struct load_info *info) 2591 static void free_copy(struct load_info *info)
2586 { 2592 {
2587 vfree(info->hdr); 2593 vfree(info->hdr);
2588 } 2594 }
2589 2595
2590 static int rewrite_section_headers(struct load_info *info, int flags) 2596 static int rewrite_section_headers(struct load_info *info, int flags)
2591 { 2597 {
2592 unsigned int i; 2598 unsigned int i;
2593 2599
2594 /* This should always be true, but let's be sure. */ 2600 /* This should always be true, but let's be sure. */
2595 info->sechdrs[0].sh_addr = 0; 2601 info->sechdrs[0].sh_addr = 0;
2596 2602
2597 for (i = 1; i < info->hdr->e_shnum; i++) { 2603 for (i = 1; i < info->hdr->e_shnum; i++) {
2598 Elf_Shdr *shdr = &info->sechdrs[i]; 2604 Elf_Shdr *shdr = &info->sechdrs[i];
2599 if (shdr->sh_type != SHT_NOBITS 2605 if (shdr->sh_type != SHT_NOBITS
2600 && info->len < shdr->sh_offset + shdr->sh_size) { 2606 && info->len < shdr->sh_offset + shdr->sh_size) {
2601 printk(KERN_ERR "Module len %lu truncated\n", 2607 printk(KERN_ERR "Module len %lu truncated\n",
2602 info->len); 2608 info->len);
2603 return -ENOEXEC; 2609 return -ENOEXEC;
2604 } 2610 }
2605 2611
2606 /* Mark all sections sh_addr with their address in the 2612 /* Mark all sections sh_addr with their address in the
2607 temporary image. */ 2613 temporary image. */
2608 shdr->sh_addr = (size_t)info->hdr + shdr->sh_offset; 2614 shdr->sh_addr = (size_t)info->hdr + shdr->sh_offset;
2609 2615
2610 #ifndef CONFIG_MODULE_UNLOAD 2616 #ifndef CONFIG_MODULE_UNLOAD
2611 /* Don't load .exit sections */ 2617 /* Don't load .exit sections */
2612 if (strstarts(info->secstrings+shdr->sh_name, ".exit")) 2618 if (strstarts(info->secstrings+shdr->sh_name, ".exit"))
2613 shdr->sh_flags &= ~(unsigned long)SHF_ALLOC; 2619 shdr->sh_flags &= ~(unsigned long)SHF_ALLOC;
2614 #endif 2620 #endif
2615 } 2621 }
2616 2622
2617 /* Track but don't keep modinfo and version sections. */ 2623 /* Track but don't keep modinfo and version sections. */
2618 if (flags & MODULE_INIT_IGNORE_MODVERSIONS) 2624 if (flags & MODULE_INIT_IGNORE_MODVERSIONS)
2619 info->index.vers = 0; /* Pretend no __versions section! */ 2625 info->index.vers = 0; /* Pretend no __versions section! */
2620 else 2626 else
2621 info->index.vers = find_sec(info, "__versions"); 2627 info->index.vers = find_sec(info, "__versions");
2622 info->index.info = find_sec(info, ".modinfo"); 2628 info->index.info = find_sec(info, ".modinfo");
2623 info->sechdrs[info->index.info].sh_flags &= ~(unsigned long)SHF_ALLOC; 2629 info->sechdrs[info->index.info].sh_flags &= ~(unsigned long)SHF_ALLOC;
2624 info->sechdrs[info->index.vers].sh_flags &= ~(unsigned long)SHF_ALLOC; 2630 info->sechdrs[info->index.vers].sh_flags &= ~(unsigned long)SHF_ALLOC;
2625 return 0; 2631 return 0;
2626 } 2632 }
2627 2633
2628 /* 2634 /*
2629 * Set up our basic convenience variables (pointers to section headers, 2635 * Set up our basic convenience variables (pointers to section headers,
2630 * search for module section index etc), and do some basic section 2636 * search for module section index etc), and do some basic section
2631 * verification. 2637 * verification.
2632 * 2638 *
2633 * Return the temporary module pointer (we'll replace it with the final 2639 * Return the temporary module pointer (we'll replace it with the final
2634 * one when we move the module sections around). 2640 * one when we move the module sections around).
2635 */ 2641 */
2636 static struct module *setup_load_info(struct load_info *info, int flags) 2642 static struct module *setup_load_info(struct load_info *info, int flags)
2637 { 2643 {
2638 unsigned int i; 2644 unsigned int i;
2639 int err; 2645 int err;
2640 struct module *mod; 2646 struct module *mod;
2641 2647
2642 /* Set up the convenience variables */ 2648 /* Set up the convenience variables */
2643 info->sechdrs = (void *)info->hdr + info->hdr->e_shoff; 2649 info->sechdrs = (void *)info->hdr + info->hdr->e_shoff;
2644 info->secstrings = (void *)info->hdr 2650 info->secstrings = (void *)info->hdr
2645 + info->sechdrs[info->hdr->e_shstrndx].sh_offset; 2651 + info->sechdrs[info->hdr->e_shstrndx].sh_offset;
2646 2652
2647 err = rewrite_section_headers(info, flags); 2653 err = rewrite_section_headers(info, flags);
2648 if (err) 2654 if (err)
2649 return ERR_PTR(err); 2655 return ERR_PTR(err);
2650 2656
2651 /* Find internal symbols and strings. */ 2657 /* Find internal symbols and strings. */
2652 for (i = 1; i < info->hdr->e_shnum; i++) { 2658 for (i = 1; i < info->hdr->e_shnum; i++) {
2653 if (info->sechdrs[i].sh_type == SHT_SYMTAB) { 2659 if (info->sechdrs[i].sh_type == SHT_SYMTAB) {
2654 info->index.sym = i; 2660 info->index.sym = i;
2655 info->index.str = info->sechdrs[i].sh_link; 2661 info->index.str = info->sechdrs[i].sh_link;
2656 info->strtab = (char *)info->hdr 2662 info->strtab = (char *)info->hdr
2657 + info->sechdrs[info->index.str].sh_offset; 2663 + info->sechdrs[info->index.str].sh_offset;
2658 break; 2664 break;
2659 } 2665 }
2660 } 2666 }
2661 2667
2662 info->index.mod = find_sec(info, ".gnu.linkonce.this_module"); 2668 info->index.mod = find_sec(info, ".gnu.linkonce.this_module");
2663 if (!info->index.mod) { 2669 if (!info->index.mod) {
2664 printk(KERN_WARNING "No module found in object\n"); 2670 printk(KERN_WARNING "No module found in object\n");
2665 return ERR_PTR(-ENOEXEC); 2671 return ERR_PTR(-ENOEXEC);
2666 } 2672 }
2667 /* This is temporary: point mod into copy of data. */ 2673 /* This is temporary: point mod into copy of data. */
2668 mod = (void *)info->sechdrs[info->index.mod].sh_addr; 2674 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
2669 2675
2670 if (info->index.sym == 0) { 2676 if (info->index.sym == 0) {
2671 printk(KERN_WARNING "%s: module has no symbols (stripped?)\n", 2677 printk(KERN_WARNING "%s: module has no symbols (stripped?)\n",
2672 mod->name); 2678 mod->name);
2673 return ERR_PTR(-ENOEXEC); 2679 return ERR_PTR(-ENOEXEC);
2674 } 2680 }
2675 2681
2676 info->index.pcpu = find_pcpusec(info); 2682 info->index.pcpu = find_pcpusec(info);
2677 2683
2678 /* Check module struct version now, before we try to use module. */ 2684 /* Check module struct version now, before we try to use module. */
2679 if (!check_modstruct_version(info->sechdrs, info->index.vers, mod)) 2685 if (!check_modstruct_version(info->sechdrs, info->index.vers, mod))
2680 return ERR_PTR(-ENOEXEC); 2686 return ERR_PTR(-ENOEXEC);
2681 2687
2682 return mod; 2688 return mod;
2683 } 2689 }
2684 2690
2685 static int check_modinfo(struct module *mod, struct load_info *info, int flags) 2691 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
2686 { 2692 {
2687 const char *modmagic = get_modinfo(info, "vermagic"); 2693 const char *modmagic = get_modinfo(info, "vermagic");
2688 int err; 2694 int err;
2689 2695
2690 if (flags & MODULE_INIT_IGNORE_VERMAGIC) 2696 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
2691 modmagic = NULL; 2697 modmagic = NULL;
2692 2698
2693 /* This is allowed: modprobe --force will invalidate it. */ 2699 /* This is allowed: modprobe --force will invalidate it. */
2694 if (!modmagic) { 2700 if (!modmagic) {
2695 err = try_to_force_load(mod, "bad vermagic"); 2701 err = try_to_force_load(mod, "bad vermagic");
2696 if (err) 2702 if (err)
2697 return err; 2703 return err;
2698 } else if (!same_magic(modmagic, vermagic, info->index.vers)) { 2704 } else if (!same_magic(modmagic, vermagic, info->index.vers)) {
2699 printk(KERN_ERR "%s: version magic '%s' should be '%s'\n", 2705 printk(KERN_ERR "%s: version magic '%s' should be '%s'\n",
2700 mod->name, modmagic, vermagic); 2706 mod->name, modmagic, vermagic);
2701 return -ENOEXEC; 2707 return -ENOEXEC;
2702 } 2708 }
2703 2709
2704 if (!get_modinfo(info, "intree")) 2710 if (!get_modinfo(info, "intree"))
2705 add_taint_module(mod, TAINT_OOT_MODULE, LOCKDEP_STILL_OK); 2711 add_taint_module(mod, TAINT_OOT_MODULE, LOCKDEP_STILL_OK);
2706 2712
2707 if (get_modinfo(info, "staging")) { 2713 if (get_modinfo(info, "staging")) {
2708 add_taint_module(mod, TAINT_CRAP, LOCKDEP_STILL_OK); 2714 add_taint_module(mod, TAINT_CRAP, LOCKDEP_STILL_OK);
2709 printk(KERN_WARNING "%s: module is from the staging directory," 2715 printk(KERN_WARNING "%s: module is from the staging directory,"
2710 " the quality is unknown, you have been warned.\n", 2716 " the quality is unknown, you have been warned.\n",
2711 mod->name); 2717 mod->name);
2712 } 2718 }
2713 2719
2714 /* Set up license info based on the info section */ 2720 /* Set up license info based on the info section */
2715 set_license(mod, get_modinfo(info, "license")); 2721 set_license(mod, get_modinfo(info, "license"));
2716 2722
2717 return 0; 2723 return 0;
2718 } 2724 }
2719 2725
2720 static void find_module_sections(struct module *mod, struct load_info *info) 2726 static void find_module_sections(struct module *mod, struct load_info *info)
2721 { 2727 {
2722 mod->kp = section_objs(info, "__param", 2728 mod->kp = section_objs(info, "__param",
2723 sizeof(*mod->kp), &mod->num_kp); 2729 sizeof(*mod->kp), &mod->num_kp);
2724 mod->syms = section_objs(info, "__ksymtab", 2730 mod->syms = section_objs(info, "__ksymtab",
2725 sizeof(*mod->syms), &mod->num_syms); 2731 sizeof(*mod->syms), &mod->num_syms);
2726 mod->crcs = section_addr(info, "__kcrctab"); 2732 mod->crcs = section_addr(info, "__kcrctab");
2727 mod->gpl_syms = section_objs(info, "__ksymtab_gpl", 2733 mod->gpl_syms = section_objs(info, "__ksymtab_gpl",
2728 sizeof(*mod->gpl_syms), 2734 sizeof(*mod->gpl_syms),
2729 &mod->num_gpl_syms); 2735 &mod->num_gpl_syms);
2730 mod->gpl_crcs = section_addr(info, "__kcrctab_gpl"); 2736 mod->gpl_crcs = section_addr(info, "__kcrctab_gpl");
2731 mod->gpl_future_syms = section_objs(info, 2737 mod->gpl_future_syms = section_objs(info,
2732 "__ksymtab_gpl_future", 2738 "__ksymtab_gpl_future",
2733 sizeof(*mod->gpl_future_syms), 2739 sizeof(*mod->gpl_future_syms),
2734 &mod->num_gpl_future_syms); 2740 &mod->num_gpl_future_syms);
2735 mod->gpl_future_crcs = section_addr(info, "__kcrctab_gpl_future"); 2741 mod->gpl_future_crcs = section_addr(info, "__kcrctab_gpl_future");
2736 2742
2737 #ifdef CONFIG_UNUSED_SYMBOLS 2743 #ifdef CONFIG_UNUSED_SYMBOLS
2738 mod->unused_syms = section_objs(info, "__ksymtab_unused", 2744 mod->unused_syms = section_objs(info, "__ksymtab_unused",
2739 sizeof(*mod->unused_syms), 2745 sizeof(*mod->unused_syms),
2740 &mod->num_unused_syms); 2746 &mod->num_unused_syms);
2741 mod->unused_crcs = section_addr(info, "__kcrctab_unused"); 2747 mod->unused_crcs = section_addr(info, "__kcrctab_unused");
2742 mod->unused_gpl_syms = section_objs(info, "__ksymtab_unused_gpl", 2748 mod->unused_gpl_syms = section_objs(info, "__ksymtab_unused_gpl",
2743 sizeof(*mod->unused_gpl_syms), 2749 sizeof(*mod->unused_gpl_syms),
2744 &mod->num_unused_gpl_syms); 2750 &mod->num_unused_gpl_syms);
2745 mod->unused_gpl_crcs = section_addr(info, "__kcrctab_unused_gpl"); 2751 mod->unused_gpl_crcs = section_addr(info, "__kcrctab_unused_gpl");
2746 #endif 2752 #endif
2747 #ifdef CONFIG_CONSTRUCTORS 2753 #ifdef CONFIG_CONSTRUCTORS
2748 mod->ctors = section_objs(info, ".ctors", 2754 mod->ctors = section_objs(info, ".ctors",
2749 sizeof(*mod->ctors), &mod->num_ctors); 2755 sizeof(*mod->ctors), &mod->num_ctors);
2750 #endif 2756 #endif
2751 2757
2752 #ifdef CONFIG_TRACEPOINTS 2758 #ifdef CONFIG_TRACEPOINTS
2753 mod->tracepoints_ptrs = section_objs(info, "__tracepoints_ptrs", 2759 mod->tracepoints_ptrs = section_objs(info, "__tracepoints_ptrs",
2754 sizeof(*mod->tracepoints_ptrs), 2760 sizeof(*mod->tracepoints_ptrs),
2755 &mod->num_tracepoints); 2761 &mod->num_tracepoints);
2756 #endif 2762 #endif
2757 #ifdef HAVE_JUMP_LABEL 2763 #ifdef HAVE_JUMP_LABEL
2758 mod->jump_entries = section_objs(info, "__jump_table", 2764 mod->jump_entries = section_objs(info, "__jump_table",
2759 sizeof(*mod->jump_entries), 2765 sizeof(*mod->jump_entries),
2760 &mod->num_jump_entries); 2766 &mod->num_jump_entries);
2761 #endif 2767 #endif
2762 #ifdef CONFIG_EVENT_TRACING 2768 #ifdef CONFIG_EVENT_TRACING
2763 mod->trace_events = section_objs(info, "_ftrace_events", 2769 mod->trace_events = section_objs(info, "_ftrace_events",
2764 sizeof(*mod->trace_events), 2770 sizeof(*mod->trace_events),
2765 &mod->num_trace_events); 2771 &mod->num_trace_events);
2766 /* 2772 /*
2767 * This section contains pointers to allocated objects in the trace 2773 * This section contains pointers to allocated objects in the trace
2768 * code and not scanning it leads to false positives. 2774 * code and not scanning it leads to false positives.
2769 */ 2775 */
2770 kmemleak_scan_area(mod->trace_events, sizeof(*mod->trace_events) * 2776 kmemleak_scan_area(mod->trace_events, sizeof(*mod->trace_events) *
2771 mod->num_trace_events, GFP_KERNEL); 2777 mod->num_trace_events, GFP_KERNEL);
2772 #endif 2778 #endif
2773 #ifdef CONFIG_TRACING 2779 #ifdef CONFIG_TRACING
2774 mod->trace_bprintk_fmt_start = section_objs(info, "__trace_printk_fmt", 2780 mod->trace_bprintk_fmt_start = section_objs(info, "__trace_printk_fmt",
2775 sizeof(*mod->trace_bprintk_fmt_start), 2781 sizeof(*mod->trace_bprintk_fmt_start),
2776 &mod->num_trace_bprintk_fmt); 2782 &mod->num_trace_bprintk_fmt);
2777 /* 2783 /*
2778 * This section contains pointers to allocated objects in the trace 2784 * This section contains pointers to allocated objects in the trace
2779 * code and not scanning it leads to false positives. 2785 * code and not scanning it leads to false positives.
2780 */ 2786 */
2781 kmemleak_scan_area(mod->trace_bprintk_fmt_start, 2787 kmemleak_scan_area(mod->trace_bprintk_fmt_start,
2782 sizeof(*mod->trace_bprintk_fmt_start) * 2788 sizeof(*mod->trace_bprintk_fmt_start) *
2783 mod->num_trace_bprintk_fmt, GFP_KERNEL); 2789 mod->num_trace_bprintk_fmt, GFP_KERNEL);
2784 #endif 2790 #endif
2785 #ifdef CONFIG_FTRACE_MCOUNT_RECORD 2791 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
2786 /* sechdrs[0].sh_size is always zero */ 2792 /* sechdrs[0].sh_size is always zero */
2787 mod->ftrace_callsites = section_objs(info, "__mcount_loc", 2793 mod->ftrace_callsites = section_objs(info, "__mcount_loc",
2788 sizeof(*mod->ftrace_callsites), 2794 sizeof(*mod->ftrace_callsites),
2789 &mod->num_ftrace_callsites); 2795 &mod->num_ftrace_callsites);
2790 #endif 2796 #endif
2791 2797
2792 mod->extable = section_objs(info, "__ex_table", 2798 mod->extable = section_objs(info, "__ex_table",
2793 sizeof(*mod->extable), &mod->num_exentries); 2799 sizeof(*mod->extable), &mod->num_exentries);
2794 2800
2795 if (section_addr(info, "__obsparm")) 2801 if (section_addr(info, "__obsparm"))
2796 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n", 2802 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n",
2797 mod->name); 2803 mod->name);
2798 2804
2799 info->debug = section_objs(info, "__verbose", 2805 info->debug = section_objs(info, "__verbose",
2800 sizeof(*info->debug), &info->num_debug); 2806 sizeof(*info->debug), &info->num_debug);
2801 } 2807 }
2802 2808
2803 static int move_module(struct module *mod, struct load_info *info) 2809 static int move_module(struct module *mod, struct load_info *info)
2804 { 2810 {
2805 int i; 2811 int i;
2806 void *ptr; 2812 void *ptr;
2807 2813
2808 /* Do the allocs. */ 2814 /* Do the allocs. */
2809 ptr = module_alloc_update_bounds(mod->core_size); 2815 ptr = module_alloc_update_bounds(mod->core_size);
2810 /* 2816 /*
2811 * The pointer to this block is stored in the module structure 2817 * The pointer to this block is stored in the module structure
2812 * which is inside the block. Just mark it as not being a 2818 * which is inside the block. Just mark it as not being a
2813 * leak. 2819 * leak.
2814 */ 2820 */
2815 kmemleak_not_leak(ptr); 2821 kmemleak_not_leak(ptr);
2816 if (!ptr) 2822 if (!ptr)
2817 return -ENOMEM; 2823 return -ENOMEM;
2818 2824
2819 memset(ptr, 0, mod->core_size); 2825 memset(ptr, 0, mod->core_size);
2820 mod->module_core = ptr; 2826 mod->module_core = ptr;
2821 2827
2822 if (mod->init_size) { 2828 if (mod->init_size) {
2823 ptr = module_alloc_update_bounds(mod->init_size); 2829 ptr = module_alloc_update_bounds(mod->init_size);
2824 /* 2830 /*
2825 * The pointer to this block is stored in the module structure 2831 * The pointer to this block is stored in the module structure
2826 * which is inside the block. This block doesn't need to be 2832 * which is inside the block. This block doesn't need to be
2827 * scanned as it contains data and code that will be freed 2833 * scanned as it contains data and code that will be freed
2828 * after the module is initialized. 2834 * after the module is initialized.
2829 */ 2835 */
2830 kmemleak_ignore(ptr); 2836 kmemleak_ignore(ptr);
2831 if (!ptr) { 2837 if (!ptr) {
2832 module_free(mod, mod->module_core); 2838 module_free(mod, mod->module_core);
2833 return -ENOMEM; 2839 return -ENOMEM;
2834 } 2840 }
2835 memset(ptr, 0, mod->init_size); 2841 memset(ptr, 0, mod->init_size);
2836 mod->module_init = ptr; 2842 mod->module_init = ptr;
2837 } else 2843 } else
2838 mod->module_init = NULL; 2844 mod->module_init = NULL;
2839 2845
2840 /* Transfer each section which specifies SHF_ALLOC */ 2846 /* Transfer each section which specifies SHF_ALLOC */
2841 pr_debug("final section addresses:\n"); 2847 pr_debug("final section addresses:\n");
2842 for (i = 0; i < info->hdr->e_shnum; i++) { 2848 for (i = 0; i < info->hdr->e_shnum; i++) {
2843 void *dest; 2849 void *dest;
2844 Elf_Shdr *shdr = &info->sechdrs[i]; 2850 Elf_Shdr *shdr = &info->sechdrs[i];
2845 2851
2846 if (!(shdr->sh_flags & SHF_ALLOC)) 2852 if (!(shdr->sh_flags & SHF_ALLOC))
2847 continue; 2853 continue;
2848 2854
2849 if (shdr->sh_entsize & INIT_OFFSET_MASK) 2855 if (shdr->sh_entsize & INIT_OFFSET_MASK)
2850 dest = mod->module_init 2856 dest = mod->module_init
2851 + (shdr->sh_entsize & ~INIT_OFFSET_MASK); 2857 + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
2852 else 2858 else
2853 dest = mod->module_core + shdr->sh_entsize; 2859 dest = mod->module_core + shdr->sh_entsize;
2854 2860
2855 if (shdr->sh_type != SHT_NOBITS) 2861 if (shdr->sh_type != SHT_NOBITS)
2856 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size); 2862 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
2857 /* Update sh_addr to point to copy in image. */ 2863 /* Update sh_addr to point to copy in image. */
2858 shdr->sh_addr = (unsigned long)dest; 2864 shdr->sh_addr = (unsigned long)dest;
2859 pr_debug("\t0x%lx %s\n", 2865 pr_debug("\t0x%lx %s\n",
2860 (long)shdr->sh_addr, info->secstrings + shdr->sh_name); 2866 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
2861 } 2867 }
2862 2868
2863 return 0; 2869 return 0;
2864 } 2870 }
2865 2871
2866 static int check_module_license_and_versions(struct module *mod) 2872 static int check_module_license_and_versions(struct module *mod)
2867 { 2873 {
2868 /* 2874 /*
2869 * ndiswrapper is under GPL by itself, but loads proprietary modules. 2875 * ndiswrapper is under GPL by itself, but loads proprietary modules.
2870 * Don't use add_taint_module(), as it would prevent ndiswrapper from 2876 * Don't use add_taint_module(), as it would prevent ndiswrapper from
2871 * using GPL-only symbols it needs. 2877 * using GPL-only symbols it needs.
2872 */ 2878 */
2873 if (strcmp(mod->name, "ndiswrapper") == 0) 2879 if (strcmp(mod->name, "ndiswrapper") == 0)
2874 add_taint(TAINT_PROPRIETARY_MODULE, LOCKDEP_NOW_UNRELIABLE); 2880 add_taint(TAINT_PROPRIETARY_MODULE, LOCKDEP_NOW_UNRELIABLE);
2875 2881
2876 /* driverloader was caught wrongly pretending to be under GPL */ 2882 /* driverloader was caught wrongly pretending to be under GPL */
2877 if (strcmp(mod->name, "driverloader") == 0) 2883 if (strcmp(mod->name, "driverloader") == 0)
2878 add_taint_module(mod, TAINT_PROPRIETARY_MODULE, 2884 add_taint_module(mod, TAINT_PROPRIETARY_MODULE,
2879 LOCKDEP_NOW_UNRELIABLE); 2885 LOCKDEP_NOW_UNRELIABLE);
2880 2886
2881 /* lve claims to be GPL but upstream won't provide source */ 2887 /* lve claims to be GPL but upstream won't provide source */
2882 if (strcmp(mod->name, "lve") == 0) 2888 if (strcmp(mod->name, "lve") == 0)
2883 add_taint_module(mod, TAINT_PROPRIETARY_MODULE, 2889 add_taint_module(mod, TAINT_PROPRIETARY_MODULE,
2884 LOCKDEP_NOW_UNRELIABLE); 2890 LOCKDEP_NOW_UNRELIABLE);
2885 2891
2886 #ifdef CONFIG_MODVERSIONS 2892 #ifdef CONFIG_MODVERSIONS
2887 if ((mod->num_syms && !mod->crcs) 2893 if ((mod->num_syms && !mod->crcs)
2888 || (mod->num_gpl_syms && !mod->gpl_crcs) 2894 || (mod->num_gpl_syms && !mod->gpl_crcs)
2889 || (mod->num_gpl_future_syms && !mod->gpl_future_crcs) 2895 || (mod->num_gpl_future_syms && !mod->gpl_future_crcs)
2890 #ifdef CONFIG_UNUSED_SYMBOLS 2896 #ifdef CONFIG_UNUSED_SYMBOLS
2891 || (mod->num_unused_syms && !mod->unused_crcs) 2897 || (mod->num_unused_syms && !mod->unused_crcs)
2892 || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs) 2898 || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs)
2893 #endif 2899 #endif
2894 ) { 2900 ) {
2895 return try_to_force_load(mod, 2901 return try_to_force_load(mod,
2896 "no versions for exported symbols"); 2902 "no versions for exported symbols");
2897 } 2903 }
2898 #endif 2904 #endif
2899 return 0; 2905 return 0;
2900 } 2906 }
2901 2907
2902 static void flush_module_icache(const struct module *mod) 2908 static void flush_module_icache(const struct module *mod)
2903 { 2909 {
2904 mm_segment_t old_fs; 2910 mm_segment_t old_fs;
2905 2911
2906 /* flush the icache in correct context */ 2912 /* flush the icache in correct context */
2907 old_fs = get_fs(); 2913 old_fs = get_fs();
2908 set_fs(KERNEL_DS); 2914 set_fs(KERNEL_DS);
2909 2915
2910 /* 2916 /*
2911 * Flush the instruction cache, since we've played with text. 2917 * Flush the instruction cache, since we've played with text.
2912 * Do it before processing of module parameters, so the module 2918 * Do it before processing of module parameters, so the module
2913 * can provide parameter accessor functions of its own. 2919 * can provide parameter accessor functions of its own.
2914 */ 2920 */
2915 if (mod->module_init) 2921 if (mod->module_init)
2916 flush_icache_range((unsigned long)mod->module_init, 2922 flush_icache_range((unsigned long)mod->module_init,
2917 (unsigned long)mod->module_init 2923 (unsigned long)mod->module_init
2918 + mod->init_size); 2924 + mod->init_size);
2919 flush_icache_range((unsigned long)mod->module_core, 2925 flush_icache_range((unsigned long)mod->module_core,
2920 (unsigned long)mod->module_core + mod->core_size); 2926 (unsigned long)mod->module_core + mod->core_size);
2921 2927
2922 set_fs(old_fs); 2928 set_fs(old_fs);
2923 } 2929 }
2924 2930
2925 int __weak module_frob_arch_sections(Elf_Ehdr *hdr, 2931 int __weak module_frob_arch_sections(Elf_Ehdr *hdr,
2926 Elf_Shdr *sechdrs, 2932 Elf_Shdr *sechdrs,
2927 char *secstrings, 2933 char *secstrings,
2928 struct module *mod) 2934 struct module *mod)
2929 { 2935 {
2930 return 0; 2936 return 0;
2931 } 2937 }
2932 2938
2933 static struct module *layout_and_allocate(struct load_info *info, int flags) 2939 static struct module *layout_and_allocate(struct load_info *info, int flags)
2934 { 2940 {
2935 /* Module within temporary copy. */ 2941 /* Module within temporary copy. */
2936 struct module *mod; 2942 struct module *mod;
2937 Elf_Shdr *pcpusec; 2943 Elf_Shdr *pcpusec;
2938 int err; 2944 int err;
2939 2945
2940 mod = setup_load_info(info, flags); 2946 mod = setup_load_info(info, flags);
2941 if (IS_ERR(mod)) 2947 if (IS_ERR(mod))
2942 return mod; 2948 return mod;
2943 2949
2944 err = check_modinfo(mod, info, flags); 2950 err = check_modinfo(mod, info, flags);
2945 if (err) 2951 if (err)
2946 return ERR_PTR(err); 2952 return ERR_PTR(err);
2947 2953
2948 /* Allow arches to frob section contents and sizes. */ 2954 /* Allow arches to frob section contents and sizes. */
2949 err = module_frob_arch_sections(info->hdr, info->sechdrs, 2955 err = module_frob_arch_sections(info->hdr, info->sechdrs,
2950 info->secstrings, mod); 2956 info->secstrings, mod);
2951 if (err < 0) 2957 if (err < 0)
2952 goto out; 2958 goto out;
2953 2959
2954 pcpusec = &info->sechdrs[info->index.pcpu]; 2960 pcpusec = &info->sechdrs[info->index.pcpu];
2955 if (pcpusec->sh_size) { 2961 if (pcpusec->sh_size) {
2956 /* We have a special allocation for this section. */ 2962 /* We have a special allocation for this section. */
2957 err = percpu_modalloc(mod, 2963 err = percpu_modalloc(mod,
2958 pcpusec->sh_size, pcpusec->sh_addralign); 2964 pcpusec->sh_size, pcpusec->sh_addralign);
2959 if (err) 2965 if (err)
2960 goto out; 2966 goto out;
2961 pcpusec->sh_flags &= ~(unsigned long)SHF_ALLOC; 2967 pcpusec->sh_flags &= ~(unsigned long)SHF_ALLOC;
2962 } 2968 }
2963 2969
2964 /* Determine total sizes, and put offsets in sh_entsize. For now 2970 /* Determine total sizes, and put offsets in sh_entsize. For now
2965 this is done generically; there doesn't appear to be any 2971 this is done generically; there doesn't appear to be any
2966 special cases for the architectures. */ 2972 special cases for the architectures. */
2967 layout_sections(mod, info); 2973 layout_sections(mod, info);
2968 layout_symtab(mod, info); 2974 layout_symtab(mod, info);
2969 2975
2970 /* Allocate and move to the final place */ 2976 /* Allocate and move to the final place */
2971 err = move_module(mod, info); 2977 err = move_module(mod, info);
2972 if (err) 2978 if (err)
2973 goto free_percpu; 2979 goto free_percpu;
2974 2980
2975 /* Module has been copied to its final place now: return it. */ 2981 /* Module has been copied to its final place now: return it. */
2976 mod = (void *)info->sechdrs[info->index.mod].sh_addr; 2982 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
2977 kmemleak_load_module(mod, info); 2983 kmemleak_load_module(mod, info);
2978 return mod; 2984 return mod;
2979 2985
2980 free_percpu: 2986 free_percpu:
2981 percpu_modfree(mod); 2987 percpu_modfree(mod);
2982 out: 2988 out:
2983 return ERR_PTR(err); 2989 return ERR_PTR(err);
2984 } 2990 }
2985 2991
2986 /* mod is no longer valid after this! */ 2992 /* mod is no longer valid after this! */
2987 static void module_deallocate(struct module *mod, struct load_info *info) 2993 static void module_deallocate(struct module *mod, struct load_info *info)
2988 { 2994 {
2989 percpu_modfree(mod); 2995 percpu_modfree(mod);
2990 module_free(mod, mod->module_init); 2996 module_free(mod, mod->module_init);
2991 module_free(mod, mod->module_core); 2997 module_free(mod, mod->module_core);
2992 } 2998 }
2993 2999
2994 int __weak module_finalize(const Elf_Ehdr *hdr, 3000 int __weak module_finalize(const Elf_Ehdr *hdr,
2995 const Elf_Shdr *sechdrs, 3001 const Elf_Shdr *sechdrs,
2996 struct module *me) 3002 struct module *me)
2997 { 3003 {
2998 return 0; 3004 return 0;
2999 } 3005 }
3000 3006
3001 static int post_relocation(struct module *mod, const struct load_info *info) 3007 static int post_relocation(struct module *mod, const struct load_info *info)
3002 { 3008 {
3003 /* Sort exception table now relocations are done. */ 3009 /* Sort exception table now relocations are done. */
3004 sort_extable(mod->extable, mod->extable + mod->num_exentries); 3010 sort_extable(mod->extable, mod->extable + mod->num_exentries);
3005 3011
3006 /* Copy relocated percpu area over. */ 3012 /* Copy relocated percpu area over. */
3007 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr, 3013 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
3008 info->sechdrs[info->index.pcpu].sh_size); 3014 info->sechdrs[info->index.pcpu].sh_size);
3009 3015
3010 /* Setup kallsyms-specific fields. */ 3016 /* Setup kallsyms-specific fields. */
3011 add_kallsyms(mod, info); 3017 add_kallsyms(mod, info);
3012 3018
3013 /* Arch-specific module finalizing. */ 3019 /* Arch-specific module finalizing. */
3014 return module_finalize(info->hdr, info->sechdrs, mod); 3020 return module_finalize(info->hdr, info->sechdrs, mod);
3015 } 3021 }
3016 3022
3017 /* Is this module of this name done loading? No locks held. */ 3023 /* Is this module of this name done loading? No locks held. */
3018 static bool finished_loading(const char *name) 3024 static bool finished_loading(const char *name)
3019 { 3025 {
3020 struct module *mod; 3026 struct module *mod;
3021 bool ret; 3027 bool ret;
3022 3028
3023 mutex_lock(&module_mutex); 3029 mutex_lock(&module_mutex);
3024 mod = find_module_all(name, true); 3030 mod = find_module_all(name, true);
3025 ret = !mod || mod->state == MODULE_STATE_LIVE 3031 ret = !mod || mod->state == MODULE_STATE_LIVE
3026 || mod->state == MODULE_STATE_GOING; 3032 || mod->state == MODULE_STATE_GOING;
3027 mutex_unlock(&module_mutex); 3033 mutex_unlock(&module_mutex);
3028 3034
3029 return ret; 3035 return ret;
3030 } 3036 }
3031 3037
3032 /* Call module constructors. */ 3038 /* Call module constructors. */
3033 static void do_mod_ctors(struct module *mod) 3039 static void do_mod_ctors(struct module *mod)
3034 { 3040 {
3035 #ifdef CONFIG_CONSTRUCTORS 3041 #ifdef CONFIG_CONSTRUCTORS
3036 unsigned long i; 3042 unsigned long i;
3037 3043
3038 for (i = 0; i < mod->num_ctors; i++) 3044 for (i = 0; i < mod->num_ctors; i++)
3039 mod->ctors[i](); 3045 mod->ctors[i]();
3040 #endif 3046 #endif
3041 } 3047 }
3042 3048
3043 /* This is where the real work happens */ 3049 /* This is where the real work happens */
3044 static int do_init_module(struct module *mod) 3050 static int do_init_module(struct module *mod)
3045 { 3051 {
3046 int ret = 0; 3052 int ret = 0;
3047 3053
3048 /* 3054 /*
3049 * We want to find out whether @mod uses async during init. Clear 3055 * We want to find out whether @mod uses async during init. Clear
3050 * PF_USED_ASYNC. async_schedule*() will set it. 3056 * PF_USED_ASYNC. async_schedule*() will set it.
3051 */ 3057 */
3052 current->flags &= ~PF_USED_ASYNC; 3058 current->flags &= ~PF_USED_ASYNC;
3053 3059
3054 blocking_notifier_call_chain(&module_notify_list, 3060 blocking_notifier_call_chain(&module_notify_list,
3055 MODULE_STATE_COMING, mod); 3061 MODULE_STATE_COMING, mod);
3056 3062
3057 /* Set RO and NX regions for core */ 3063 /* Set RO and NX regions for core */
3058 set_section_ro_nx(mod->module_core, 3064 set_section_ro_nx(mod->module_core,
3059 mod->core_text_size, 3065 mod->core_text_size,
3060 mod->core_ro_size, 3066 mod->core_ro_size,
3061 mod->core_size); 3067 mod->core_size);
3062 3068
3063 /* Set RO and NX regions for init */ 3069 /* Set RO and NX regions for init */
3064 set_section_ro_nx(mod->module_init, 3070 set_section_ro_nx(mod->module_init,
3065 mod->init_text_size, 3071 mod->init_text_size,
3066 mod->init_ro_size, 3072 mod->init_ro_size,
3067 mod->init_size); 3073 mod->init_size);
3068 3074
3069 do_mod_ctors(mod); 3075 do_mod_ctors(mod);
3070 /* Start the module */ 3076 /* Start the module */
3071 if (mod->init != NULL) 3077 if (mod->init != NULL)
3072 ret = do_one_initcall(mod->init); 3078 ret = do_one_initcall(mod->init);
3073 if (ret < 0) { 3079 if (ret < 0) {
3074 /* Init routine failed: abort. Try to protect us from 3080 /* Init routine failed: abort. Try to protect us from
3075 buggy refcounters. */ 3081 buggy refcounters. */
3076 mod->state = MODULE_STATE_GOING; 3082 mod->state = MODULE_STATE_GOING;
3077 synchronize_sched(); 3083 synchronize_sched();
3078 module_put(mod); 3084 module_put(mod);
3079 blocking_notifier_call_chain(&module_notify_list, 3085 blocking_notifier_call_chain(&module_notify_list,
3080 MODULE_STATE_GOING, mod); 3086 MODULE_STATE_GOING, mod);
3081 free_module(mod); 3087 free_module(mod);
3082 wake_up_all(&module_wq); 3088 wake_up_all(&module_wq);
3083 return ret; 3089 return ret;
3084 } 3090 }
3085 if (ret > 0) { 3091 if (ret > 0) {
3086 printk(KERN_WARNING 3092 printk(KERN_WARNING
3087 "%s: '%s'->init suspiciously returned %d, it should follow 0/-E convention\n" 3093 "%s: '%s'->init suspiciously returned %d, it should follow 0/-E convention\n"
3088 "%s: loading module anyway...\n", 3094 "%s: loading module anyway...\n",
3089 __func__, mod->name, ret, 3095 __func__, mod->name, ret,
3090 __func__); 3096 __func__);
3091 dump_stack(); 3097 dump_stack();
3092 } 3098 }
3093 3099
3094 /* Now it's a first class citizen! */ 3100 /* Now it's a first class citizen! */
3095 mod->state = MODULE_STATE_LIVE; 3101 mod->state = MODULE_STATE_LIVE;
3096 blocking_notifier_call_chain(&module_notify_list, 3102 blocking_notifier_call_chain(&module_notify_list,
3097 MODULE_STATE_LIVE, mod); 3103 MODULE_STATE_LIVE, mod);
3098 3104
3099 /* 3105 /*
3100 * We need to finish all async code before the module init sequence 3106 * We need to finish all async code before the module init sequence
3101 * is done. This has potential to deadlock. For example, a newly 3107 * is done. This has potential to deadlock. For example, a newly
3102 * detected block device can trigger request_module() of the 3108 * detected block device can trigger request_module() of the
3103 * default iosched from async probing task. Once userland helper 3109 * default iosched from async probing task. Once userland helper
3104 * reaches here, async_synchronize_full() will wait on the async 3110 * reaches here, async_synchronize_full() will wait on the async
3105 * task waiting on request_module() and deadlock. 3111 * task waiting on request_module() and deadlock.
3106 * 3112 *
3107 * This deadlock is avoided by perfomring async_synchronize_full() 3113 * This deadlock is avoided by perfomring async_synchronize_full()
3108 * iff module init queued any async jobs. This isn't a full 3114 * iff module init queued any async jobs. This isn't a full
3109 * solution as it will deadlock the same if module loading from 3115 * solution as it will deadlock the same if module loading from
3110 * async jobs nests more than once; however, due to the various 3116 * async jobs nests more than once; however, due to the various
3111 * constraints, this hack seems to be the best option for now. 3117 * constraints, this hack seems to be the best option for now.
3112 * Please refer to the following thread for details. 3118 * Please refer to the following thread for details.
3113 * 3119 *
3114 * http://thread.gmane.org/gmane.linux.kernel/1420814 3120 * http://thread.gmane.org/gmane.linux.kernel/1420814
3115 */ 3121 */
3116 if (current->flags & PF_USED_ASYNC) 3122 if (current->flags & PF_USED_ASYNC)
3117 async_synchronize_full(); 3123 async_synchronize_full();
3118 3124
3119 mutex_lock(&module_mutex); 3125 mutex_lock(&module_mutex);
3120 /* Drop initial reference. */ 3126 /* Drop initial reference. */
3121 module_put(mod); 3127 module_put(mod);
3122 trim_init_extable(mod); 3128 trim_init_extable(mod);
3123 #ifdef CONFIG_KALLSYMS 3129 #ifdef CONFIG_KALLSYMS
3124 mod->num_symtab = mod->core_num_syms; 3130 mod->num_symtab = mod->core_num_syms;
3125 mod->symtab = mod->core_symtab; 3131 mod->symtab = mod->core_symtab;
3126 mod->strtab = mod->core_strtab; 3132 mod->strtab = mod->core_strtab;
3127 #endif 3133 #endif
3128 unset_module_init_ro_nx(mod); 3134 unset_module_init_ro_nx(mod);
3129 module_free(mod, mod->module_init); 3135 module_free(mod, mod->module_init);
3130 mod->module_init = NULL; 3136 mod->module_init = NULL;
3131 mod->init_size = 0; 3137 mod->init_size = 0;
3132 mod->init_ro_size = 0; 3138 mod->init_ro_size = 0;
3133 mod->init_text_size = 0; 3139 mod->init_text_size = 0;
3134 mutex_unlock(&module_mutex); 3140 mutex_unlock(&module_mutex);
3135 wake_up_all(&module_wq); 3141 wake_up_all(&module_wq);
3136 3142
3137 return 0; 3143 return 0;
3138 } 3144 }
3139 3145
3140 static int may_init_module(void) 3146 static int may_init_module(void)
3141 { 3147 {
3142 if (!capable(CAP_SYS_MODULE) || modules_disabled) 3148 if (!capable(CAP_SYS_MODULE) || modules_disabled)
3143 return -EPERM; 3149 return -EPERM;
3144 3150
3145 return 0; 3151 return 0;
3146 } 3152 }
3147 3153
3148 /* 3154 /*
3149 * We try to place it in the list now to make sure it's unique before 3155 * We try to place it in the list now to make sure it's unique before
3150 * we dedicate too many resources. In particular, temporary percpu 3156 * we dedicate too many resources. In particular, temporary percpu
3151 * memory exhaustion. 3157 * memory exhaustion.
3152 */ 3158 */
3153 static int add_unformed_module(struct module *mod) 3159 static int add_unformed_module(struct module *mod)
3154 { 3160 {
3155 int err; 3161 int err;
3156 struct module *old; 3162 struct module *old;
3157 3163
3158 mod->state = MODULE_STATE_UNFORMED; 3164 mod->state = MODULE_STATE_UNFORMED;
3159 3165
3160 again: 3166 again:
3161 mutex_lock(&module_mutex); 3167 mutex_lock(&module_mutex);
3162 if ((old = find_module_all(mod->name, true)) != NULL) { 3168 if ((old = find_module_all(mod->name, true)) != NULL) {
3163 if (old->state == MODULE_STATE_COMING 3169 if (old->state == MODULE_STATE_COMING
3164 || old->state == MODULE_STATE_UNFORMED) { 3170 || old->state == MODULE_STATE_UNFORMED) {
3165 /* Wait in case it fails to load. */ 3171 /* Wait in case it fails to load. */
3166 mutex_unlock(&module_mutex); 3172 mutex_unlock(&module_mutex);
3167 err = wait_event_interruptible(module_wq, 3173 err = wait_event_interruptible(module_wq,
3168 finished_loading(mod->name)); 3174 finished_loading(mod->name));
3169 if (err) 3175 if (err)
3170 goto out_unlocked; 3176 goto out_unlocked;
3171 goto again; 3177 goto again;
3172 } 3178 }
3173 err = -EEXIST; 3179 err = -EEXIST;
3174 goto out; 3180 goto out;
3175 } 3181 }
3176 list_add_rcu(&mod->list, &modules); 3182 list_add_rcu(&mod->list, &modules);
3177 err = 0; 3183 err = 0;
3178 3184
3179 out: 3185 out:
3180 mutex_unlock(&module_mutex); 3186 mutex_unlock(&module_mutex);
3181 out_unlocked: 3187 out_unlocked:
3182 return err; 3188 return err;
3183 } 3189 }
3184 3190
3185 static int complete_formation(struct module *mod, struct load_info *info) 3191 static int complete_formation(struct module *mod, struct load_info *info)
3186 { 3192 {
3187 int err; 3193 int err;
3188 3194
3189 mutex_lock(&module_mutex); 3195 mutex_lock(&module_mutex);
3190 3196
3191 /* Find duplicate symbols (must be called under lock). */ 3197 /* Find duplicate symbols (must be called under lock). */
3192 err = verify_export_symbols(mod); 3198 err = verify_export_symbols(mod);
3193 if (err < 0) 3199 if (err < 0)
3194 goto out; 3200 goto out;
3195 3201
3196 /* This relies on module_mutex for list integrity. */ 3202 /* This relies on module_mutex for list integrity. */
3197 module_bug_finalize(info->hdr, info->sechdrs, mod); 3203 module_bug_finalize(info->hdr, info->sechdrs, mod);
3198 3204
3199 /* Mark state as coming so strong_try_module_get() ignores us, 3205 /* Mark state as coming so strong_try_module_get() ignores us,
3200 * but kallsyms etc. can see us. */ 3206 * but kallsyms etc. can see us. */
3201 mod->state = MODULE_STATE_COMING; 3207 mod->state = MODULE_STATE_COMING;
3202 3208
3203 out: 3209 out:
3204 mutex_unlock(&module_mutex); 3210 mutex_unlock(&module_mutex);
3205 return err; 3211 return err;
3206 } 3212 }
3207 3213
3208 /* Allocate and load the module: note that size of section 0 is always 3214 /* Allocate and load the module: note that size of section 0 is always
3209 zero, and we rely on this for optional sections. */ 3215 zero, and we rely on this for optional sections. */
3210 static int load_module(struct load_info *info, const char __user *uargs, 3216 static int load_module(struct load_info *info, const char __user *uargs,
3211 int flags) 3217 int flags)
3212 { 3218 {
3213 struct module *mod; 3219 struct module *mod;
3214 long err; 3220 long err;
3215 3221
3216 err = module_sig_check(info); 3222 err = module_sig_check(info);
3217 if (err) 3223 if (err)
3218 goto free_copy; 3224 goto free_copy;
3219 3225
3220 err = elf_header_check(info); 3226 err = elf_header_check(info);
3221 if (err) 3227 if (err)
3222 goto free_copy; 3228 goto free_copy;
3223 3229
3224 /* Figure out module layout, and allocate all the memory. */ 3230 /* Figure out module layout, and allocate all the memory. */
3225 mod = layout_and_allocate(info, flags); 3231 mod = layout_and_allocate(info, flags);
3226 if (IS_ERR(mod)) { 3232 if (IS_ERR(mod)) {
3227 err = PTR_ERR(mod); 3233 err = PTR_ERR(mod);
3228 goto free_copy; 3234 goto free_copy;
3229 } 3235 }
3230 3236
3231 /* Reserve our place in the list. */ 3237 /* Reserve our place in the list. */
3232 err = add_unformed_module(mod); 3238 err = add_unformed_module(mod);
3233 if (err) 3239 if (err)
3234 goto free_module; 3240 goto free_module;
3235 3241
3236 #ifdef CONFIG_MODULE_SIG 3242 #ifdef CONFIG_MODULE_SIG
3237 mod->sig_ok = info->sig_ok; 3243 mod->sig_ok = info->sig_ok;
3238 if (!mod->sig_ok) { 3244 if (!mod->sig_ok) {
3239 printk_once(KERN_NOTICE 3245 printk_once(KERN_NOTICE
3240 "%s: module verification failed: signature and/or" 3246 "%s: module verification failed: signature and/or"
3241 " required key missing - tainting kernel\n", 3247 " required key missing - tainting kernel\n",
3242 mod->name); 3248 mod->name);
3243 add_taint_module(mod, TAINT_FORCED_MODULE, LOCKDEP_STILL_OK); 3249 add_taint_module(mod, TAINT_FORCED_MODULE, LOCKDEP_STILL_OK);
3244 } 3250 }
3245 #endif 3251 #endif
3246 3252
3247 /* Now module is in final location, initialize linked lists, etc. */ 3253 /* Now module is in final location, initialize linked lists, etc. */
3248 err = module_unload_init(mod); 3254 err = module_unload_init(mod);
3249 if (err) 3255 if (err)
3250 goto unlink_mod; 3256 goto unlink_mod;
3251 3257
3252 /* Now we've got everything in the final locations, we can 3258 /* Now we've got everything in the final locations, we can
3253 * find optional sections. */ 3259 * find optional sections. */
3254 find_module_sections(mod, info); 3260 find_module_sections(mod, info);
3255 3261
3256 err = check_module_license_and_versions(mod); 3262 err = check_module_license_and_versions(mod);
3257 if (err) 3263 if (err)
3258 goto free_unload; 3264 goto free_unload;
3259 3265
3260 /* Set up MODINFO_ATTR fields */ 3266 /* Set up MODINFO_ATTR fields */
3261 setup_modinfo(mod, info); 3267 setup_modinfo(mod, info);
3262 3268
3263 /* Fix up syms, so that st_value is a pointer to location. */ 3269 /* Fix up syms, so that st_value is a pointer to location. */
3264 err = simplify_symbols(mod, info); 3270 err = simplify_symbols(mod, info);
3265 if (err < 0) 3271 if (err < 0)
3266 goto free_modinfo; 3272 goto free_modinfo;
3267 3273
3268 err = apply_relocations(mod, info); 3274 err = apply_relocations(mod, info);
3269 if (err < 0) 3275 if (err < 0)
3270 goto free_modinfo; 3276 goto free_modinfo;
3271 3277
3272 err = post_relocation(mod, info); 3278 err = post_relocation(mod, info);
3273 if (err < 0) 3279 if (err < 0)
3274 goto free_modinfo; 3280 goto free_modinfo;
3275 3281
3276 flush_module_icache(mod); 3282 flush_module_icache(mod);
3277 3283
3278 /* Now copy in args */ 3284 /* Now copy in args */
3279 mod->args = strndup_user(uargs, ~0UL >> 1); 3285 mod->args = strndup_user(uargs, ~0UL >> 1);
3280 if (IS_ERR(mod->args)) { 3286 if (IS_ERR(mod->args)) {
3281 err = PTR_ERR(mod->args); 3287 err = PTR_ERR(mod->args);
3282 goto free_arch_cleanup; 3288 goto free_arch_cleanup;
3283 } 3289 }
3284 3290
3285 dynamic_debug_setup(info->debug, info->num_debug); 3291 dynamic_debug_setup(info->debug, info->num_debug);
3286 3292
3287 /* Finally it's fully formed, ready to start executing. */ 3293 /* Finally it's fully formed, ready to start executing. */
3288 err = complete_formation(mod, info); 3294 err = complete_formation(mod, info);
3289 if (err) 3295 if (err)
3290 goto ddebug_cleanup; 3296 goto ddebug_cleanup;
3291 3297
3292 /* Module is ready to execute: parsing args may do that. */ 3298 /* Module is ready to execute: parsing args may do that. */
3293 err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, 3299 err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp,
3294 -32768, 32767, &ddebug_dyndbg_module_param_cb); 3300 -32768, 32767, &ddebug_dyndbg_module_param_cb);
3295 if (err < 0) 3301 if (err < 0)
3296 goto bug_cleanup; 3302 goto bug_cleanup;
3297 3303
3298 /* Link in to syfs. */ 3304 /* Link in to syfs. */
3299 err = mod_sysfs_setup(mod, info, mod->kp, mod->num_kp); 3305 err = mod_sysfs_setup(mod, info, mod->kp, mod->num_kp);
3300 if (err < 0) 3306 if (err < 0)
3301 goto bug_cleanup; 3307 goto bug_cleanup;
3302 3308
3303 /* Get rid of temporary copy. */ 3309 /* Get rid of temporary copy. */
3304 free_copy(info); 3310 free_copy(info);
3305 3311
3306 /* Done! */ 3312 /* Done! */
3307 trace_module_load(mod); 3313 trace_module_load(mod);
3308 3314
3309 return do_init_module(mod); 3315 return do_init_module(mod);
3310 3316
3311 bug_cleanup: 3317 bug_cleanup:
3312 /* module_bug_cleanup needs module_mutex protection */ 3318 /* module_bug_cleanup needs module_mutex protection */
3313 mutex_lock(&module_mutex); 3319 mutex_lock(&module_mutex);
3314 module_bug_cleanup(mod); 3320 module_bug_cleanup(mod);
3315 mutex_unlock(&module_mutex); 3321 mutex_unlock(&module_mutex);
3316 ddebug_cleanup: 3322 ddebug_cleanup:
3317 dynamic_debug_remove(info->debug); 3323 dynamic_debug_remove(info->debug);
3318 synchronize_sched(); 3324 synchronize_sched();
3319 kfree(mod->args); 3325 kfree(mod->args);
3320 free_arch_cleanup: 3326 free_arch_cleanup:
3321 module_arch_cleanup(mod); 3327 module_arch_cleanup(mod);
3322 free_modinfo: 3328 free_modinfo:
3323 free_modinfo(mod); 3329 free_modinfo(mod);
3324 free_unload: 3330 free_unload:
3325 module_unload_free(mod); 3331 module_unload_free(mod);
3326 unlink_mod: 3332 unlink_mod:
3327 mutex_lock(&module_mutex); 3333 mutex_lock(&module_mutex);
3328 /* Unlink carefully: kallsyms could be walking list. */ 3334 /* Unlink carefully: kallsyms could be walking list. */
3329 list_del_rcu(&mod->list); 3335 list_del_rcu(&mod->list);
3330 wake_up_all(&module_wq); 3336 wake_up_all(&module_wq);
3331 mutex_unlock(&module_mutex); 3337 mutex_unlock(&module_mutex);
3332 free_module: 3338 free_module:
3333 module_deallocate(mod, info); 3339 module_deallocate(mod, info);
3334 free_copy: 3340 free_copy:
3335 free_copy(info); 3341 free_copy(info);
3336 return err; 3342 return err;
3337 } 3343 }
3338 3344
3339 SYSCALL_DEFINE3(init_module, void __user *, umod, 3345 SYSCALL_DEFINE3(init_module, void __user *, umod,
3340 unsigned long, len, const char __user *, uargs) 3346 unsigned long, len, const char __user *, uargs)
3341 { 3347 {
3342 int err; 3348 int err;
3343 struct load_info info = { }; 3349 struct load_info info = { };
3344 3350
3345 err = may_init_module(); 3351 err = may_init_module();
3346 if (err) 3352 if (err)
3347 return err; 3353 return err;
3348 3354
3349 pr_debug("init_module: umod=%p, len=%lu, uargs=%p\n", 3355 pr_debug("init_module: umod=%p, len=%lu, uargs=%p\n",
3350 umod, len, uargs); 3356 umod, len, uargs);
3351 3357
3352 err = copy_module_from_user(umod, len, &info); 3358 err = copy_module_from_user(umod, len, &info);
3353 if (err) 3359 if (err)
3354 return err; 3360 return err;
3355 3361
3356 return load_module(&info, uargs, 0); 3362 return load_module(&info, uargs, 0);
3357 } 3363 }
3358 3364
3359 SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags) 3365 SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags)
3360 { 3366 {
3361 int err; 3367 int err;
3362 struct load_info info = { }; 3368 struct load_info info = { };
3363 3369
3364 err = may_init_module(); 3370 err = may_init_module();
3365 if (err) 3371 if (err)
3366 return err; 3372 return err;
3367 3373
3368 pr_debug("finit_module: fd=%d, uargs=%p, flags=%i\n", fd, uargs, flags); 3374 pr_debug("finit_module: fd=%d, uargs=%p, flags=%i\n", fd, uargs, flags);
3369 3375
3370 if (flags & ~(MODULE_INIT_IGNORE_MODVERSIONS 3376 if (flags & ~(MODULE_INIT_IGNORE_MODVERSIONS
3371 |MODULE_INIT_IGNORE_VERMAGIC)) 3377 |MODULE_INIT_IGNORE_VERMAGIC))
3372 return -EINVAL; 3378 return -EINVAL;
3373 3379
3374 err = copy_module_from_fd(fd, &info); 3380 err = copy_module_from_fd(fd, &info);
3375 if (err) 3381 if (err)
3376 return err; 3382 return err;
3377 3383
3378 return load_module(&info, uargs, flags); 3384 return load_module(&info, uargs, flags);
3379 } 3385 }
3380 3386
3381 static inline int within(unsigned long addr, void *start, unsigned long size) 3387 static inline int within(unsigned long addr, void *start, unsigned long size)
3382 { 3388 {
3383 return ((void *)addr >= start && (void *)addr < start + size); 3389 return ((void *)addr >= start && (void *)addr < start + size);
3384 } 3390 }
3385 3391
3386 #ifdef CONFIG_KALLSYMS 3392 #ifdef CONFIG_KALLSYMS
3387 /* 3393 /*
3388 * This ignores the intensely annoying "mapping symbols" found 3394 * This ignores the intensely annoying "mapping symbols" found
3389 * in ARM ELF files: $a, $t and $d. 3395 * in ARM ELF files: $a, $t and $d.
3390 */ 3396 */
3391 static inline int is_arm_mapping_symbol(const char *str) 3397 static inline int is_arm_mapping_symbol(const char *str)
3392 { 3398 {
3393 return str[0] == '$' && strchr("atd", str[1]) 3399 return str[0] == '$' && strchr("atd", str[1])
3394 && (str[2] == '\0' || str[2] == '.'); 3400 && (str[2] == '\0' || str[2] == '.');
3395 } 3401 }
3396 3402
3397 static const char *get_ksymbol(struct module *mod, 3403 static const char *get_ksymbol(struct module *mod,
3398 unsigned long addr, 3404 unsigned long addr,
3399 unsigned long *size, 3405 unsigned long *size,
3400 unsigned long *offset) 3406 unsigned long *offset)
3401 { 3407 {
3402 unsigned int i, best = 0; 3408 unsigned int i, best = 0;
3403 unsigned long nextval; 3409 unsigned long nextval;
3404 3410
3405 /* At worse, next value is at end of module */ 3411 /* At worse, next value is at end of module */
3406 if (within_module_init(addr, mod)) 3412 if (within_module_init(addr, mod))
3407 nextval = (unsigned long)mod->module_init+mod->init_text_size; 3413 nextval = (unsigned long)mod->module_init+mod->init_text_size;
3408 else 3414 else
3409 nextval = (unsigned long)mod->module_core+mod->core_text_size; 3415 nextval = (unsigned long)mod->module_core+mod->core_text_size;
3410 3416
3411 /* Scan for closest preceding symbol, and next symbol. (ELF 3417 /* Scan for closest preceding symbol, and next symbol. (ELF
3412 starts real symbols at 1). */ 3418 starts real symbols at 1). */
3413 for (i = 1; i < mod->num_symtab; i++) { 3419 for (i = 1; i < mod->num_symtab; i++) {
3414 if (mod->symtab[i].st_shndx == SHN_UNDEF) 3420 if (mod->symtab[i].st_shndx == SHN_UNDEF)
3415 continue; 3421 continue;
3416 3422
3417 /* We ignore unnamed symbols: they're uninformative 3423 /* We ignore unnamed symbols: they're uninformative
3418 * and inserted at a whim. */ 3424 * and inserted at a whim. */
3419 if (mod->symtab[i].st_value <= addr 3425 if (mod->symtab[i].st_value <= addr
3420 && mod->symtab[i].st_value > mod->symtab[best].st_value 3426 && mod->symtab[i].st_value > mod->symtab[best].st_value
3421 && *(mod->strtab + mod->symtab[i].st_name) != '\0' 3427 && *(mod->strtab + mod->symtab[i].st_name) != '\0'
3422 && !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name)) 3428 && !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name))
3423 best = i; 3429 best = i;
3424 if (mod->symtab[i].st_value > addr 3430 if (mod->symtab[i].st_value > addr
3425 && mod->symtab[i].st_value < nextval 3431 && mod->symtab[i].st_value < nextval
3426 && *(mod->strtab + mod->symtab[i].st_name) != '\0' 3432 && *(mod->strtab + mod->symtab[i].st_name) != '\0'
3427 && !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name)) 3433 && !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name))
3428 nextval = mod->symtab[i].st_value; 3434 nextval = mod->symtab[i].st_value;
3429 } 3435 }
3430 3436
3431 if (!best) 3437 if (!best)
3432 return NULL; 3438 return NULL;
3433 3439
3434 if (size) 3440 if (size)
3435 *size = nextval - mod->symtab[best].st_value; 3441 *size = nextval - mod->symtab[best].st_value;
3436 if (offset) 3442 if (offset)
3437 *offset = addr - mod->symtab[best].st_value; 3443 *offset = addr - mod->symtab[best].st_value;
3438 return mod->strtab + mod->symtab[best].st_name; 3444 return mod->strtab + mod->symtab[best].st_name;
3439 } 3445 }
3440 3446
3441 /* For kallsyms to ask for address resolution. NULL means not found. Careful 3447 /* For kallsyms to ask for address resolution. NULL means not found. Careful
3442 * not to lock to avoid deadlock on oopses, simply disable preemption. */ 3448 * not to lock to avoid deadlock on oopses, simply disable preemption. */
3443 const char *module_address_lookup(unsigned long addr, 3449 const char *module_address_lookup(unsigned long addr,
3444 unsigned long *size, 3450 unsigned long *size,
3445 unsigned long *offset, 3451 unsigned long *offset,
3446 char **modname, 3452 char **modname,
3447 char *namebuf) 3453 char *namebuf)
3448 { 3454 {
3449 struct module *mod; 3455 struct module *mod;
3450 const char *ret = NULL; 3456 const char *ret = NULL;
3451 3457
3452 preempt_disable(); 3458 preempt_disable();
3453 list_for_each_entry_rcu(mod, &modules, list) { 3459 list_for_each_entry_rcu(mod, &modules, list) {
3454 if (mod->state == MODULE_STATE_UNFORMED) 3460 if (mod->state == MODULE_STATE_UNFORMED)
3455 continue; 3461 continue;
3456 if (within_module_init(addr, mod) || 3462 if (within_module_init(addr, mod) ||
3457 within_module_core(addr, mod)) { 3463 within_module_core(addr, mod)) {
3458 if (modname) 3464 if (modname)
3459 *modname = mod->name; 3465 *modname = mod->name;
3460 ret = get_ksymbol(mod, addr, size, offset); 3466 ret = get_ksymbol(mod, addr, size, offset);
3461 break; 3467 break;
3462 } 3468 }
3463 } 3469 }
3464 /* Make a copy in here where it's safe */ 3470 /* Make a copy in here where it's safe */
3465 if (ret) { 3471 if (ret) {
3466 strncpy(namebuf, ret, KSYM_NAME_LEN - 1); 3472 strncpy(namebuf, ret, KSYM_NAME_LEN - 1);
3467 ret = namebuf; 3473 ret = namebuf;
3468 } 3474 }
3469 preempt_enable(); 3475 preempt_enable();
3470 return ret; 3476 return ret;
3471 } 3477 }
3472 3478
3473 int lookup_module_symbol_name(unsigned long addr, char *symname) 3479 int lookup_module_symbol_name(unsigned long addr, char *symname)
3474 { 3480 {
3475 struct module *mod; 3481 struct module *mod;
3476 3482
3477 preempt_disable(); 3483 preempt_disable();
3478 list_for_each_entry_rcu(mod, &modules, list) { 3484 list_for_each_entry_rcu(mod, &modules, list) {
3479 if (mod->state == MODULE_STATE_UNFORMED) 3485 if (mod->state == MODULE_STATE_UNFORMED)
3480 continue; 3486 continue;
3481 if (within_module_init(addr, mod) || 3487 if (within_module_init(addr, mod) ||
3482 within_module_core(addr, mod)) { 3488 within_module_core(addr, mod)) {
3483 const char *sym; 3489 const char *sym;
3484 3490
3485 sym = get_ksymbol(mod, addr, NULL, NULL); 3491 sym = get_ksymbol(mod, addr, NULL, NULL);
3486 if (!sym) 3492 if (!sym)
3487 goto out; 3493 goto out;
3488 strlcpy(symname, sym, KSYM_NAME_LEN); 3494 strlcpy(symname, sym, KSYM_NAME_LEN);
3489 preempt_enable(); 3495 preempt_enable();
3490 return 0; 3496 return 0;
3491 } 3497 }
3492 } 3498 }
3493 out: 3499 out:
3494 preempt_enable(); 3500 preempt_enable();
3495 return -ERANGE; 3501 return -ERANGE;
3496 } 3502 }
3497 3503
3498 int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, 3504 int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size,
3499 unsigned long *offset, char *modname, char *name) 3505 unsigned long *offset, char *modname, char *name)
3500 { 3506 {
3501 struct module *mod; 3507 struct module *mod;
3502 3508
3503 preempt_disable(); 3509 preempt_disable();
3504 list_for_each_entry_rcu(mod, &modules, list) { 3510 list_for_each_entry_rcu(mod, &modules, list) {
3505 if (mod->state == MODULE_STATE_UNFORMED) 3511 if (mod->state == MODULE_STATE_UNFORMED)
3506 continue; 3512 continue;
3507 if (within_module_init(addr, mod) || 3513 if (within_module_init(addr, mod) ||
3508 within_module_core(addr, mod)) { 3514 within_module_core(addr, mod)) {
3509 const char *sym; 3515 const char *sym;
3510 3516
3511 sym = get_ksymbol(mod, addr, size, offset); 3517 sym = get_ksymbol(mod, addr, size, offset);
3512 if (!sym) 3518 if (!sym)
3513 goto out; 3519 goto out;
3514 if (modname) 3520 if (modname)
3515 strlcpy(modname, mod->name, MODULE_NAME_LEN); 3521 strlcpy(modname, mod->name, MODULE_NAME_LEN);
3516 if (name) 3522 if (name)
3517 strlcpy(name, sym, KSYM_NAME_LEN); 3523 strlcpy(name, sym, KSYM_NAME_LEN);
3518 preempt_enable(); 3524 preempt_enable();
3519 return 0; 3525 return 0;
3520 } 3526 }
3521 } 3527 }
3522 out: 3528 out:
3523 preempt_enable(); 3529 preempt_enable();
3524 return -ERANGE; 3530 return -ERANGE;
3525 } 3531 }
3526 3532
3527 int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, 3533 int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
3528 char *name, char *module_name, int *exported) 3534 char *name, char *module_name, int *exported)
3529 { 3535 {
3530 struct module *mod; 3536 struct module *mod;
3531 3537
3532 preempt_disable(); 3538 preempt_disable();
3533 list_for_each_entry_rcu(mod, &modules, list) { 3539 list_for_each_entry_rcu(mod, &modules, list) {
3534 if (mod->state == MODULE_STATE_UNFORMED) 3540 if (mod->state == MODULE_STATE_UNFORMED)
3535 continue; 3541 continue;
3536 if (symnum < mod->num_symtab) { 3542 if (symnum < mod->num_symtab) {
3537 *value = mod->symtab[symnum].st_value; 3543 *value = mod->symtab[symnum].st_value;
3538 *type = mod->symtab[symnum].st_info; 3544 *type = mod->symtab[symnum].st_info;
3539 strlcpy(name, mod->strtab + mod->symtab[symnum].st_name, 3545 strlcpy(name, mod->strtab + mod->symtab[symnum].st_name,
3540 KSYM_NAME_LEN); 3546 KSYM_NAME_LEN);
3541 strlcpy(module_name, mod->name, MODULE_NAME_LEN); 3547 strlcpy(module_name, mod->name, MODULE_NAME_LEN);
3542 *exported = is_exported(name, *value, mod); 3548 *exported = is_exported(name, *value, mod);
3543 preempt_enable(); 3549 preempt_enable();
3544 return 0; 3550 return 0;
3545 } 3551 }
3546 symnum -= mod->num_symtab; 3552 symnum -= mod->num_symtab;
3547 } 3553 }
3548 preempt_enable(); 3554 preempt_enable();
3549 return -ERANGE; 3555 return -ERANGE;
3550 } 3556 }
3551 3557
3552 static unsigned long mod_find_symname(struct module *mod, const char *name) 3558 static unsigned long mod_find_symname(struct module *mod, const char *name)
3553 { 3559 {
3554 unsigned int i; 3560 unsigned int i;
3555 3561
3556 for (i = 0; i < mod->num_symtab; i++) 3562 for (i = 0; i < mod->num_symtab; i++)
3557 if (strcmp(name, mod->strtab+mod->symtab[i].st_name) == 0 && 3563 if (strcmp(name, mod->strtab+mod->symtab[i].st_name) == 0 &&
3558 mod->symtab[i].st_info != 'U') 3564 mod->symtab[i].st_info != 'U')
3559 return mod->symtab[i].st_value; 3565 return mod->symtab[i].st_value;
3560 return 0; 3566 return 0;
3561 } 3567 }
3562 3568
3563 /* Look for this name: can be of form module:name. */ 3569 /* Look for this name: can be of form module:name. */
3564 unsigned long module_kallsyms_lookup_name(const char *name) 3570 unsigned long module_kallsyms_lookup_name(const char *name)
3565 { 3571 {
3566 struct module *mod; 3572 struct module *mod;
3567 char *colon; 3573 char *colon;
3568 unsigned long ret = 0; 3574 unsigned long ret = 0;
3569 3575
3570 /* Don't lock: we're in enough trouble already. */ 3576 /* Don't lock: we're in enough trouble already. */
3571 preempt_disable(); 3577 preempt_disable();
3572 if ((colon = strchr(name, ':')) != NULL) { 3578 if ((colon = strchr(name, ':')) != NULL) {
3573 *colon = '\0'; 3579 *colon = '\0';
3574 if ((mod = find_module(name)) != NULL) 3580 if ((mod = find_module(name)) != NULL)
3575 ret = mod_find_symname(mod, colon+1); 3581 ret = mod_find_symname(mod, colon+1);
3576 *colon = ':'; 3582 *colon = ':';
3577 } else { 3583 } else {
3578 list_for_each_entry_rcu(mod, &modules, list) { 3584 list_for_each_entry_rcu(mod, &modules, list) {
3579 if (mod->state == MODULE_STATE_UNFORMED) 3585 if (mod->state == MODULE_STATE_UNFORMED)
3580 continue; 3586 continue;
3581 if ((ret = mod_find_symname(mod, name)) != 0) 3587 if ((ret = mod_find_symname(mod, name)) != 0)
3582 break; 3588 break;
3583 } 3589 }
3584 } 3590 }
3585 preempt_enable(); 3591 preempt_enable();
3586 return ret; 3592 return ret;
3587 } 3593 }
3588 3594
3589 int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *, 3595 int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
3590 struct module *, unsigned long), 3596 struct module *, unsigned long),
3591 void *data) 3597 void *data)
3592 { 3598 {
3593 struct module *mod; 3599 struct module *mod;
3594 unsigned int i; 3600 unsigned int i;
3595 int ret; 3601 int ret;
3596 3602
3597 list_for_each_entry(mod, &modules, list) { 3603 list_for_each_entry(mod, &modules, list) {
3598 if (mod->state == MODULE_STATE_UNFORMED) 3604 if (mod->state == MODULE_STATE_UNFORMED)
3599 continue; 3605 continue;
3600 for (i = 0; i < mod->num_symtab; i++) { 3606 for (i = 0; i < mod->num_symtab; i++) {
3601 ret = fn(data, mod->strtab + mod->symtab[i].st_name, 3607 ret = fn(data, mod->strtab + mod->symtab[i].st_name,
3602 mod, mod->symtab[i].st_value); 3608 mod, mod->symtab[i].st_value);
3603 if (ret != 0) 3609 if (ret != 0)
3604 return ret; 3610 return ret;
3605 } 3611 }
3606 } 3612 }
3607 return 0; 3613 return 0;
3608 } 3614 }
3609 #endif /* CONFIG_KALLSYMS */ 3615 #endif /* CONFIG_KALLSYMS */
3610 3616
3611 static char *module_flags(struct module *mod, char *buf) 3617 static char *module_flags(struct module *mod, char *buf)
3612 { 3618 {
3613 int bx = 0; 3619 int bx = 0;
3614 3620
3615 BUG_ON(mod->state == MODULE_STATE_UNFORMED); 3621 BUG_ON(mod->state == MODULE_STATE_UNFORMED);
3616 if (mod->taints || 3622 if (mod->taints ||
3617 mod->state == MODULE_STATE_GOING || 3623 mod->state == MODULE_STATE_GOING ||
3618 mod->state == MODULE_STATE_COMING) { 3624 mod->state == MODULE_STATE_COMING) {
3619 buf[bx++] = '('; 3625 buf[bx++] = '(';
3620 bx += module_flags_taint(mod, buf + bx); 3626 bx += module_flags_taint(mod, buf + bx);
3621 /* Show a - for module-is-being-unloaded */ 3627 /* Show a - for module-is-being-unloaded */
3622 if (mod->state == MODULE_STATE_GOING) 3628 if (mod->state == MODULE_STATE_GOING)
3623 buf[bx++] = '-'; 3629 buf[bx++] = '-';
3624 /* Show a + for module-is-being-loaded */ 3630 /* Show a + for module-is-being-loaded */
3625 if (mod->state == MODULE_STATE_COMING) 3631 if (mod->state == MODULE_STATE_COMING)
3626 buf[bx++] = '+'; 3632 buf[bx++] = '+';
3627 buf[bx++] = ')'; 3633 buf[bx++] = ')';
3628 } 3634 }
3629 buf[bx] = '\0'; 3635 buf[bx] = '\0';
3630 3636
3631 return buf; 3637 return buf;
3632 } 3638 }
3633 3639
3634 #ifdef CONFIG_PROC_FS 3640 #ifdef CONFIG_PROC_FS
3635 /* Called by the /proc file system to return a list of modules. */ 3641 /* Called by the /proc file system to return a list of modules. */
3636 static void *m_start(struct seq_file *m, loff_t *pos) 3642 static void *m_start(struct seq_file *m, loff_t *pos)
3637 { 3643 {
3638 mutex_lock(&module_mutex); 3644 mutex_lock(&module_mutex);
3639 return seq_list_start(&modules, *pos); 3645 return seq_list_start(&modules, *pos);
3640 } 3646 }
3641 3647
3642 static void *m_next(struct seq_file *m, void *p, loff_t *pos) 3648 static void *m_next(struct seq_file *m, void *p, loff_t *pos)
3643 { 3649 {
3644 return seq_list_next(p, &modules, pos); 3650 return seq_list_next(p, &modules, pos);
3645 } 3651 }
3646 3652
3647 static void m_stop(struct seq_file *m, void *p) 3653 static void m_stop(struct seq_file *m, void *p)
3648 { 3654 {
3649 mutex_unlock(&module_mutex); 3655 mutex_unlock(&module_mutex);
3650 } 3656 }
3651 3657
3652 static int m_show(struct seq_file *m, void *p) 3658 static int m_show(struct seq_file *m, void *p)
3653 { 3659 {
3654 struct module *mod = list_entry(p, struct module, list); 3660 struct module *mod = list_entry(p, struct module, list);
3655 char buf[8]; 3661 char buf[8];
3656 3662
3657 /* We always ignore unformed modules. */ 3663 /* We always ignore unformed modules. */
3658 if (mod->state == MODULE_STATE_UNFORMED) 3664 if (mod->state == MODULE_STATE_UNFORMED)
3659 return 0; 3665 return 0;
3660 3666
3661 seq_printf(m, "%s %u", 3667 seq_printf(m, "%s %u",
3662 mod->name, mod->init_size + mod->core_size); 3668 mod->name, mod->init_size + mod->core_size);
3663 print_unload_info(m, mod); 3669 print_unload_info(m, mod);
3664 3670
3665 /* Informative for users. */ 3671 /* Informative for users. */
3666 seq_printf(m, " %s", 3672 seq_printf(m, " %s",
3667 mod->state == MODULE_STATE_GOING ? "Unloading": 3673 mod->state == MODULE_STATE_GOING ? "Unloading":
3668 mod->state == MODULE_STATE_COMING ? "Loading": 3674 mod->state == MODULE_STATE_COMING ? "Loading":
3669 "Live"); 3675 "Live");
3670 /* Used by oprofile and other similar tools. */ 3676 /* Used by oprofile and other similar tools. */
3671 seq_printf(m, " 0x%pK", mod->module_core); 3677 seq_printf(m, " 0x%pK", mod->module_core);
3672 3678
3673 /* Taints info */ 3679 /* Taints info */
3674 if (mod->taints) 3680 if (mod->taints)
3675 seq_printf(m, " %s", module_flags(mod, buf)); 3681 seq_printf(m, " %s", module_flags(mod, buf));
3676 3682
3677 seq_printf(m, "\n"); 3683 seq_printf(m, "\n");
3678 return 0; 3684 return 0;
3679 } 3685 }
3680 3686
3681 /* Format: modulename size refcount deps address 3687 /* Format: modulename size refcount deps address
3682 3688
3683 Where refcount is a number or -, and deps is a comma-separated list 3689 Where refcount is a number or -, and deps is a comma-separated list
3684 of depends or -. 3690 of depends or -.
3685 */ 3691 */
3686 static const struct seq_operations modules_op = { 3692 static const struct seq_operations modules_op = {
3687 .start = m_start, 3693 .start = m_start,
3688 .next = m_next, 3694 .next = m_next,
3689 .stop = m_stop, 3695 .stop = m_stop,
3690 .show = m_show 3696 .show = m_show
3691 }; 3697 };
3692 3698
3693 static int modules_open(struct inode *inode, struct file *file) 3699 static int modules_open(struct inode *inode, struct file *file)
3694 { 3700 {
3695 return seq_open(file, &modules_op); 3701 return seq_open(file, &modules_op);
3696 } 3702 }
3697 3703
3698 static const struct file_operations proc_modules_operations = { 3704 static const struct file_operations proc_modules_operations = {
3699 .open = modules_open, 3705 .open = modules_open,
3700 .read = seq_read, 3706 .read = seq_read,
3701 .llseek = seq_lseek, 3707 .llseek = seq_lseek,
3702 .release = seq_release, 3708 .release = seq_release,
3703 }; 3709 };
3704 3710
3705 static int __init proc_modules_init(void) 3711 static int __init proc_modules_init(void)
3706 { 3712 {
3707 proc_create("modules", 0, NULL, &proc_modules_operations); 3713 proc_create("modules", 0, NULL, &proc_modules_operations);
3708 return 0; 3714 return 0;
3709 } 3715 }
3710 module_init(proc_modules_init); 3716 module_init(proc_modules_init);
3711 #endif 3717 #endif
3712 3718
3713 /* Given an address, look for it in the module exception tables. */ 3719 /* Given an address, look for it in the module exception tables. */
3714 const struct exception_table_entry *search_module_extables(unsigned long addr) 3720 const struct exception_table_entry *search_module_extables(unsigned long addr)
3715 { 3721 {
3716 const struct exception_table_entry *e = NULL; 3722 const struct exception_table_entry *e = NULL;
3717 struct module *mod; 3723 struct module *mod;
3718 3724
3719 preempt_disable(); 3725 preempt_disable();
3720 list_for_each_entry_rcu(mod, &modules, list) { 3726 list_for_each_entry_rcu(mod, &modules, list) {
3721 if (mod->state == MODULE_STATE_UNFORMED) 3727 if (mod->state == MODULE_STATE_UNFORMED)
3722 continue; 3728 continue;
3723 if (mod->num_exentries == 0) 3729 if (mod->num_exentries == 0)
3724 continue; 3730 continue;
3725 3731
3726 e = search_extable(mod->extable, 3732 e = search_extable(mod->extable,
3727 mod->extable + mod->num_exentries - 1, 3733 mod->extable + mod->num_exentries - 1,
3728 addr); 3734 addr);
3729 if (e) 3735 if (e)
3730 break; 3736 break;
3731 } 3737 }
3732 preempt_enable(); 3738 preempt_enable();
3733 3739
3734 /* Now, if we found one, we are running inside it now, hence 3740 /* Now, if we found one, we are running inside it now, hence
3735 we cannot unload the module, hence no refcnt needed. */ 3741 we cannot unload the module, hence no refcnt needed. */
3736 return e; 3742 return e;
3737 } 3743 }
3738 3744
3739 /* 3745 /*
3740 * is_module_address - is this address inside a module? 3746 * is_module_address - is this address inside a module?
3741 * @addr: the address to check. 3747 * @addr: the address to check.
3742 * 3748 *
3743 * See is_module_text_address() if you simply want to see if the address 3749 * See is_module_text_address() if you simply want to see if the address
3744 * is code (not data). 3750 * is code (not data).
3745 */ 3751 */
3746 bool is_module_address(unsigned long addr) 3752 bool is_module_address(unsigned long addr)
3747 { 3753 {
3748 bool ret; 3754 bool ret;
3749 3755
3750 preempt_disable(); 3756 preempt_disable();
3751 ret = __module_address(addr) != NULL; 3757 ret = __module_address(addr) != NULL;
3752 preempt_enable(); 3758 preempt_enable();
3753 3759
3754 return ret; 3760 return ret;
3755 } 3761 }
3756 3762
3757 /* 3763 /*
3758 * __module_address - get the module which contains an address. 3764 * __module_address - get the module which contains an address.
3759 * @addr: the address. 3765 * @addr: the address.
3760 * 3766 *
3761 * Must be called with preempt disabled or module mutex held so that 3767 * Must be called with preempt disabled or module mutex held so that
3762 * module doesn't get freed during this. 3768 * module doesn't get freed during this.
3763 */ 3769 */
3764 struct module *__module_address(unsigned long addr) 3770 struct module *__module_address(unsigned long addr)
3765 { 3771 {
3766 struct module *mod; 3772 struct module *mod;
3767 3773
3768 if (addr < module_addr_min || addr > module_addr_max) 3774 if (addr < module_addr_min || addr > module_addr_max)
3769 return NULL; 3775 return NULL;
3770 3776
3771 list_for_each_entry_rcu(mod, &modules, list) { 3777 list_for_each_entry_rcu(mod, &modules, list) {
3772 if (mod->state == MODULE_STATE_UNFORMED) 3778 if (mod->state == MODULE_STATE_UNFORMED)
3773 continue; 3779 continue;
3774 if (within_module_core(addr, mod) 3780 if (within_module_core(addr, mod)
3775 || within_module_init(addr, mod)) 3781 || within_module_init(addr, mod))
3776 return mod; 3782 return mod;
3777 } 3783 }
3778 return NULL; 3784 return NULL;
3779 } 3785 }
3780 EXPORT_SYMBOL_GPL(__module_address); 3786 EXPORT_SYMBOL_GPL(__module_address);
3781 3787
3782 /* 3788 /*
3783 * is_module_text_address - is this address inside module code? 3789 * is_module_text_address - is this address inside module code?
3784 * @addr: the address to check. 3790 * @addr: the address to check.
3785 * 3791 *
3786 * See is_module_address() if you simply want to see if the address is 3792 * See is_module_address() if you simply want to see if the address is
3787 * anywhere in a module. See kernel_text_address() for testing if an 3793 * anywhere in a module. See kernel_text_address() for testing if an
3788 * address corresponds to kernel or module code. 3794 * address corresponds to kernel or module code.
3789 */ 3795 */
3790 bool is_module_text_address(unsigned long addr) 3796 bool is_module_text_address(unsigned long addr)
3791 { 3797 {
3792 bool ret; 3798 bool ret;
3793 3799
3794 preempt_disable(); 3800 preempt_disable();
3795 ret = __module_text_address(addr) != NULL; 3801 ret = __module_text_address(addr) != NULL;
3796 preempt_enable(); 3802 preempt_enable();
3797 3803
3798 return ret; 3804 return ret;
3799 } 3805 }
3800 3806
3801 /* 3807 /*
3802 * __module_text_address - get the module whose code contains an address. 3808 * __module_text_address - get the module whose code contains an address.
3803 * @addr: the address. 3809 * @addr: the address.
3804 * 3810 *
3805 * Must be called with preempt disabled or module mutex held so that 3811 * Must be called with preempt disabled or module mutex held so that
3806 * module doesn't get freed during this. 3812 * module doesn't get freed during this.
3807 */ 3813 */
3808 struct module *__module_text_address(unsigned long addr) 3814 struct module *__module_text_address(unsigned long addr)
3809 { 3815 {
3810 struct module *mod = __module_address(addr); 3816 struct module *mod = __module_address(addr);
3811 if (mod) { 3817 if (mod) {
3812 /* Make sure it's within the text section. */ 3818 /* Make sure it's within the text section. */
3813 if (!within(addr, mod->module_init, mod->init_text_size) 3819 if (!within(addr, mod->module_init, mod->init_text_size)
3814 && !within(addr, mod->module_core, mod->core_text_size)) 3820 && !within(addr, mod->module_core, mod->core_text_size))
3815 mod = NULL; 3821 mod = NULL;
3816 } 3822 }
3817 return mod; 3823 return mod;
3818 } 3824 }
3819 EXPORT_SYMBOL_GPL(__module_text_address); 3825 EXPORT_SYMBOL_GPL(__module_text_address);
3820 3826
3821 /* Don't grab lock, we're oopsing. */ 3827 /* Don't grab lock, we're oopsing. */
3822 void print_modules(void) 3828 void print_modules(void)
3823 { 3829 {
3824 struct module *mod; 3830 struct module *mod;
3825 char buf[8]; 3831 char buf[8];
3826 3832
3827 printk(KERN_DEFAULT "Modules linked in:"); 3833 printk(KERN_DEFAULT "Modules linked in:");
3828 /* Most callers should already have preempt disabled, but make sure */ 3834 /* Most callers should already have preempt disabled, but make sure */
3829 preempt_disable(); 3835 preempt_disable();
3830 list_for_each_entry_rcu(mod, &modules, list) { 3836 list_for_each_entry_rcu(mod, &modules, list) {
3831 if (mod->state == MODULE_STATE_UNFORMED) 3837 if (mod->state == MODULE_STATE_UNFORMED)
3832 continue; 3838 continue;
3833 printk(" %s%s", mod->name, module_flags(mod, buf)); 3839 printk(" %s%s", mod->name, module_flags(mod, buf));
3834 } 3840 }
3835 preempt_enable(); 3841 preempt_enable();
3836 if (last_unloaded_module[0]) 3842 if (last_unloaded_module[0])
3837 printk(" [last unloaded: %s]", last_unloaded_module); 3843 printk(" [last unloaded: %s]", last_unloaded_module);
3838 printk("\n"); 3844 printk("\n");
3839 } 3845 }
3840 3846
3841 #ifdef CONFIG_MODVERSIONS 3847 #ifdef CONFIG_MODVERSIONS
3842 /* Generate the signature for all relevant module structures here. 3848 /* Generate the signature for all relevant module structures here.
3843 * If these change, we don't want to try to parse the module. */ 3849 * If these change, we don't want to try to parse the module. */
3844 void module_layout(struct module *mod, 3850 void module_layout(struct module *mod,
3845 struct modversion_info *ver, 3851 struct modversion_info *ver,
3846 struct kernel_param *kp, 3852 struct kernel_param *kp,
3847 struct kernel_symbol *ks, 3853 struct kernel_symbol *ks,
3848 struct tracepoint * const *tp) 3854 struct tracepoint * const *tp)
3849 { 3855 {
scripts/Makefile.build
1 # ========================================================================== 1 # ==========================================================================
2 # Building 2 # Building
3 # ========================================================================== 3 # ==========================================================================
4 4
5 src := $(obj) 5 src := $(obj)
6 6
7 PHONY := __build 7 PHONY := __build
8 __build: 8 __build:
9 9
10 # Init all relevant variables used in kbuild files so 10 # Init all relevant variables used in kbuild files so
11 # 1) they have correct type 11 # 1) they have correct type
12 # 2) they do not inherit any value from the environment 12 # 2) they do not inherit any value from the environment
13 obj-y := 13 obj-y :=
14 obj-m := 14 obj-m :=
15 lib-y := 15 lib-y :=
16 lib-m := 16 lib-m :=
17 always := 17 always :=
18 targets := 18 targets :=
19 subdir-y := 19 subdir-y :=
20 subdir-m := 20 subdir-m :=
21 EXTRA_AFLAGS := 21 EXTRA_AFLAGS :=
22 EXTRA_CFLAGS := 22 EXTRA_CFLAGS :=
23 EXTRA_CPPFLAGS := 23 EXTRA_CPPFLAGS :=
24 EXTRA_LDFLAGS := 24 EXTRA_LDFLAGS :=
25 asflags-y := 25 asflags-y :=
26 ccflags-y := 26 ccflags-y :=
27 cppflags-y := 27 cppflags-y :=
28 ldflags-y := 28 ldflags-y :=
29 29
30 subdir-asflags-y := 30 subdir-asflags-y :=
31 subdir-ccflags-y := 31 subdir-ccflags-y :=
32 32
33 # Read auto.conf if it exists, otherwise ignore 33 # Read auto.conf if it exists, otherwise ignore
34 -include include/config/auto.conf 34 -include include/config/auto.conf
35 35
36 include scripts/Kbuild.include 36 include scripts/Kbuild.include
37 37
38 # For backward compatibility check that these variables do not change 38 # For backward compatibility check that these variables do not change
39 save-cflags := $(CFLAGS) 39 save-cflags := $(CFLAGS)
40 40
41 # The filename Kbuild has precedence over Makefile 41 # The filename Kbuild has precedence over Makefile
42 kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) 42 kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
43 kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile) 43 kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile)
44 include $(kbuild-file) 44 include $(kbuild-file)
45 45
46 # If the save-* variables changed error out 46 # If the save-* variables changed error out
47 ifeq ($(KBUILD_NOPEDANTIC),) 47 ifeq ($(KBUILD_NOPEDANTIC),)
48 ifneq ("$(save-cflags)","$(CFLAGS)") 48 ifneq ("$(save-cflags)","$(CFLAGS)")
49 $(error CFLAGS was changed in "$(kbuild-file)". Fix it to use ccflags-y) 49 $(error CFLAGS was changed in "$(kbuild-file)". Fix it to use ccflags-y)
50 endif 50 endif
51 endif 51 endif
52 52
53 # 53 #
54 # make W=... settings 54 # make W=... settings
55 # 55 #
56 # W=1 - warnings that may be relevant and does not occur too often 56 # W=1 - warnings that may be relevant and does not occur too often
57 # W=2 - warnings that occur quite often but may still be relevant 57 # W=2 - warnings that occur quite often but may still be relevant
58 # W=3 - the more obscure warnings, can most likely be ignored 58 # W=3 - the more obscure warnings, can most likely be ignored
59 # 59 #
60 # $(call cc-option, -W...) handles gcc -W.. options which 60 # $(call cc-option, -W...) handles gcc -W.. options which
61 # are not supported by all versions of the compiler 61 # are not supported by all versions of the compiler
62 ifdef KBUILD_ENABLE_EXTRA_GCC_CHECKS 62 ifdef KBUILD_ENABLE_EXTRA_GCC_CHECKS
63 warning- := $(empty) 63 warning- := $(empty)
64 64
65 warning-1 := -Wextra -Wunused -Wno-unused-parameter 65 warning-1 := -Wextra -Wunused -Wno-unused-parameter
66 warning-1 += -Wmissing-declarations 66 warning-1 += -Wmissing-declarations
67 warning-1 += -Wmissing-format-attribute 67 warning-1 += -Wmissing-format-attribute
68 warning-1 += -Wmissing-prototypes 68 warning-1 += -Wmissing-prototypes
69 warning-1 += -Wold-style-definition 69 warning-1 += -Wold-style-definition
70 warning-1 += $(call cc-option, -Wmissing-include-dirs) 70 warning-1 += $(call cc-option, -Wmissing-include-dirs)
71 warning-1 += $(call cc-option, -Wunused-but-set-variable) 71 warning-1 += $(call cc-option, -Wunused-but-set-variable)
72 warning-1 += $(call cc-disable-warning, missing-field-initializers) 72 warning-1 += $(call cc-disable-warning, missing-field-initializers)
73 73
74 warning-2 := -Waggregate-return 74 warning-2 := -Waggregate-return
75 warning-2 += -Wcast-align 75 warning-2 += -Wcast-align
76 warning-2 += -Wdisabled-optimization 76 warning-2 += -Wdisabled-optimization
77 warning-2 += -Wnested-externs 77 warning-2 += -Wnested-externs
78 warning-2 += -Wshadow 78 warning-2 += -Wshadow
79 warning-2 += $(call cc-option, -Wlogical-op) 79 warning-2 += $(call cc-option, -Wlogical-op)
80 warning-2 += $(call cc-option, -Wmissing-field-initializers) 80 warning-2 += $(call cc-option, -Wmissing-field-initializers)
81 81
82 warning-3 := -Wbad-function-cast 82 warning-3 := -Wbad-function-cast
83 warning-3 += -Wcast-qual 83 warning-3 += -Wcast-qual
84 warning-3 += -Wconversion 84 warning-3 += -Wconversion
85 warning-3 += -Wpacked 85 warning-3 += -Wpacked
86 warning-3 += -Wpadded 86 warning-3 += -Wpadded
87 warning-3 += -Wpointer-arith 87 warning-3 += -Wpointer-arith
88 warning-3 += -Wredundant-decls 88 warning-3 += -Wredundant-decls
89 warning-3 += -Wswitch-default 89 warning-3 += -Wswitch-default
90 warning-3 += $(call cc-option, -Wpacked-bitfield-compat) 90 warning-3 += $(call cc-option, -Wpacked-bitfield-compat)
91 warning-3 += $(call cc-option, -Wvla) 91 warning-3 += $(call cc-option, -Wvla)
92 92
93 warning := $(warning-$(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) 93 warning := $(warning-$(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
94 warning += $(warning-$(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) 94 warning += $(warning-$(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
95 warning += $(warning-$(findstring 3, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) 95 warning += $(warning-$(findstring 3, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)))
96 96
97 ifeq ("$(strip $(warning))","") 97 ifeq ("$(strip $(warning))","")
98 $(error W=$(KBUILD_ENABLE_EXTRA_GCC_CHECKS) is unknown) 98 $(error W=$(KBUILD_ENABLE_EXTRA_GCC_CHECKS) is unknown)
99 endif 99 endif
100 100
101 KBUILD_CFLAGS += $(warning) 101 KBUILD_CFLAGS += $(warning)
102 endif 102 endif
103 103
104 include scripts/Makefile.lib 104 include scripts/Makefile.lib
105 105
106 ifdef host-progs 106 ifdef host-progs
107 ifneq ($(hostprogs-y),$(host-progs)) 107 ifneq ($(hostprogs-y),$(host-progs))
108 $(warning kbuild: $(obj)/Makefile - Usage of host-progs is deprecated. Please replace with hostprogs-y!) 108 $(warning kbuild: $(obj)/Makefile - Usage of host-progs is deprecated. Please replace with hostprogs-y!)
109 hostprogs-y += $(host-progs) 109 hostprogs-y += $(host-progs)
110 endif 110 endif
111 endif 111 endif
112 112
113 # Do not include host rules unless needed 113 # Do not include host rules unless needed
114 ifneq ($(hostprogs-y)$(hostprogs-m),) 114 ifneq ($(hostprogs-y)$(hostprogs-m),)
115 include scripts/Makefile.host 115 include scripts/Makefile.host
116 endif 116 endif
117 117
118 ifneq ($(KBUILD_SRC),) 118 ifneq ($(KBUILD_SRC),)
119 # Create output directory if not already present 119 # Create output directory if not already present
120 _dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj)) 120 _dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
121 121
122 # Create directories for object files if directory does not exist 122 # Create directories for object files if directory does not exist
123 # Needed when obj-y := dir/file.o syntax is used 123 # Needed when obj-y := dir/file.o syntax is used
124 _dummy := $(foreach d,$(obj-dirs), $(shell [ -d $(d) ] || mkdir -p $(d))) 124 _dummy := $(foreach d,$(obj-dirs), $(shell [ -d $(d) ] || mkdir -p $(d)))
125 endif 125 endif
126 126
127 ifndef obj 127 ifndef obj
128 $(warning kbuild: Makefile.build is included improperly) 128 $(warning kbuild: Makefile.build is included improperly)
129 endif 129 endif
130 130
131 # =========================================================================== 131 # ===========================================================================
132 132
133 ifneq ($(strip $(lib-y) $(lib-m) $(lib-n) $(lib-)),) 133 ifneq ($(strip $(lib-y) $(lib-m) $(lib-n) $(lib-)),)
134 lib-target := $(obj)/lib.a 134 lib-target := $(obj)/lib.a
135 endif 135 endif
136 136
137 ifneq ($(strip $(obj-y) $(obj-m) $(obj-n) $(obj-) $(subdir-m) $(lib-target)),) 137 ifneq ($(strip $(obj-y) $(obj-m) $(obj-n) $(obj-) $(subdir-m) $(lib-target)),)
138 builtin-target := $(obj)/built-in.o 138 builtin-target := $(obj)/built-in.o
139 endif 139 endif
140 140
141 modorder-target := $(obj)/modules.order 141 modorder-target := $(obj)/modules.order
142 142
143 # We keep a list of all modules in $(MODVERDIR) 143 # We keep a list of all modules in $(MODVERDIR)
144 144
145 __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \ 145 __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \
146 $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \ 146 $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \
147 $(subdir-ym) $(always) 147 $(subdir-ym) $(always)
148 @: 148 @:
149 149
150 # Linus' kernel sanity checking tool 150 # Linus' kernel sanity checking tool
151 ifneq ($(KBUILD_CHECKSRC),0) 151 ifneq ($(KBUILD_CHECKSRC),0)
152 ifeq ($(KBUILD_CHECKSRC),2) 152 ifeq ($(KBUILD_CHECKSRC),2)
153 quiet_cmd_force_checksrc = CHECK $< 153 quiet_cmd_force_checksrc = CHECK $<
154 cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ; 154 cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ;
155 else 155 else
156 quiet_cmd_checksrc = CHECK $< 156 quiet_cmd_checksrc = CHECK $<
157 cmd_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ; 157 cmd_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ;
158 endif 158 endif
159 endif 159 endif
160 160
161 # Do section mismatch analysis for each module/built-in.o 161 # Do section mismatch analysis for each module/built-in.o
162 ifdef CONFIG_DEBUG_SECTION_MISMATCH 162 ifdef CONFIG_DEBUG_SECTION_MISMATCH
163 cmd_secanalysis = ; scripts/mod/modpost $@ 163 cmd_secanalysis = ; scripts/mod/modpost $@
164 endif 164 endif
165 165
166 # Compile C sources (.c) 166 # Compile C sources (.c)
167 # --------------------------------------------------------------------------- 167 # ---------------------------------------------------------------------------
168 168
169 # Default is built-in, unless we know otherwise 169 # Default is built-in, unless we know otherwise
170 modkern_cflags = \ 170 modkern_cflags = \
171 $(if $(part-of-module), \ 171 $(if $(part-of-module), \
172 $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \ 172 $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \
173 $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL)) 173 $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL))
174 quiet_modtag := $(empty) $(empty) 174 quiet_modtag := $(empty) $(empty)
175 175
176 $(real-objs-m) : part-of-module := y 176 $(real-objs-m) : part-of-module := y
177 $(real-objs-m:.o=.i) : part-of-module := y 177 $(real-objs-m:.o=.i) : part-of-module := y
178 $(real-objs-m:.o=.s) : part-of-module := y 178 $(real-objs-m:.o=.s) : part-of-module := y
179 $(real-objs-m:.o=.lst): part-of-module := y 179 $(real-objs-m:.o=.lst): part-of-module := y
180 180
181 $(real-objs-m) : quiet_modtag := [M] 181 $(real-objs-m) : quiet_modtag := [M]
182 $(real-objs-m:.o=.i) : quiet_modtag := [M] 182 $(real-objs-m:.o=.i) : quiet_modtag := [M]
183 $(real-objs-m:.o=.s) : quiet_modtag := [M] 183 $(real-objs-m:.o=.s) : quiet_modtag := [M]
184 $(real-objs-m:.o=.lst): quiet_modtag := [M] 184 $(real-objs-m:.o=.lst): quiet_modtag := [M]
185 185
186 $(obj-m) : quiet_modtag := [M] 186 $(obj-m) : quiet_modtag := [M]
187 187
188 # Default for not multi-part modules 188 # Default for not multi-part modules
189 modname = $(basetarget) 189 modname = $(basetarget)
190 190
191 $(multi-objs-m) : modname = $(modname-multi) 191 $(multi-objs-m) : modname = $(modname-multi)
192 $(multi-objs-m:.o=.i) : modname = $(modname-multi) 192 $(multi-objs-m:.o=.i) : modname = $(modname-multi)
193 $(multi-objs-m:.o=.s) : modname = $(modname-multi) 193 $(multi-objs-m:.o=.s) : modname = $(modname-multi)
194 $(multi-objs-m:.o=.lst) : modname = $(modname-multi) 194 $(multi-objs-m:.o=.lst) : modname = $(modname-multi)
195 $(multi-objs-y) : modname = $(modname-multi) 195 $(multi-objs-y) : modname = $(modname-multi)
196 $(multi-objs-y:.o=.i) : modname = $(modname-multi) 196 $(multi-objs-y:.o=.i) : modname = $(modname-multi)
197 $(multi-objs-y:.o=.s) : modname = $(modname-multi) 197 $(multi-objs-y:.o=.s) : modname = $(modname-multi)
198 $(multi-objs-y:.o=.lst) : modname = $(modname-multi) 198 $(multi-objs-y:.o=.lst) : modname = $(modname-multi)
199 199
200 quiet_cmd_cc_s_c = CC $(quiet_modtag) $@ 200 quiet_cmd_cc_s_c = CC $(quiet_modtag) $@
201 cmd_cc_s_c = $(CC) $(c_flags) -fverbose-asm -S -o $@ $< 201 cmd_cc_s_c = $(CC) $(c_flags) -fverbose-asm -S -o $@ $<
202 202
203 $(obj)/%.s: $(src)/%.c FORCE 203 $(obj)/%.s: $(src)/%.c FORCE
204 $(call if_changed_dep,cc_s_c) 204 $(call if_changed_dep,cc_s_c)
205 205
206 quiet_cmd_cc_i_c = CPP $(quiet_modtag) $@ 206 quiet_cmd_cc_i_c = CPP $(quiet_modtag) $@
207 cmd_cc_i_c = $(CPP) $(c_flags) -o $@ $< 207 cmd_cc_i_c = $(CPP) $(c_flags) -o $@ $<
208 208
209 $(obj)/%.i: $(src)/%.c FORCE 209 $(obj)/%.i: $(src)/%.c FORCE
210 $(call if_changed_dep,cc_i_c) 210 $(call if_changed_dep,cc_i_c)
211 211
212 cmd_gensymtypes = \ 212 cmd_gensymtypes = \
213 $(CPP) -D__GENKSYMS__ $(c_flags) $< | \ 213 $(CPP) -D__GENKSYMS__ $(c_flags) $< | \
214 $(GENKSYMS) $(if $(1), -T $(2)) -a $(ARCH) \ 214 $(GENKSYMS) $(if $(1), -T $(2)) \
215 $(patsubst y,-s _,$(CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX)) \
215 $(if $(KBUILD_PRESERVE),-p) \ 216 $(if $(KBUILD_PRESERVE),-p) \
216 -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null)) 217 -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
217 218
218 quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@ 219 quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
219 cmd_cc_symtypes_c = \ 220 cmd_cc_symtypes_c = \
220 set -e; \ 221 set -e; \
221 $(call cmd_gensymtypes,true,$@) >/dev/null; \ 222 $(call cmd_gensymtypes,true,$@) >/dev/null; \
222 test -s $@ || rm -f $@ 223 test -s $@ || rm -f $@
223 224
224 $(obj)/%.symtypes : $(src)/%.c FORCE 225 $(obj)/%.symtypes : $(src)/%.c FORCE
225 $(call cmd,cc_symtypes_c) 226 $(call cmd,cc_symtypes_c)
226 227
227 # C (.c) files 228 # C (.c) files
228 # The C file is compiled and updated dependency information is generated. 229 # The C file is compiled and updated dependency information is generated.
229 # (See cmd_cc_o_c + relevant part of rule_cc_o_c) 230 # (See cmd_cc_o_c + relevant part of rule_cc_o_c)
230 231
231 quiet_cmd_cc_o_c = CC $(quiet_modtag) $@ 232 quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
232 233
233 ifndef CONFIG_MODVERSIONS 234 ifndef CONFIG_MODVERSIONS
234 cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< 235 cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
235 236
236 else 237 else
237 # When module versioning is enabled the following steps are executed: 238 # When module versioning is enabled the following steps are executed:
238 # o compile a .tmp_<file>.o from <file>.c 239 # o compile a .tmp_<file>.o from <file>.c
239 # o if .tmp_<file>.o doesn't contain a __ksymtab version, i.e. does 240 # o if .tmp_<file>.o doesn't contain a __ksymtab version, i.e. does
240 # not export symbols, we just rename .tmp_<file>.o to <file>.o and 241 # not export symbols, we just rename .tmp_<file>.o to <file>.o and
241 # are done. 242 # are done.
242 # o otherwise, we calculate symbol versions using the good old 243 # o otherwise, we calculate symbol versions using the good old
243 # genksyms on the preprocessed source and postprocess them in a way 244 # genksyms on the preprocessed source and postprocess them in a way
244 # that they are usable as a linker script 245 # that they are usable as a linker script
245 # o generate <file>.o from .tmp_<file>.o using the linker to 246 # o generate <file>.o from .tmp_<file>.o using the linker to
246 # replace the unresolved symbols __crc_exported_symbol with 247 # replace the unresolved symbols __crc_exported_symbol with
247 # the actual value of the checksum generated by genksyms 248 # the actual value of the checksum generated by genksyms
248 249
249 cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $< 250 cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $<
250 cmd_modversions = \ 251 cmd_modversions = \
251 if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \ 252 if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \
252 $(call cmd_gensymtypes,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ 253 $(call cmd_gensymtypes,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
253 > $(@D)/.tmp_$(@F:.o=.ver); \ 254 > $(@D)/.tmp_$(@F:.o=.ver); \
254 \ 255 \
255 $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \ 256 $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \
256 -T $(@D)/.tmp_$(@F:.o=.ver); \ 257 -T $(@D)/.tmp_$(@F:.o=.ver); \
257 rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \ 258 rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \
258 else \ 259 else \
259 mv -f $(@D)/.tmp_$(@F) $@; \ 260 mv -f $(@D)/.tmp_$(@F) $@; \
260 fi; 261 fi;
261 endif 262 endif
262 263
263 ifdef CONFIG_FTRACE_MCOUNT_RECORD 264 ifdef CONFIG_FTRACE_MCOUNT_RECORD
264 ifdef BUILD_C_RECORDMCOUNT 265 ifdef BUILD_C_RECORDMCOUNT
265 ifeq ("$(origin RECORDMCOUNT_WARN)", "command line") 266 ifeq ("$(origin RECORDMCOUNT_WARN)", "command line")
266 RECORDMCOUNT_FLAGS = -w 267 RECORDMCOUNT_FLAGS = -w
267 endif 268 endif
268 # Due to recursion, we must skip empty.o. 269 # Due to recursion, we must skip empty.o.
269 # The empty.o file is created in the make process in order to determine 270 # The empty.o file is created in the make process in order to determine
270 # the target endianness and word size. It is made before all other C 271 # the target endianness and word size. It is made before all other C
271 # files, including recordmcount. 272 # files, including recordmcount.
272 sub_cmd_record_mcount = \ 273 sub_cmd_record_mcount = \
273 if [ $(@) != "scripts/mod/empty.o" ]; then \ 274 if [ $(@) != "scripts/mod/empty.o" ]; then \
274 $(objtree)/scripts/recordmcount $(RECORDMCOUNT_FLAGS) "$(@)"; \ 275 $(objtree)/scripts/recordmcount $(RECORDMCOUNT_FLAGS) "$(@)"; \
275 fi; 276 fi;
276 recordmcount_source := $(srctree)/scripts/recordmcount.c \ 277 recordmcount_source := $(srctree)/scripts/recordmcount.c \
277 $(srctree)/scripts/recordmcount.h 278 $(srctree)/scripts/recordmcount.h
278 else 279 else
279 sub_cmd_record_mcount = set -e ; perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \ 280 sub_cmd_record_mcount = set -e ; perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \
280 "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \ 281 "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \
281 "$(if $(CONFIG_64BIT),64,32)" \ 282 "$(if $(CONFIG_64BIT),64,32)" \
282 "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CFLAGS)" \ 283 "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CFLAGS)" \
283 "$(LD)" "$(NM)" "$(RM)" "$(MV)" \ 284 "$(LD)" "$(NM)" "$(RM)" "$(MV)" \
284 "$(if $(part-of-module),1,0)" "$(@)"; 285 "$(if $(part-of-module),1,0)" "$(@)";
285 recordmcount_source := $(srctree)/scripts/recordmcount.pl 286 recordmcount_source := $(srctree)/scripts/recordmcount.pl
286 endif 287 endif
287 cmd_record_mcount = \ 288 cmd_record_mcount = \
288 if [ "$(findstring -pg,$(_c_flags))" = "-pg" ]; then \ 289 if [ "$(findstring -pg,$(_c_flags))" = "-pg" ]; then \
289 $(sub_cmd_record_mcount) \ 290 $(sub_cmd_record_mcount) \
290 fi; 291 fi;
291 endif 292 endif
292 293
293 define rule_cc_o_c 294 define rule_cc_o_c
294 $(call echo-cmd,checksrc) $(cmd_checksrc) \ 295 $(call echo-cmd,checksrc) $(cmd_checksrc) \
295 $(call echo-cmd,cc_o_c) $(cmd_cc_o_c); \ 296 $(call echo-cmd,cc_o_c) $(cmd_cc_o_c); \
296 $(cmd_modversions) \ 297 $(cmd_modversions) \
297 $(call echo-cmd,record_mcount) \ 298 $(call echo-cmd,record_mcount) \
298 $(cmd_record_mcount) \ 299 $(cmd_record_mcount) \
299 scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,cc_o_c)' > \ 300 scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,cc_o_c)' > \
300 $(dot-target).tmp; \ 301 $(dot-target).tmp; \
301 rm -f $(depfile); \ 302 rm -f $(depfile); \
302 mv -f $(dot-target).tmp $(dot-target).cmd 303 mv -f $(dot-target).tmp $(dot-target).cmd
303 endef 304 endef
304 305
305 # Built-in and composite module parts 306 # Built-in and composite module parts
306 $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE 307 $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
307 $(call cmd,force_checksrc) 308 $(call cmd,force_checksrc)
308 $(call if_changed_rule,cc_o_c) 309 $(call if_changed_rule,cc_o_c)
309 310
310 # Single-part modules are special since we need to mark them in $(MODVERDIR) 311 # Single-part modules are special since we need to mark them in $(MODVERDIR)
311 312
312 $(single-used-m): $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE 313 $(single-used-m): $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
313 $(call cmd,force_checksrc) 314 $(call cmd,force_checksrc)
314 $(call if_changed_rule,cc_o_c) 315 $(call if_changed_rule,cc_o_c)
315 @{ echo $(@:.o=.ko); echo $@; } > $(MODVERDIR)/$(@F:.o=.mod) 316 @{ echo $(@:.o=.ko); echo $@; } > $(MODVERDIR)/$(@F:.o=.mod)
316 317
317 quiet_cmd_cc_lst_c = MKLST $@ 318 quiet_cmd_cc_lst_c = MKLST $@
318 cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \ 319 cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
319 $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \ 320 $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
320 System.map $(OBJDUMP) > $@ 321 System.map $(OBJDUMP) > $@
321 322
322 $(obj)/%.lst: $(src)/%.c FORCE 323 $(obj)/%.lst: $(src)/%.c FORCE
323 $(call if_changed_dep,cc_lst_c) 324 $(call if_changed_dep,cc_lst_c)
324 325
325 # Compile assembler sources (.S) 326 # Compile assembler sources (.S)
326 # --------------------------------------------------------------------------- 327 # ---------------------------------------------------------------------------
327 328
328 modkern_aflags := $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL) 329 modkern_aflags := $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL)
329 330
330 $(real-objs-m) : modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE) 331 $(real-objs-m) : modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE)
331 $(real-objs-m:.o=.s): modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE) 332 $(real-objs-m:.o=.s): modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE)
332 333
333 quiet_cmd_as_s_S = CPP $(quiet_modtag) $@ 334 quiet_cmd_as_s_S = CPP $(quiet_modtag) $@
334 cmd_as_s_S = $(CPP) $(a_flags) -o $@ $< 335 cmd_as_s_S = $(CPP) $(a_flags) -o $@ $<
335 336
336 $(obj)/%.s: $(src)/%.S FORCE 337 $(obj)/%.s: $(src)/%.S FORCE
337 $(call if_changed_dep,as_s_S) 338 $(call if_changed_dep,as_s_S)
338 339
339 quiet_cmd_as_o_S = AS $(quiet_modtag) $@ 340 quiet_cmd_as_o_S = AS $(quiet_modtag) $@
340 cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< 341 cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
341 342
342 $(obj)/%.o: $(src)/%.S FORCE 343 $(obj)/%.o: $(src)/%.S FORCE
343 $(call if_changed_dep,as_o_S) 344 $(call if_changed_dep,as_o_S)
344 345
345 targets += $(real-objs-y) $(real-objs-m) $(lib-y) 346 targets += $(real-objs-y) $(real-objs-m) $(lib-y)
346 targets += $(extra-y) $(MAKECMDGOALS) $(always) 347 targets += $(extra-y) $(MAKECMDGOALS) $(always)
347 348
348 # Linker scripts preprocessor (.lds.S -> .lds) 349 # Linker scripts preprocessor (.lds.S -> .lds)
349 # --------------------------------------------------------------------------- 350 # ---------------------------------------------------------------------------
350 quiet_cmd_cpp_lds_S = LDS $@ 351 quiet_cmd_cpp_lds_S = LDS $@
351 cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -C -U$(ARCH) \ 352 cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -C -U$(ARCH) \
352 -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $< 353 -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $<
353 354
354 $(obj)/%.lds: $(src)/%.lds.S FORCE 355 $(obj)/%.lds: $(src)/%.lds.S FORCE
355 $(call if_changed_dep,cpp_lds_S) 356 $(call if_changed_dep,cpp_lds_S)
356 357
357 # ASN.1 grammar 358 # ASN.1 grammar
358 # --------------------------------------------------------------------------- 359 # ---------------------------------------------------------------------------
359 quiet_cmd_asn1_compiler = ASN.1 $@ 360 quiet_cmd_asn1_compiler = ASN.1 $@
360 cmd_asn1_compiler = $(objtree)/scripts/asn1_compiler $< \ 361 cmd_asn1_compiler = $(objtree)/scripts/asn1_compiler $< \
361 $(subst .h,.c,$@) $(subst .c,.h,$@) 362 $(subst .h,.c,$@) $(subst .c,.h,$@)
362 363
363 .PRECIOUS: $(objtree)/$(obj)/%-asn1.c $(objtree)/$(obj)/%-asn1.h 364 .PRECIOUS: $(objtree)/$(obj)/%-asn1.c $(objtree)/$(obj)/%-asn1.h
364 365
365 $(obj)/%-asn1.c $(obj)/%-asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler 366 $(obj)/%-asn1.c $(obj)/%-asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler
366 $(call cmd,asn1_compiler) 367 $(call cmd,asn1_compiler)
367 368
368 # Build the compiled-in targets 369 # Build the compiled-in targets
369 # --------------------------------------------------------------------------- 370 # ---------------------------------------------------------------------------
370 371
371 # To build objects in subdirs, we need to descend into the directories 372 # To build objects in subdirs, we need to descend into the directories
372 $(sort $(subdir-obj-y)): $(subdir-ym) ; 373 $(sort $(subdir-obj-y)): $(subdir-ym) ;
373 374
374 # 375 #
375 # Rule to compile a set of .o files into one .o file 376 # Rule to compile a set of .o files into one .o file
376 # 377 #
377 ifdef builtin-target 378 ifdef builtin-target
378 quiet_cmd_link_o_target = LD $@ 379 quiet_cmd_link_o_target = LD $@
379 # If the list of objects to link is empty, just create an empty built-in.o 380 # If the list of objects to link is empty, just create an empty built-in.o
380 cmd_link_o_target = $(if $(strip $(obj-y)),\ 381 cmd_link_o_target = $(if $(strip $(obj-y)),\
381 $(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^) \ 382 $(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^) \
382 $(cmd_secanalysis),\ 383 $(cmd_secanalysis),\
383 rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@) 384 rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@)
384 385
385 $(builtin-target): $(obj-y) FORCE 386 $(builtin-target): $(obj-y) FORCE
386 $(call if_changed,link_o_target) 387 $(call if_changed,link_o_target)
387 388
388 targets += $(builtin-target) 389 targets += $(builtin-target)
389 endif # builtin-target 390 endif # builtin-target
390 391
391 # 392 #
392 # Rule to create modules.order file 393 # Rule to create modules.order file
393 # 394 #
394 # Create commands to either record .ko file or cat modules.order from 395 # Create commands to either record .ko file or cat modules.order from
395 # a subdirectory 396 # a subdirectory
396 modorder-cmds = \ 397 modorder-cmds = \
397 $(foreach m, $(modorder), \ 398 $(foreach m, $(modorder), \
398 $(if $(filter %/modules.order, $m), \ 399 $(if $(filter %/modules.order, $m), \
399 cat $m;, echo kernel/$m;)) 400 cat $m;, echo kernel/$m;))
400 401
401 $(modorder-target): $(subdir-ym) FORCE 402 $(modorder-target): $(subdir-ym) FORCE
402 $(Q)(cat /dev/null; $(modorder-cmds)) > $@ 403 $(Q)(cat /dev/null; $(modorder-cmds)) > $@
403 404
404 # 405 #
405 # Rule to compile a set of .o files into one .a file 406 # Rule to compile a set of .o files into one .a file
406 # 407 #
407 ifdef lib-target 408 ifdef lib-target
408 quiet_cmd_link_l_target = AR $@ 409 quiet_cmd_link_l_target = AR $@
409 cmd_link_l_target = rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@ $(lib-y) 410 cmd_link_l_target = rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@ $(lib-y)
410 411
411 $(lib-target): $(lib-y) FORCE 412 $(lib-target): $(lib-y) FORCE
412 $(call if_changed,link_l_target) 413 $(call if_changed,link_l_target)
413 414
414 targets += $(lib-target) 415 targets += $(lib-target)
415 endif 416 endif
416 417
417 # 418 #
418 # Rule to link composite objects 419 # Rule to link composite objects
419 # 420 #
420 # Composite objects are specified in kbuild makefile as follows: 421 # Composite objects are specified in kbuild makefile as follows:
421 # <composite-object>-objs := <list of .o files> 422 # <composite-object>-objs := <list of .o files>
422 # or 423 # or
423 # <composite-object>-y := <list of .o files> 424 # <composite-object>-y := <list of .o files>
424 link_multi_deps = \ 425 link_multi_deps = \
425 $(filter $(addprefix $(obj)/, \ 426 $(filter $(addprefix $(obj)/, \
426 $($(subst $(obj)/,,$(@:.o=-objs))) \ 427 $($(subst $(obj)/,,$(@:.o=-objs))) \
427 $($(subst $(obj)/,,$(@:.o=-y)))), $^) 428 $($(subst $(obj)/,,$(@:.o=-y)))), $^)
428 429
429 quiet_cmd_link_multi-y = LD $@ 430 quiet_cmd_link_multi-y = LD $@
430 cmd_link_multi-y = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps) $(cmd_secanalysis) 431 cmd_link_multi-y = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps) $(cmd_secanalysis)
431 432
432 quiet_cmd_link_multi-m = LD [M] $@ 433 quiet_cmd_link_multi-m = LD [M] $@
433 cmd_link_multi-m = $(cmd_link_multi-y) 434 cmd_link_multi-m = $(cmd_link_multi-y)
434 435
435 # We would rather have a list of rules like 436 # We would rather have a list of rules like
436 # foo.o: $(foo-objs) 437 # foo.o: $(foo-objs)
437 # but that's not so easy, so we rather make all composite objects depend 438 # but that's not so easy, so we rather make all composite objects depend
438 # on the set of all their parts 439 # on the set of all their parts
439 $(multi-used-y) : %.o: $(multi-objs-y) FORCE 440 $(multi-used-y) : %.o: $(multi-objs-y) FORCE
440 $(call if_changed,link_multi-y) 441 $(call if_changed,link_multi-y)
441 442
442 $(multi-used-m) : %.o: $(multi-objs-m) FORCE 443 $(multi-used-m) : %.o: $(multi-objs-m) FORCE
443 $(call if_changed,link_multi-m) 444 $(call if_changed,link_multi-m)
444 @{ echo $(@:.o=.ko); echo $(link_multi_deps); } > $(MODVERDIR)/$(@F:.o=.mod) 445 @{ echo $(@:.o=.ko); echo $(link_multi_deps); } > $(MODVERDIR)/$(@F:.o=.mod)
445 446
446 targets += $(multi-used-y) $(multi-used-m) 447 targets += $(multi-used-y) $(multi-used-m)
447 448
448 449
449 # Descending 450 # Descending
450 # --------------------------------------------------------------------------- 451 # ---------------------------------------------------------------------------
451 452
452 PHONY += $(subdir-ym) 453 PHONY += $(subdir-ym)
453 $(subdir-ym): 454 $(subdir-ym):
454 $(Q)$(MAKE) $(build)=$@ 455 $(Q)$(MAKE) $(build)=$@
455 456
456 # Add FORCE to the prequisites of a target to force it to be always rebuilt. 457 # Add FORCE to the prequisites of a target to force it to be always rebuilt.
457 # --------------------------------------------------------------------------- 458 # ---------------------------------------------------------------------------
458 459
459 PHONY += FORCE 460 PHONY += FORCE
460 461
461 FORCE: 462 FORCE:
462 463
463 # Read all saved command lines and dependencies for the $(targets) we 464 # Read all saved command lines and dependencies for the $(targets) we
464 # may be building above, using $(if_changed{,_dep}). As an 465 # may be building above, using $(if_changed{,_dep}). As an
465 # optimization, we don't need to read them if the target does not 466 # optimization, we don't need to read them if the target does not
466 # exist, we will rebuild anyway in that case. 467 # exist, we will rebuild anyway in that case.
467 468
468 targets := $(wildcard $(sort $(targets))) 469 targets := $(wildcard $(sort $(targets)))
469 cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) 470 cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
470 471
471 ifneq ($(cmd_files),) 472 ifneq ($(cmd_files),)
472 include $(cmd_files) 473 include $(cmd_files)
473 endif 474 endif
474 475
475 # Declare the contents of the .PHONY variable as phony. We keep that 476 # Declare the contents of the .PHONY variable as phony. We keep that
476 # information in a variable se we can use it in if_changed and friends. 477 # information in a variable se we can use it in if_changed and friends.
477 478
478 .PHONY: $(PHONY) 479 .PHONY: $(PHONY)
479 480
scripts/Makefile.lib
1 # Backward compatibility 1 # Backward compatibility
2 asflags-y += $(EXTRA_AFLAGS) 2 asflags-y += $(EXTRA_AFLAGS)
3 ccflags-y += $(EXTRA_CFLAGS) 3 ccflags-y += $(EXTRA_CFLAGS)
4 cppflags-y += $(EXTRA_CPPFLAGS) 4 cppflags-y += $(EXTRA_CPPFLAGS)
5 ldflags-y += $(EXTRA_LDFLAGS) 5 ldflags-y += $(EXTRA_LDFLAGS)
6 6
7 # 7 #
8 # flags that take effect in sub directories 8 # flags that take effect in sub directories
9 export KBUILD_SUBDIR_ASFLAGS := $(KBUILD_SUBDIR_ASFLAGS) $(subdir-asflags-y) 9 export KBUILD_SUBDIR_ASFLAGS := $(KBUILD_SUBDIR_ASFLAGS) $(subdir-asflags-y)
10 export KBUILD_SUBDIR_CCFLAGS := $(KBUILD_SUBDIR_CCFLAGS) $(subdir-ccflags-y) 10 export KBUILD_SUBDIR_CCFLAGS := $(KBUILD_SUBDIR_CCFLAGS) $(subdir-ccflags-y)
11 11
12 # Figure out what we need to build from the various variables 12 # Figure out what we need to build from the various variables
13 # =========================================================================== 13 # ===========================================================================
14 14
15 # When an object is listed to be built compiled-in and modular, 15 # When an object is listed to be built compiled-in and modular,
16 # only build the compiled-in version 16 # only build the compiled-in version
17 17
18 obj-m := $(filter-out $(obj-y),$(obj-m)) 18 obj-m := $(filter-out $(obj-y),$(obj-m))
19 19
20 # Libraries are always collected in one lib file. 20 # Libraries are always collected in one lib file.
21 # Filter out objects already built-in 21 # Filter out objects already built-in
22 22
23 lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m))) 23 lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
24 24
25 25
26 # Handle objects in subdirs 26 # Handle objects in subdirs
27 # --------------------------------------------------------------------------- 27 # ---------------------------------------------------------------------------
28 # o if we encounter foo/ in $(obj-y), replace it by foo/built-in.o 28 # o if we encounter foo/ in $(obj-y), replace it by foo/built-in.o
29 # and add the directory to the list of dirs to descend into: $(subdir-y) 29 # and add the directory to the list of dirs to descend into: $(subdir-y)
30 # o if we encounter foo/ in $(obj-m), remove it from $(obj-m) 30 # o if we encounter foo/ in $(obj-m), remove it from $(obj-m)
31 # and add the directory to the list of dirs to descend into: $(subdir-m) 31 # and add the directory to the list of dirs to descend into: $(subdir-m)
32 32
33 # Determine modorder. 33 # Determine modorder.
34 # Unfortunately, we don't have information about ordering between -y 34 # Unfortunately, we don't have information about ordering between -y
35 # and -m subdirs. Just put -y's first. 35 # and -m subdirs. Just put -y's first.
36 modorder := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m:.o=.ko)) 36 modorder := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m:.o=.ko))
37 37
38 __subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y))) 38 __subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y)))
39 subdir-y += $(__subdir-y) 39 subdir-y += $(__subdir-y)
40 __subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m))) 40 __subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m)))
41 subdir-m += $(__subdir-m) 41 subdir-m += $(__subdir-m)
42 obj-y := $(patsubst %/, %/built-in.o, $(obj-y)) 42 obj-y := $(patsubst %/, %/built-in.o, $(obj-y))
43 obj-m := $(filter-out %/, $(obj-m)) 43 obj-m := $(filter-out %/, $(obj-m))
44 44
45 # Subdirectories we need to descend into 45 # Subdirectories we need to descend into
46 46
47 subdir-ym := $(sort $(subdir-y) $(subdir-m)) 47 subdir-ym := $(sort $(subdir-y) $(subdir-m))
48 48
49 # if $(foo-objs) exists, foo.o is a composite object 49 # if $(foo-objs) exists, foo.o is a composite object
50 multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m)))) 50 multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
51 multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m)))) 51 multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
52 multi-used := $(multi-used-y) $(multi-used-m) 52 multi-used := $(multi-used-y) $(multi-used-m)
53 single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m))) 53 single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m)))
54 54
55 # Build list of the parts of our composite objects, our composite 55 # Build list of the parts of our composite objects, our composite
56 # objects depend on those (obviously) 56 # objects depend on those (obviously)
57 multi-objs-y := $(foreach m, $(multi-used-y), $($(m:.o=-objs)) $($(m:.o=-y))) 57 multi-objs-y := $(foreach m, $(multi-used-y), $($(m:.o=-objs)) $($(m:.o=-y)))
58 multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y))) 58 multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y)))
59 multi-objs := $(multi-objs-y) $(multi-objs-m) 59 multi-objs := $(multi-objs-y) $(multi-objs-m)
60 60
61 # $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to 61 # $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to
62 # tell kbuild to descend 62 # tell kbuild to descend
63 subdir-obj-y := $(filter %/built-in.o, $(obj-y)) 63 subdir-obj-y := $(filter %/built-in.o, $(obj-y))
64 64
65 # $(obj-dirs) is a list of directories that contain object files 65 # $(obj-dirs) is a list of directories that contain object files
66 obj-dirs := $(dir $(multi-objs) $(subdir-obj-y)) 66 obj-dirs := $(dir $(multi-objs) $(subdir-obj-y))
67 67
68 # Replace multi-part objects by their individual parts, look at local dir only 68 # Replace multi-part objects by their individual parts, look at local dir only
69 real-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) $(extra-y) 69 real-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) $(extra-y)
70 real-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) 70 real-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m)))
71 71
72 # Add subdir path 72 # Add subdir path
73 73
74 extra-y := $(addprefix $(obj)/,$(extra-y)) 74 extra-y := $(addprefix $(obj)/,$(extra-y))
75 always := $(addprefix $(obj)/,$(always)) 75 always := $(addprefix $(obj)/,$(always))
76 targets := $(addprefix $(obj)/,$(targets)) 76 targets := $(addprefix $(obj)/,$(targets))
77 modorder := $(addprefix $(obj)/,$(modorder)) 77 modorder := $(addprefix $(obj)/,$(modorder))
78 obj-y := $(addprefix $(obj)/,$(obj-y)) 78 obj-y := $(addprefix $(obj)/,$(obj-y))
79 obj-m := $(addprefix $(obj)/,$(obj-m)) 79 obj-m := $(addprefix $(obj)/,$(obj-m))
80 lib-y := $(addprefix $(obj)/,$(lib-y)) 80 lib-y := $(addprefix $(obj)/,$(lib-y))
81 subdir-obj-y := $(addprefix $(obj)/,$(subdir-obj-y)) 81 subdir-obj-y := $(addprefix $(obj)/,$(subdir-obj-y))
82 real-objs-y := $(addprefix $(obj)/,$(real-objs-y)) 82 real-objs-y := $(addprefix $(obj)/,$(real-objs-y))
83 real-objs-m := $(addprefix $(obj)/,$(real-objs-m)) 83 real-objs-m := $(addprefix $(obj)/,$(real-objs-m))
84 single-used-m := $(addprefix $(obj)/,$(single-used-m)) 84 single-used-m := $(addprefix $(obj)/,$(single-used-m))
85 multi-used-y := $(addprefix $(obj)/,$(multi-used-y)) 85 multi-used-y := $(addprefix $(obj)/,$(multi-used-y))
86 multi-used-m := $(addprefix $(obj)/,$(multi-used-m)) 86 multi-used-m := $(addprefix $(obj)/,$(multi-used-m))
87 multi-objs-y := $(addprefix $(obj)/,$(multi-objs-y)) 87 multi-objs-y := $(addprefix $(obj)/,$(multi-objs-y))
88 multi-objs-m := $(addprefix $(obj)/,$(multi-objs-m)) 88 multi-objs-m := $(addprefix $(obj)/,$(multi-objs-m))
89 subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) 89 subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
90 obj-dirs := $(addprefix $(obj)/,$(obj-dirs)) 90 obj-dirs := $(addprefix $(obj)/,$(obj-dirs))
91 91
92 # These flags are needed for modversions and compiling, so we define them here 92 # These flags are needed for modversions and compiling, so we define them here
93 # already 93 # already
94 # $(modname_flags) #defines KBUILD_MODNAME as the name of the module it will 94 # $(modname_flags) #defines KBUILD_MODNAME as the name of the module it will
95 # end up in (or would, if it gets compiled in) 95 # end up in (or would, if it gets compiled in)
96 # Note: Files that end up in two or more modules are compiled without the 96 # Note: Files that end up in two or more modules are compiled without the
97 # KBUILD_MODNAME definition. The reason is that any made-up name would 97 # KBUILD_MODNAME definition. The reason is that any made-up name would
98 # differ in different configs. 98 # differ in different configs.
99 name-fix = $(subst $(comma),_,$(subst -,_,$1)) 99 name-fix = $(subst $(comma),_,$(subst -,_,$1))
100 basename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(basetarget)))" 100 basename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(basetarget)))"
101 modname_flags = $(if $(filter 1,$(words $(modname))),\ 101 modname_flags = $(if $(filter 1,$(words $(modname))),\
102 -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))") 102 -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))")
103 103
104 orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(KBUILD_SUBDIR_CCFLAGS) \ 104 orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(KBUILD_SUBDIR_CCFLAGS) \
105 $(ccflags-y) $(CFLAGS_$(basetarget).o) 105 $(ccflags-y) $(CFLAGS_$(basetarget).o)
106 _c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags)) 106 _c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags))
107 _a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(KBUILD_SUBDIR_ASFLAGS) \ 107 _a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(KBUILD_SUBDIR_ASFLAGS) \
108 $(asflags-y) $(AFLAGS_$(basetarget).o) 108 $(asflags-y) $(AFLAGS_$(basetarget).o)
109 _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F)) 109 _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F))
110 110
111 # 111 #
112 # Enable gcov profiling flags for a file, directory or for all files depending 112 # Enable gcov profiling flags for a file, directory or for all files depending
113 # on variables GCOV_PROFILE_obj.o, GCOV_PROFILE and CONFIG_GCOV_PROFILE_ALL 113 # on variables GCOV_PROFILE_obj.o, GCOV_PROFILE and CONFIG_GCOV_PROFILE_ALL
114 # (in this order) 114 # (in this order)
115 # 115 #
116 ifeq ($(CONFIG_GCOV_KERNEL),y) 116 ifeq ($(CONFIG_GCOV_KERNEL),y)
117 _c_flags += $(if $(patsubst n%,, \ 117 _c_flags += $(if $(patsubst n%,, \
118 $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \ 118 $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \
119 $(CFLAGS_GCOV)) 119 $(CFLAGS_GCOV))
120 endif 120 endif
121 121
122 ifdef CONFIG_SYMBOL_PREFIX
123 _sym_flags = -DSYMBOL_PREFIX=$(patsubst "%",%,$(CONFIG_SYMBOL_PREFIX))
124 _cpp_flags += $(_sym_flags)
125 _a_flags += $(_sym_flags)
126 endif
127
128
129 # If building the kernel in a separate objtree expand all occurrences 122 # If building the kernel in a separate objtree expand all occurrences
130 # of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/'). 123 # of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/').
131 124
132 ifeq ($(KBUILD_SRC),) 125 ifeq ($(KBUILD_SRC),)
133 __c_flags = $(_c_flags) 126 __c_flags = $(_c_flags)
134 __a_flags = $(_a_flags) 127 __a_flags = $(_a_flags)
135 __cpp_flags = $(_cpp_flags) 128 __cpp_flags = $(_cpp_flags)
136 else 129 else
137 130
138 # -I$(obj) locates generated .h files 131 # -I$(obj) locates generated .h files
139 # $(call addtree,-I$(obj)) locates .h files in srctree, from generated .c files 132 # $(call addtree,-I$(obj)) locates .h files in srctree, from generated .c files
140 # and locates generated .h files 133 # and locates generated .h files
141 # FIXME: Replace both with specific CFLAGS* statements in the makefiles 134 # FIXME: Replace both with specific CFLAGS* statements in the makefiles
142 __c_flags = $(call addtree,-I$(obj)) $(call flags,_c_flags) 135 __c_flags = $(call addtree,-I$(obj)) $(call flags,_c_flags)
143 __a_flags = $(call flags,_a_flags) 136 __a_flags = $(call flags,_a_flags)
144 __cpp_flags = $(call flags,_cpp_flags) 137 __cpp_flags = $(call flags,_cpp_flags)
145 endif 138 endif
146 139
147 c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ 140 c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
148 $(__c_flags) $(modkern_cflags) \ 141 $(__c_flags) $(modkern_cflags) \
149 -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags) 142 -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags)
150 143
151 a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ 144 a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
152 $(__a_flags) $(modkern_aflags) 145 $(__a_flags) $(modkern_aflags)
153 146
154 cpp_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ 147 cpp_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
155 $(__cpp_flags) 148 $(__cpp_flags)
156 149
157 ld_flags = $(LDFLAGS) $(ldflags-y) 150 ld_flags = $(LDFLAGS) $(ldflags-y)
158 151
159 dtc_cpp_flags = -Wp,-MD,$(depfile).pre -nostdinc \ 152 dtc_cpp_flags = -Wp,-MD,$(depfile).pre -nostdinc \
160 -I$(srctree)/arch/$(SRCARCH)/boot/dts \ 153 -I$(srctree)/arch/$(SRCARCH)/boot/dts \
161 -I$(srctree)/arch/$(SRCARCH)/boot/dts/include \ 154 -I$(srctree)/arch/$(SRCARCH)/boot/dts/include \
162 -undef -D__DTS__ 155 -undef -D__DTS__
163 156
164 # Finds the multi-part object the current object will be linked into 157 # Finds the multi-part object the current object will be linked into
165 modname-multi = $(sort $(foreach m,$(multi-used),\ 158 modname-multi = $(sort $(foreach m,$(multi-used),\
166 $(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=)))) 159 $(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=))))
167 160
168 ifdef REGENERATE_PARSERS 161 ifdef REGENERATE_PARSERS
169 162
170 # GPERF 163 # GPERF
171 # --------------------------------------------------------------------------- 164 # ---------------------------------------------------------------------------
172 quiet_cmd_gperf = GPERF $@ 165 quiet_cmd_gperf = GPERF $@
173 cmd_gperf = gperf -t --output-file $@ -a -C -E -g -k 1,3,$$ -p -t $< 166 cmd_gperf = gperf -t --output-file $@ -a -C -E -g -k 1,3,$$ -p -t $<
174 167
175 .PRECIOUS: $(src)/%.hash.c_shipped 168 .PRECIOUS: $(src)/%.hash.c_shipped
176 $(src)/%.hash.c_shipped: $(src)/%.gperf 169 $(src)/%.hash.c_shipped: $(src)/%.gperf
177 $(call cmd,gperf) 170 $(call cmd,gperf)
178 171
179 # LEX 172 # LEX
180 # --------------------------------------------------------------------------- 173 # ---------------------------------------------------------------------------
181 LEX_PREFIX = $(if $(LEX_PREFIX_${baseprereq}),$(LEX_PREFIX_${baseprereq}),yy) 174 LEX_PREFIX = $(if $(LEX_PREFIX_${baseprereq}),$(LEX_PREFIX_${baseprereq}),yy)
182 175
183 quiet_cmd_flex = LEX $@ 176 quiet_cmd_flex = LEX $@
184 cmd_flex = flex -o$@ -L -P $(LEX_PREFIX) $< 177 cmd_flex = flex -o$@ -L -P $(LEX_PREFIX) $<
185 178
186 .PRECIOUS: $(src)/%.lex.c_shipped 179 .PRECIOUS: $(src)/%.lex.c_shipped
187 $(src)/%.lex.c_shipped: $(src)/%.l 180 $(src)/%.lex.c_shipped: $(src)/%.l
188 $(call cmd,flex) 181 $(call cmd,flex)
189 182
190 # YACC 183 # YACC
191 # --------------------------------------------------------------------------- 184 # ---------------------------------------------------------------------------
192 YACC_PREFIX = $(if $(YACC_PREFIX_${baseprereq}),$(YACC_PREFIX_${baseprereq}),yy) 185 YACC_PREFIX = $(if $(YACC_PREFIX_${baseprereq}),$(YACC_PREFIX_${baseprereq}),yy)
193 186
194 quiet_cmd_bison = YACC $@ 187 quiet_cmd_bison = YACC $@
195 cmd_bison = bison -o$@ -t -l -p $(YACC_PREFIX) $< 188 cmd_bison = bison -o$@ -t -l -p $(YACC_PREFIX) $<
196 189
197 .PRECIOUS: $(src)/%.tab.c_shipped 190 .PRECIOUS: $(src)/%.tab.c_shipped
198 $(src)/%.tab.c_shipped: $(src)/%.y 191 $(src)/%.tab.c_shipped: $(src)/%.y
199 $(call cmd,bison) 192 $(call cmd,bison)
200 193
201 quiet_cmd_bison_h = YACC $@ 194 quiet_cmd_bison_h = YACC $@
202 cmd_bison_h = bison -o/dev/null --defines=$@ -t -l -p $(YACC_PREFIX) $< 195 cmd_bison_h = bison -o/dev/null --defines=$@ -t -l -p $(YACC_PREFIX) $<
203 196
204 .PRECIOUS: $(src)/%.tab.h_shipped 197 .PRECIOUS: $(src)/%.tab.h_shipped
205 $(src)/%.tab.h_shipped: $(src)/%.y 198 $(src)/%.tab.h_shipped: $(src)/%.y
206 $(call cmd,bison_h) 199 $(call cmd,bison_h)
207 200
208 endif 201 endif
209 202
210 # Shipped files 203 # Shipped files
211 # =========================================================================== 204 # ===========================================================================
212 205
213 quiet_cmd_shipped = SHIPPED $@ 206 quiet_cmd_shipped = SHIPPED $@
214 cmd_shipped = cat $< > $@ 207 cmd_shipped = cat $< > $@
215 208
216 $(obj)/%: $(src)/%_shipped 209 $(obj)/%: $(src)/%_shipped
217 $(call cmd,shipped) 210 $(call cmd,shipped)
218 211
219 # Commands useful for building a boot image 212 # Commands useful for building a boot image
220 # =========================================================================== 213 # ===========================================================================
221 # 214 #
222 # Use as following: 215 # Use as following:
223 # 216 #
224 # target: source(s) FORCE 217 # target: source(s) FORCE
225 # $(if_changed,ld/objcopy/gzip) 218 # $(if_changed,ld/objcopy/gzip)
226 # 219 #
227 # and add target to extra-y so that we know we have to 220 # and add target to extra-y so that we know we have to
228 # read in the saved command line 221 # read in the saved command line
229 222
230 # Linking 223 # Linking
231 # --------------------------------------------------------------------------- 224 # ---------------------------------------------------------------------------
232 225
233 quiet_cmd_ld = LD $@ 226 quiet_cmd_ld = LD $@
234 cmd_ld = $(LD) $(LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F)) \ 227 cmd_ld = $(LD) $(LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F)) \
235 $(filter-out FORCE,$^) -o $@ 228 $(filter-out FORCE,$^) -o $@
236 229
237 # Objcopy 230 # Objcopy
238 # --------------------------------------------------------------------------- 231 # ---------------------------------------------------------------------------
239 232
240 quiet_cmd_objcopy = OBJCOPY $@ 233 quiet_cmd_objcopy = OBJCOPY $@
241 cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ 234 cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
242 235
243 # Gzip 236 # Gzip
244 # --------------------------------------------------------------------------- 237 # ---------------------------------------------------------------------------
245 238
246 quiet_cmd_gzip = GZIP $@ 239 quiet_cmd_gzip = GZIP $@
247 cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -n -f -9 > $@) || \ 240 cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -n -f -9 > $@) || \
248 (rm -f $@ ; false) 241 (rm -f $@ ; false)
249 242
250 # DTC 243 # DTC
251 # --------------------------------------------------------------------------- 244 # ---------------------------------------------------------------------------
252 245
253 # Generate an assembly file to wrap the output of the device tree compiler 246 # Generate an assembly file to wrap the output of the device tree compiler
254 quiet_cmd_dt_S_dtb= DTB $@ 247 quiet_cmd_dt_S_dtb= DTB $@
255 cmd_dt_S_dtb= \ 248 cmd_dt_S_dtb= \
256 ( \ 249 ( \
257 echo '\#include <asm-generic/vmlinux.lds.h>'; \ 250 echo '\#include <asm-generic/vmlinux.lds.h>'; \
258 echo '.section .dtb.init.rodata,"a"'; \ 251 echo '.section .dtb.init.rodata,"a"'; \
259 echo '.balign STRUCT_ALIGNMENT'; \ 252 echo '.balign STRUCT_ALIGNMENT'; \
260 echo '.global __dtb_$(*F)_begin'; \ 253 echo '.global __dtb_$(*F)_begin'; \
261 echo '__dtb_$(*F)_begin:'; \ 254 echo '__dtb_$(*F)_begin:'; \
262 echo '.incbin "$<" '; \ 255 echo '.incbin "$<" '; \
263 echo '__dtb_$(*F)_end:'; \ 256 echo '__dtb_$(*F)_end:'; \
264 echo '.global __dtb_$(*F)_end'; \ 257 echo '.global __dtb_$(*F)_end'; \
265 echo '.balign STRUCT_ALIGNMENT'; \ 258 echo '.balign STRUCT_ALIGNMENT'; \
266 ) > $@ 259 ) > $@
267 260
268 $(obj)/%.dtb.S: $(obj)/%.dtb 261 $(obj)/%.dtb.S: $(obj)/%.dtb
269 $(call cmd,dt_S_dtb) 262 $(call cmd,dt_S_dtb)
270 263
271 quiet_cmd_dtc = DTC $@ 264 quiet_cmd_dtc = DTC $@
272 cmd_dtc = $(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \ 265 cmd_dtc = $(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
273 $(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 \ 266 $(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 \
274 -i $(srctree)/arch/$(SRCARCH)/boot/dts $(DTC_FLAGS) \ 267 -i $(srctree)/arch/$(SRCARCH)/boot/dts $(DTC_FLAGS) \
275 -d $(depfile).dtc $(dtc-tmp) ; \ 268 -d $(depfile).dtc $(dtc-tmp) ; \
276 cat $(depfile).pre $(depfile).dtc > $(depfile) 269 cat $(depfile).pre $(depfile).dtc > $(depfile)
277 270
278 $(obj)/%.dtb: $(src)/%.dts FORCE 271 $(obj)/%.dtb: $(src)/%.dts FORCE
279 $(call if_changed_dep,dtc) 272 $(call if_changed_dep,dtc)
280 273
281 dtc-tmp = $(subst $(comma),_,$(dot-target).dts) 274 dtc-tmp = $(subst $(comma),_,$(dot-target).dts)
282 275
283 # Bzip2 276 # Bzip2
284 # --------------------------------------------------------------------------- 277 # ---------------------------------------------------------------------------
285 278
286 # Bzip2 and LZMA do not include size in file... so we have to fake that; 279 # Bzip2 and LZMA do not include size in file... so we have to fake that;
287 # append the size as a 32-bit littleendian number as gzip does. 280 # append the size as a 32-bit littleendian number as gzip does.
288 size_append = printf $(shell \ 281 size_append = printf $(shell \
289 dec_size=0; \ 282 dec_size=0; \
290 for F in $1; do \ 283 for F in $1; do \
291 fsize=$$(stat -c "%s" $$F); \ 284 fsize=$$(stat -c "%s" $$F); \
292 dec_size=$$(expr $$dec_size + $$fsize); \ 285 dec_size=$$(expr $$dec_size + $$fsize); \
293 done; \ 286 done; \
294 printf "%08x\n" $$dec_size | \ 287 printf "%08x\n" $$dec_size | \
295 sed 's/\(..\)/\1 /g' | { \ 288 sed 's/\(..\)/\1 /g' | { \
296 read ch0 ch1 ch2 ch3; \ 289 read ch0 ch1 ch2 ch3; \
297 for ch in $$ch3 $$ch2 $$ch1 $$ch0; do \ 290 for ch in $$ch3 $$ch2 $$ch1 $$ch0; do \
298 printf '%s%03o' '\\' $$((0x$$ch)); \ 291 printf '%s%03o' '\\' $$((0x$$ch)); \
299 done; \ 292 done; \
300 } \ 293 } \
301 ) 294 )
302 295
303 quiet_cmd_bzip2 = BZIP2 $@ 296 quiet_cmd_bzip2 = BZIP2 $@
304 cmd_bzip2 = (cat $(filter-out FORCE,$^) | \ 297 cmd_bzip2 = (cat $(filter-out FORCE,$^) | \
305 bzip2 -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \ 298 bzip2 -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
306 (rm -f $@ ; false) 299 (rm -f $@ ; false)
307 300
308 # Lzma 301 # Lzma
309 # --------------------------------------------------------------------------- 302 # ---------------------------------------------------------------------------
310 303
311 quiet_cmd_lzma = LZMA $@ 304 quiet_cmd_lzma = LZMA $@
312 cmd_lzma = (cat $(filter-out FORCE,$^) | \ 305 cmd_lzma = (cat $(filter-out FORCE,$^) | \
313 lzma -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \ 306 lzma -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
314 (rm -f $@ ; false) 307 (rm -f $@ ; false)
315 308
316 quiet_cmd_lzo = LZO $@ 309 quiet_cmd_lzo = LZO $@
317 cmd_lzo = (cat $(filter-out FORCE,$^) | \ 310 cmd_lzo = (cat $(filter-out FORCE,$^) | \
318 lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \ 311 lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
319 (rm -f $@ ; false) 312 (rm -f $@ ; false)
320 313
321 # U-Boot mkimage 314 # U-Boot mkimage
322 # --------------------------------------------------------------------------- 315 # ---------------------------------------------------------------------------
323 316
324 MKIMAGE := $(srctree)/scripts/mkuboot.sh 317 MKIMAGE := $(srctree)/scripts/mkuboot.sh
325 318
326 # SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces 319 # SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces
327 # the number of overrides in arch makefiles 320 # the number of overrides in arch makefiles
328 UIMAGE_ARCH ?= $(SRCARCH) 321 UIMAGE_ARCH ?= $(SRCARCH)
329 UIMAGE_COMPRESSION ?= $(if $(2),$(2),none) 322 UIMAGE_COMPRESSION ?= $(if $(2),$(2),none)
330 UIMAGE_OPTS-y ?= 323 UIMAGE_OPTS-y ?=
331 UIMAGE_TYPE ?= kernel 324 UIMAGE_TYPE ?= kernel
332 UIMAGE_LOADADDR ?= arch_must_set_this 325 UIMAGE_LOADADDR ?= arch_must_set_this
333 UIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR) 326 UIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR)
334 UIMAGE_NAME ?= 'Linux-$(KERNELRELEASE)' 327 UIMAGE_NAME ?= 'Linux-$(KERNELRELEASE)'
335 UIMAGE_IN ?= $< 328 UIMAGE_IN ?= $<
336 UIMAGE_OUT ?= $@ 329 UIMAGE_OUT ?= $@
337 330
338 quiet_cmd_uimage = UIMAGE $(UIMAGE_OUT) 331 quiet_cmd_uimage = UIMAGE $(UIMAGE_OUT)
339 cmd_uimage = $(CONFIG_SHELL) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \ 332 cmd_uimage = $(CONFIG_SHELL) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \
340 -C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \ 333 -C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \
341 -T $(UIMAGE_TYPE) \ 334 -T $(UIMAGE_TYPE) \
342 -a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \ 335 -a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \
343 -n $(UIMAGE_NAME) -d $(UIMAGE_IN) $(UIMAGE_OUT) 336 -n $(UIMAGE_NAME) -d $(UIMAGE_IN) $(UIMAGE_OUT)
344 337
345 # XZ 338 # XZ
346 # --------------------------------------------------------------------------- 339 # ---------------------------------------------------------------------------
347 # Use xzkern to compress the kernel image and xzmisc to compress other things. 340 # Use xzkern to compress the kernel image and xzmisc to compress other things.
348 # 341 #
349 # xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage 342 # xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage
350 # of the kernel decompressor. A BCJ filter is used if it is available for 343 # of the kernel decompressor. A BCJ filter is used if it is available for
351 # the target architecture. xzkern also appends uncompressed size of the data 344 # the target architecture. xzkern also appends uncompressed size of the data
352 # using size_append. The .xz format has the size information available at 345 # using size_append. The .xz format has the size information available at
353 # the end of the file too, but it's in more complex format and it's good to 346 # the end of the file too, but it's in more complex format and it's good to
354 # avoid changing the part of the boot code that reads the uncompressed size. 347 # avoid changing the part of the boot code that reads the uncompressed size.
355 # Note that the bytes added by size_append will make the xz tool think that 348 # Note that the bytes added by size_append will make the xz tool think that
356 # the file is corrupt. This is expected. 349 # the file is corrupt. This is expected.
357 # 350 #
358 # xzmisc doesn't use size_append, so it can be used to create normal .xz 351 # xzmisc doesn't use size_append, so it can be used to create normal .xz
359 # files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very 352 # files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very
360 # big dictionary would increase the memory usage too much in the multi-call 353 # big dictionary would increase the memory usage too much in the multi-call
361 # decompression mode. A BCJ filter isn't used either. 354 # decompression mode. A BCJ filter isn't used either.
362 quiet_cmd_xzkern = XZKERN $@ 355 quiet_cmd_xzkern = XZKERN $@
363 cmd_xzkern = (cat $(filter-out FORCE,$^) | \ 356 cmd_xzkern = (cat $(filter-out FORCE,$^) | \
364 sh $(srctree)/scripts/xz_wrap.sh && \ 357 sh $(srctree)/scripts/xz_wrap.sh && \
365 $(call size_append, $(filter-out FORCE,$^))) > $@ || \ 358 $(call size_append, $(filter-out FORCE,$^))) > $@ || \
366 (rm -f $@ ; false) 359 (rm -f $@ ; false)
367 360
368 quiet_cmd_xzmisc = XZMISC $@ 361 quiet_cmd_xzmisc = XZMISC $@
369 cmd_xzmisc = (cat $(filter-out FORCE,$^) | \ 362 cmd_xzmisc = (cat $(filter-out FORCE,$^) | \
370 xz --check=crc32 --lzma2=dict=1MiB) > $@ || \ 363 xz --check=crc32 --lzma2=dict=1MiB) > $@ || \
371 (rm -f $@ ; false) 364 (rm -f $@ ; false)
372 365
373 # misc stuff 366 # misc stuff
374 # --------------------------------------------------------------------------- 367 # ---------------------------------------------------------------------------
375 quote:=" 368 quote:="
376 369
scripts/Makefile.modpost
1 # =========================================================================== 1 # ===========================================================================
2 # Module versions 2 # Module versions
3 # =========================================================================== 3 # ===========================================================================
4 # 4 #
5 # Stage one of module building created the following: 5 # Stage one of module building created the following:
6 # a) The individual .o files used for the module 6 # a) The individual .o files used for the module
7 # b) A <module>.o file which is the .o files above linked together 7 # b) A <module>.o file which is the .o files above linked together
8 # c) A <module>.mod file in $(MODVERDIR)/, listing the name of the 8 # c) A <module>.mod file in $(MODVERDIR)/, listing the name of the
9 # the preliminary <module>.o file, plus all .o files 9 # the preliminary <module>.o file, plus all .o files
10 10
11 # Stage 2 is handled by this file and does the following 11 # Stage 2 is handled by this file and does the following
12 # 1) Find all modules from the files listed in $(MODVERDIR)/ 12 # 1) Find all modules from the files listed in $(MODVERDIR)/
13 # 2) modpost is then used to 13 # 2) modpost is then used to
14 # 3) create one <module>.mod.c file pr. module 14 # 3) create one <module>.mod.c file pr. module
15 # 4) create one Module.symvers file with CRC for all exported symbols 15 # 4) create one Module.symvers file with CRC for all exported symbols
16 # 5) compile all <module>.mod.c files 16 # 5) compile all <module>.mod.c files
17 # 6) final link of the module to a <module.ko> file 17 # 6) final link of the module to a <module.ko> file
18 18
19 # Step 3 is used to place certain information in the module's ELF 19 # Step 3 is used to place certain information in the module's ELF
20 # section, including information such as: 20 # section, including information such as:
21 # Version magic (see include/linux/vermagic.h for full details) 21 # Version magic (see include/linux/vermagic.h for full details)
22 # - Kernel release 22 # - Kernel release
23 # - SMP is CONFIG_SMP 23 # - SMP is CONFIG_SMP
24 # - PREEMPT is CONFIG_PREEMPT 24 # - PREEMPT is CONFIG_PREEMPT
25 # - GCC Version 25 # - GCC Version
26 # Module info 26 # Module info
27 # - Module version (MODULE_VERSION) 27 # - Module version (MODULE_VERSION)
28 # - Module alias'es (MODULE_ALIAS) 28 # - Module alias'es (MODULE_ALIAS)
29 # - Module license (MODULE_LICENSE) 29 # - Module license (MODULE_LICENSE)
30 # - See include/linux/module.h for more details 30 # - See include/linux/module.h for more details
31 31
32 # Step 4 is solely used to allow module versioning in external modules, 32 # Step 4 is solely used to allow module versioning in external modules,
33 # where the CRC of each module is retrieved from the Module.symvers file. 33 # where the CRC of each module is retrieved from the Module.symvers file.
34 34
35 # KBUILD_MODPOST_WARN can be set to avoid error out in case of undefined 35 # KBUILD_MODPOST_WARN can be set to avoid error out in case of undefined
36 # symbols in the final module linking stage 36 # symbols in the final module linking stage
37 # KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules. 37 # KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules.
38 # This is solely useful to speed up test compiles 38 # This is solely useful to speed up test compiles
39 PHONY := _modpost 39 PHONY := _modpost
40 _modpost: __modpost 40 _modpost: __modpost
41 41
42 include include/config/auto.conf 42 include include/config/auto.conf
43 include scripts/Kbuild.include 43 include scripts/Kbuild.include
44 44
45 # When building external modules load the Kbuild file to retrieve EXTRA_SYMBOLS info 45 # When building external modules load the Kbuild file to retrieve EXTRA_SYMBOLS info
46 ifneq ($(KBUILD_EXTMOD),) 46 ifneq ($(KBUILD_EXTMOD),)
47 47
48 # set src + obj - they may be used when building the .mod.c file 48 # set src + obj - they may be used when building the .mod.c file
49 obj := $(KBUILD_EXTMOD) 49 obj := $(KBUILD_EXTMOD)
50 src := $(obj) 50 src := $(obj)
51 51
52 # Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS 52 # Include the module's Makefile to find KBUILD_EXTRA_SYMBOLS
53 include $(if $(wildcard $(KBUILD_EXTMOD)/Kbuild), \ 53 include $(if $(wildcard $(KBUILD_EXTMOD)/Kbuild), \
54 $(KBUILD_EXTMOD)/Kbuild, $(KBUILD_EXTMOD)/Makefile) 54 $(KBUILD_EXTMOD)/Kbuild, $(KBUILD_EXTMOD)/Makefile)
55 endif 55 endif
56 56
57 include scripts/Makefile.lib 57 include scripts/Makefile.lib
58 58
59 kernelsymfile := $(objtree)/Module.symvers 59 kernelsymfile := $(objtree)/Module.symvers
60 modulesymfile := $(firstword $(KBUILD_EXTMOD))/Module.symvers 60 modulesymfile := $(firstword $(KBUILD_EXTMOD))/Module.symvers
61 61
62 # Step 1), find all modules listed in $(MODVERDIR)/ 62 # Step 1), find all modules listed in $(MODVERDIR)/
63 __modules := $(sort $(shell grep -h '\.ko$$' /dev/null $(wildcard $(MODVERDIR)/*.mod))) 63 MODLISTCMD := find $(MODVERDIR) -name '*.mod' | xargs -r grep -h '\.ko$$' | sort -u
64 __modules := $(shell $(MODLISTCMD))
64 modules := $(patsubst %.o,%.ko, $(wildcard $(__modules:.ko=.o))) 65 modules := $(patsubst %.o,%.ko, $(wildcard $(__modules:.ko=.o)))
65 66
66 # Stop after building .o files if NOFINAL is set. Makes compile tests quicker 67 # Stop after building .o files if NOFINAL is set. Makes compile tests quicker
67 _modpost: $(if $(KBUILD_MODPOST_NOFINAL), $(modules:.ko:.o),$(modules)) 68 _modpost: $(if $(KBUILD_MODPOST_NOFINAL), $(modules:.ko:.o),$(modules))
68 69
69 # Step 2), invoke modpost 70 # Step 2), invoke modpost
70 # Includes step 3,4 71 # Includes step 3,4
71 modpost = scripts/mod/modpost \ 72 modpost = scripts/mod/modpost \
72 $(if $(CONFIG_MODVERSIONS),-m) \ 73 $(if $(CONFIG_MODVERSIONS),-m) \
73 $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a,) \ 74 $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a,) \
74 $(if $(KBUILD_EXTMOD),-i,-o) $(kernelsymfile) \ 75 $(if $(KBUILD_EXTMOD),-i,-o) $(kernelsymfile) \
75 $(if $(KBUILD_EXTMOD),-I $(modulesymfile)) \ 76 $(if $(KBUILD_EXTMOD),-I $(modulesymfile)) \
76 $(if $(KBUILD_EXTRA_SYMBOLS), $(patsubst %, -e %,$(KBUILD_EXTRA_SYMBOLS))) \ 77 $(if $(KBUILD_EXTRA_SYMBOLS), $(patsubst %, -e %,$(KBUILD_EXTRA_SYMBOLS))) \
77 $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \ 78 $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \
78 $(if $(CONFIG_DEBUG_SECTION_MISMATCH),,-S) \ 79 $(if $(CONFIG_DEBUG_SECTION_MISMATCH),,-S) \
79 $(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w) 80 $(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w)
80 81
82 # We can go over command line length here, so be careful.
81 quiet_cmd_modpost = MODPOST $(words $(filter-out vmlinux FORCE, $^)) modules 83 quiet_cmd_modpost = MODPOST $(words $(filter-out vmlinux FORCE, $^)) modules
82 cmd_modpost = $(modpost) -s 84 cmd_modpost = $(MODLISTCMD) | sed 's/\.ko$$/.o/' | $(modpost) -s -T -
83 85
84 PHONY += __modpost 86 PHONY += __modpost
85 __modpost: $(modules:.ko=.o) FORCE 87 __modpost: $(modules:.ko=.o) FORCE
86 $(call cmd,modpost) $(wildcard vmlinux) $(filter-out FORCE,$^) 88 $(call cmd,modpost) $(wildcard vmlinux)
87 89
88 quiet_cmd_kernel-mod = MODPOST $@ 90 quiet_cmd_kernel-mod = MODPOST $@
89 cmd_kernel-mod = $(modpost) $@ 91 cmd_kernel-mod = $(modpost) $@
90 92
91 vmlinux.o: FORCE 93 vmlinux.o: FORCE
92 $(call cmd,kernel-mod) 94 $(call cmd,kernel-mod)
93 95
94 # Declare generated files as targets for modpost 96 # Declare generated files as targets for modpost
95 $(symverfile): __modpost ; 97 $(symverfile): __modpost ;
96 $(modules:.ko=.mod.c): __modpost ; 98 $(modules:.ko=.mod.c): __modpost ;
97 99
98 100
99 # Step 5), compile all *.mod.c files 101 # Step 5), compile all *.mod.c files
100 102
101 # modname is set to make c_flags define KBUILD_MODNAME 103 # modname is set to make c_flags define KBUILD_MODNAME
102 modname = $(notdir $(@:.mod.o=)) 104 modname = $(notdir $(@:.mod.o=))
103 105
104 quiet_cmd_cc_o_c = CC $@ 106 quiet_cmd_cc_o_c = CC $@
105 cmd_cc_o_c = $(CC) $(c_flags) $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE) \ 107 cmd_cc_o_c = $(CC) $(c_flags) $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE) \
106 -c -o $@ $< 108 -c -o $@ $<
107 109
108 $(modules:.ko=.mod.o): %.mod.o: %.mod.c FORCE 110 $(modules:.ko=.mod.o): %.mod.o: %.mod.c FORCE
109 $(call if_changed_dep,cc_o_c) 111 $(call if_changed_dep,cc_o_c)
110 112
111 targets += $(modules:.ko=.mod.o) 113 targets += $(modules:.ko=.mod.o)
112 114
113 # Step 6), final link of the modules 115 # Step 6), final link of the modules
114 quiet_cmd_ld_ko_o = LD [M] $@ 116 quiet_cmd_ld_ko_o = LD [M] $@
115 cmd_ld_ko_o = $(LD) -r $(LDFLAGS) \ 117 cmd_ld_ko_o = $(LD) -r $(LDFLAGS) \
116 $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ 118 $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \
117 -o $@ $(filter-out FORCE,$^) 119 -o $@ $(filter-out FORCE,$^)
118 120
119 $(modules): %.ko :%.o %.mod.o FORCE 121 $(modules): %.ko :%.o %.mod.o FORCE
120 $(call if_changed,ld_ko_o) 122 $(call if_changed,ld_ko_o)
121 123
122 targets += $(modules) 124 targets += $(modules)
123 125
124 126
125 # Add FORCE to the prequisites of a target to force it to be always rebuilt. 127 # Add FORCE to the prequisites of a target to force it to be always rebuilt.
126 # --------------------------------------------------------------------------- 128 # ---------------------------------------------------------------------------
127 129
128 PHONY += FORCE 130 PHONY += FORCE
129 131
130 FORCE: 132 FORCE:
131 133
132 # Read all saved command lines and dependencies for the $(targets) we 134 # Read all saved command lines and dependencies for the $(targets) we
133 # may be building above, using $(if_changed{,_dep}). As an 135 # may be building above, using $(if_changed{,_dep}). As an
134 # optimization, we don't need to read them if the target does not 136 # optimization, we don't need to read them if the target does not
135 # exist, we will rebuild anyway in that case. 137 # exist, we will rebuild anyway in that case.
136 138
137 targets := $(wildcard $(sort $(targets))) 139 targets := $(wildcard $(sort $(targets)))
138 cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) 140 cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
139 141
140 ifneq ($(cmd_files),) 142 ifneq ($(cmd_files),)
141 include $(cmd_files) 143 include $(cmd_files)
142 endif 144 endif
143 145
144 146
145 # Declare the contents of the .PHONY variable as phony. We keep that 147 # Declare the contents of the .PHONY variable as phony. We keep that
146 # information in a variable se we can use it in if_changed and friends. 148 # information in a variable se we can use it in if_changed and friends.
147 149
148 .PHONY: $(PHONY) 150 .PHONY: $(PHONY)
149 151
scripts/genksyms/genksyms.c
1 /* Generate kernel symbol version hashes. 1 /* Generate kernel symbol version hashes.
2 Copyright 1996, 1997 Linux International. 2 Copyright 1996, 1997 Linux International.
3 3
4 New implementation contributed by Richard Henderson <rth@tamu.edu> 4 New implementation contributed by Richard Henderson <rth@tamu.edu>
5 Based on original work by Bjorn Ekwall <bj0rn@blox.se> 5 Based on original work by Bjorn Ekwall <bj0rn@blox.se>
6 6
7 This file was part of the Linux modutils 2.4.22: moved back into the 7 This file was part of the Linux modutils 2.4.22: moved back into the
8 kernel sources by Rusty Russell/Kai Germaschewski. 8 kernel sources by Rusty Russell/Kai Germaschewski.
9 9
10 This program is free software; you can redistribute it and/or modify it 10 This program is free software; you can redistribute it and/or modify it
11 under the terms of the GNU General Public License as published by the 11 under the terms of the GNU General Public License as published by the
12 Free Software Foundation; either version 2 of the License, or (at your 12 Free Software Foundation; either version 2 of the License, or (at your
13 option) any later version. 13 option) any later version.
14 14
15 This program is distributed in the hope that it will be useful, but 15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of 16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details. 18 General Public License for more details.
19 19
20 You should have received a copy of the GNU General Public License 20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software Foundation, 21 along with this program; if not, write to the Free Software Foundation,
22 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 22 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 23
24 #include <stdio.h> 24 #include <stdio.h>
25 #include <string.h> 25 #include <string.h>
26 #include <stdlib.h> 26 #include <stdlib.h>
27 #include <unistd.h> 27 #include <unistd.h>
28 #include <assert.h> 28 #include <assert.h>
29 #include <stdarg.h> 29 #include <stdarg.h>
30 #ifdef __GNU_LIBRARY__ 30 #ifdef __GNU_LIBRARY__
31 #include <getopt.h> 31 #include <getopt.h>
32 #endif /* __GNU_LIBRARY__ */ 32 #endif /* __GNU_LIBRARY__ */
33 33
34 #include "genksyms.h" 34 #include "genksyms.h"
35 /*----------------------------------------------------------------------*/ 35 /*----------------------------------------------------------------------*/
36 36
37 #define HASH_BUCKETS 4096 37 #define HASH_BUCKETS 4096
38 38
39 static struct symbol *symtab[HASH_BUCKETS]; 39 static struct symbol *symtab[HASH_BUCKETS];
40 static FILE *debugfile; 40 static FILE *debugfile;
41 41
42 int cur_line = 1; 42 int cur_line = 1;
43 char *cur_filename, *source_file; 43 char *cur_filename, *source_file;
44 int in_source_file; 44 int in_source_file;
45 45
46 static int flag_debug, flag_dump_defs, flag_reference, flag_dump_types, 46 static int flag_debug, flag_dump_defs, flag_reference, flag_dump_types,
47 flag_preserve, flag_warnings; 47 flag_preserve, flag_warnings;
48 static const char *arch = "";
49 static const char *mod_prefix = ""; 48 static const char *mod_prefix = "";
50 49
51 static int errors; 50 static int errors;
52 static int nsyms; 51 static int nsyms;
53 52
54 static struct symbol *expansion_trail; 53 static struct symbol *expansion_trail;
55 static struct symbol *visited_symbols; 54 static struct symbol *visited_symbols;
56 55
57 static const struct { 56 static const struct {
58 int n; 57 int n;
59 const char *name; 58 const char *name;
60 } symbol_types[] = { 59 } symbol_types[] = {
61 [SYM_NORMAL] = { 0, NULL}, 60 [SYM_NORMAL] = { 0, NULL},
62 [SYM_TYPEDEF] = {'t', "typedef"}, 61 [SYM_TYPEDEF] = {'t', "typedef"},
63 [SYM_ENUM] = {'e', "enum"}, 62 [SYM_ENUM] = {'e', "enum"},
64 [SYM_STRUCT] = {'s', "struct"}, 63 [SYM_STRUCT] = {'s', "struct"},
65 [SYM_UNION] = {'u', "union"}, 64 [SYM_UNION] = {'u', "union"},
66 [SYM_ENUM_CONST] = {'E', "enum constant"}, 65 [SYM_ENUM_CONST] = {'E', "enum constant"},
67 }; 66 };
68 67
69 static int equal_list(struct string_list *a, struct string_list *b); 68 static int equal_list(struct string_list *a, struct string_list *b);
70 static void print_list(FILE * f, struct string_list *list); 69 static void print_list(FILE * f, struct string_list *list);
71 static struct string_list *concat_list(struct string_list *start, ...); 70 static struct string_list *concat_list(struct string_list *start, ...);
72 static struct string_list *mk_node(const char *string); 71 static struct string_list *mk_node(const char *string);
73 static void print_location(void); 72 static void print_location(void);
74 static void print_type_name(enum symbol_type type, const char *name); 73 static void print_type_name(enum symbol_type type, const char *name);
75 74
76 /*----------------------------------------------------------------------*/ 75 /*----------------------------------------------------------------------*/
77 76
78 static const unsigned int crctab32[] = { 77 static const unsigned int crctab32[] = {
79 0x00000000U, 0x77073096U, 0xee0e612cU, 0x990951baU, 0x076dc419U, 78 0x00000000U, 0x77073096U, 0xee0e612cU, 0x990951baU, 0x076dc419U,
80 0x706af48fU, 0xe963a535U, 0x9e6495a3U, 0x0edb8832U, 0x79dcb8a4U, 79 0x706af48fU, 0xe963a535U, 0x9e6495a3U, 0x0edb8832U, 0x79dcb8a4U,
81 0xe0d5e91eU, 0x97d2d988U, 0x09b64c2bU, 0x7eb17cbdU, 0xe7b82d07U, 80 0xe0d5e91eU, 0x97d2d988U, 0x09b64c2bU, 0x7eb17cbdU, 0xe7b82d07U,
82 0x90bf1d91U, 0x1db71064U, 0x6ab020f2U, 0xf3b97148U, 0x84be41deU, 81 0x90bf1d91U, 0x1db71064U, 0x6ab020f2U, 0xf3b97148U, 0x84be41deU,
83 0x1adad47dU, 0x6ddde4ebU, 0xf4d4b551U, 0x83d385c7U, 0x136c9856U, 82 0x1adad47dU, 0x6ddde4ebU, 0xf4d4b551U, 0x83d385c7U, 0x136c9856U,
84 0x646ba8c0U, 0xfd62f97aU, 0x8a65c9ecU, 0x14015c4fU, 0x63066cd9U, 83 0x646ba8c0U, 0xfd62f97aU, 0x8a65c9ecU, 0x14015c4fU, 0x63066cd9U,
85 0xfa0f3d63U, 0x8d080df5U, 0x3b6e20c8U, 0x4c69105eU, 0xd56041e4U, 84 0xfa0f3d63U, 0x8d080df5U, 0x3b6e20c8U, 0x4c69105eU, 0xd56041e4U,
86 0xa2677172U, 0x3c03e4d1U, 0x4b04d447U, 0xd20d85fdU, 0xa50ab56bU, 85 0xa2677172U, 0x3c03e4d1U, 0x4b04d447U, 0xd20d85fdU, 0xa50ab56bU,
87 0x35b5a8faU, 0x42b2986cU, 0xdbbbc9d6U, 0xacbcf940U, 0x32d86ce3U, 86 0x35b5a8faU, 0x42b2986cU, 0xdbbbc9d6U, 0xacbcf940U, 0x32d86ce3U,
88 0x45df5c75U, 0xdcd60dcfU, 0xabd13d59U, 0x26d930acU, 0x51de003aU, 87 0x45df5c75U, 0xdcd60dcfU, 0xabd13d59U, 0x26d930acU, 0x51de003aU,
89 0xc8d75180U, 0xbfd06116U, 0x21b4f4b5U, 0x56b3c423U, 0xcfba9599U, 88 0xc8d75180U, 0xbfd06116U, 0x21b4f4b5U, 0x56b3c423U, 0xcfba9599U,
90 0xb8bda50fU, 0x2802b89eU, 0x5f058808U, 0xc60cd9b2U, 0xb10be924U, 89 0xb8bda50fU, 0x2802b89eU, 0x5f058808U, 0xc60cd9b2U, 0xb10be924U,
91 0x2f6f7c87U, 0x58684c11U, 0xc1611dabU, 0xb6662d3dU, 0x76dc4190U, 90 0x2f6f7c87U, 0x58684c11U, 0xc1611dabU, 0xb6662d3dU, 0x76dc4190U,
92 0x01db7106U, 0x98d220bcU, 0xefd5102aU, 0x71b18589U, 0x06b6b51fU, 91 0x01db7106U, 0x98d220bcU, 0xefd5102aU, 0x71b18589U, 0x06b6b51fU,
93 0x9fbfe4a5U, 0xe8b8d433U, 0x7807c9a2U, 0x0f00f934U, 0x9609a88eU, 92 0x9fbfe4a5U, 0xe8b8d433U, 0x7807c9a2U, 0x0f00f934U, 0x9609a88eU,
94 0xe10e9818U, 0x7f6a0dbbU, 0x086d3d2dU, 0x91646c97U, 0xe6635c01U, 93 0xe10e9818U, 0x7f6a0dbbU, 0x086d3d2dU, 0x91646c97U, 0xe6635c01U,
95 0x6b6b51f4U, 0x1c6c6162U, 0x856530d8U, 0xf262004eU, 0x6c0695edU, 94 0x6b6b51f4U, 0x1c6c6162U, 0x856530d8U, 0xf262004eU, 0x6c0695edU,
96 0x1b01a57bU, 0x8208f4c1U, 0xf50fc457U, 0x65b0d9c6U, 0x12b7e950U, 95 0x1b01a57bU, 0x8208f4c1U, 0xf50fc457U, 0x65b0d9c6U, 0x12b7e950U,
97 0x8bbeb8eaU, 0xfcb9887cU, 0x62dd1ddfU, 0x15da2d49U, 0x8cd37cf3U, 96 0x8bbeb8eaU, 0xfcb9887cU, 0x62dd1ddfU, 0x15da2d49U, 0x8cd37cf3U,
98 0xfbd44c65U, 0x4db26158U, 0x3ab551ceU, 0xa3bc0074U, 0xd4bb30e2U, 97 0xfbd44c65U, 0x4db26158U, 0x3ab551ceU, 0xa3bc0074U, 0xd4bb30e2U,
99 0x4adfa541U, 0x3dd895d7U, 0xa4d1c46dU, 0xd3d6f4fbU, 0x4369e96aU, 98 0x4adfa541U, 0x3dd895d7U, 0xa4d1c46dU, 0xd3d6f4fbU, 0x4369e96aU,
100 0x346ed9fcU, 0xad678846U, 0xda60b8d0U, 0x44042d73U, 0x33031de5U, 99 0x346ed9fcU, 0xad678846U, 0xda60b8d0U, 0x44042d73U, 0x33031de5U,
101 0xaa0a4c5fU, 0xdd0d7cc9U, 0x5005713cU, 0x270241aaU, 0xbe0b1010U, 100 0xaa0a4c5fU, 0xdd0d7cc9U, 0x5005713cU, 0x270241aaU, 0xbe0b1010U,
102 0xc90c2086U, 0x5768b525U, 0x206f85b3U, 0xb966d409U, 0xce61e49fU, 101 0xc90c2086U, 0x5768b525U, 0x206f85b3U, 0xb966d409U, 0xce61e49fU,
103 0x5edef90eU, 0x29d9c998U, 0xb0d09822U, 0xc7d7a8b4U, 0x59b33d17U, 102 0x5edef90eU, 0x29d9c998U, 0xb0d09822U, 0xc7d7a8b4U, 0x59b33d17U,
104 0x2eb40d81U, 0xb7bd5c3bU, 0xc0ba6cadU, 0xedb88320U, 0x9abfb3b6U, 103 0x2eb40d81U, 0xb7bd5c3bU, 0xc0ba6cadU, 0xedb88320U, 0x9abfb3b6U,
105 0x03b6e20cU, 0x74b1d29aU, 0xead54739U, 0x9dd277afU, 0x04db2615U, 104 0x03b6e20cU, 0x74b1d29aU, 0xead54739U, 0x9dd277afU, 0x04db2615U,
106 0x73dc1683U, 0xe3630b12U, 0x94643b84U, 0x0d6d6a3eU, 0x7a6a5aa8U, 105 0x73dc1683U, 0xe3630b12U, 0x94643b84U, 0x0d6d6a3eU, 0x7a6a5aa8U,
107 0xe40ecf0bU, 0x9309ff9dU, 0x0a00ae27U, 0x7d079eb1U, 0xf00f9344U, 106 0xe40ecf0bU, 0x9309ff9dU, 0x0a00ae27U, 0x7d079eb1U, 0xf00f9344U,
108 0x8708a3d2U, 0x1e01f268U, 0x6906c2feU, 0xf762575dU, 0x806567cbU, 107 0x8708a3d2U, 0x1e01f268U, 0x6906c2feU, 0xf762575dU, 0x806567cbU,
109 0x196c3671U, 0x6e6b06e7U, 0xfed41b76U, 0x89d32be0U, 0x10da7a5aU, 108 0x196c3671U, 0x6e6b06e7U, 0xfed41b76U, 0x89d32be0U, 0x10da7a5aU,
110 0x67dd4accU, 0xf9b9df6fU, 0x8ebeeff9U, 0x17b7be43U, 0x60b08ed5U, 109 0x67dd4accU, 0xf9b9df6fU, 0x8ebeeff9U, 0x17b7be43U, 0x60b08ed5U,
111 0xd6d6a3e8U, 0xa1d1937eU, 0x38d8c2c4U, 0x4fdff252U, 0xd1bb67f1U, 110 0xd6d6a3e8U, 0xa1d1937eU, 0x38d8c2c4U, 0x4fdff252U, 0xd1bb67f1U,
112 0xa6bc5767U, 0x3fb506ddU, 0x48b2364bU, 0xd80d2bdaU, 0xaf0a1b4cU, 111 0xa6bc5767U, 0x3fb506ddU, 0x48b2364bU, 0xd80d2bdaU, 0xaf0a1b4cU,
113 0x36034af6U, 0x41047a60U, 0xdf60efc3U, 0xa867df55U, 0x316e8eefU, 112 0x36034af6U, 0x41047a60U, 0xdf60efc3U, 0xa867df55U, 0x316e8eefU,
114 0x4669be79U, 0xcb61b38cU, 0xbc66831aU, 0x256fd2a0U, 0x5268e236U, 113 0x4669be79U, 0xcb61b38cU, 0xbc66831aU, 0x256fd2a0U, 0x5268e236U,
115 0xcc0c7795U, 0xbb0b4703U, 0x220216b9U, 0x5505262fU, 0xc5ba3bbeU, 114 0xcc0c7795U, 0xbb0b4703U, 0x220216b9U, 0x5505262fU, 0xc5ba3bbeU,
116 0xb2bd0b28U, 0x2bb45a92U, 0x5cb36a04U, 0xc2d7ffa7U, 0xb5d0cf31U, 115 0xb2bd0b28U, 0x2bb45a92U, 0x5cb36a04U, 0xc2d7ffa7U, 0xb5d0cf31U,
117 0x2cd99e8bU, 0x5bdeae1dU, 0x9b64c2b0U, 0xec63f226U, 0x756aa39cU, 116 0x2cd99e8bU, 0x5bdeae1dU, 0x9b64c2b0U, 0xec63f226U, 0x756aa39cU,
118 0x026d930aU, 0x9c0906a9U, 0xeb0e363fU, 0x72076785U, 0x05005713U, 117 0x026d930aU, 0x9c0906a9U, 0xeb0e363fU, 0x72076785U, 0x05005713U,
119 0x95bf4a82U, 0xe2b87a14U, 0x7bb12baeU, 0x0cb61b38U, 0x92d28e9bU, 118 0x95bf4a82U, 0xe2b87a14U, 0x7bb12baeU, 0x0cb61b38U, 0x92d28e9bU,
120 0xe5d5be0dU, 0x7cdcefb7U, 0x0bdbdf21U, 0x86d3d2d4U, 0xf1d4e242U, 119 0xe5d5be0dU, 0x7cdcefb7U, 0x0bdbdf21U, 0x86d3d2d4U, 0xf1d4e242U,
121 0x68ddb3f8U, 0x1fda836eU, 0x81be16cdU, 0xf6b9265bU, 0x6fb077e1U, 120 0x68ddb3f8U, 0x1fda836eU, 0x81be16cdU, 0xf6b9265bU, 0x6fb077e1U,
122 0x18b74777U, 0x88085ae6U, 0xff0f6a70U, 0x66063bcaU, 0x11010b5cU, 121 0x18b74777U, 0x88085ae6U, 0xff0f6a70U, 0x66063bcaU, 0x11010b5cU,
123 0x8f659effU, 0xf862ae69U, 0x616bffd3U, 0x166ccf45U, 0xa00ae278U, 122 0x8f659effU, 0xf862ae69U, 0x616bffd3U, 0x166ccf45U, 0xa00ae278U,
124 0xd70dd2eeU, 0x4e048354U, 0x3903b3c2U, 0xa7672661U, 0xd06016f7U, 123 0xd70dd2eeU, 0x4e048354U, 0x3903b3c2U, 0xa7672661U, 0xd06016f7U,
125 0x4969474dU, 0x3e6e77dbU, 0xaed16a4aU, 0xd9d65adcU, 0x40df0b66U, 124 0x4969474dU, 0x3e6e77dbU, 0xaed16a4aU, 0xd9d65adcU, 0x40df0b66U,
126 0x37d83bf0U, 0xa9bcae53U, 0xdebb9ec5U, 0x47b2cf7fU, 0x30b5ffe9U, 125 0x37d83bf0U, 0xa9bcae53U, 0xdebb9ec5U, 0x47b2cf7fU, 0x30b5ffe9U,
127 0xbdbdf21cU, 0xcabac28aU, 0x53b39330U, 0x24b4a3a6U, 0xbad03605U, 126 0xbdbdf21cU, 0xcabac28aU, 0x53b39330U, 0x24b4a3a6U, 0xbad03605U,
128 0xcdd70693U, 0x54de5729U, 0x23d967bfU, 0xb3667a2eU, 0xc4614ab8U, 127 0xcdd70693U, 0x54de5729U, 0x23d967bfU, 0xb3667a2eU, 0xc4614ab8U,
129 0x5d681b02U, 0x2a6f2b94U, 0xb40bbe37U, 0xc30c8ea1U, 0x5a05df1bU, 128 0x5d681b02U, 0x2a6f2b94U, 0xb40bbe37U, 0xc30c8ea1U, 0x5a05df1bU,
130 0x2d02ef8dU 129 0x2d02ef8dU
131 }; 130 };
132 131
133 static unsigned long partial_crc32_one(unsigned char c, unsigned long crc) 132 static unsigned long partial_crc32_one(unsigned char c, unsigned long crc)
134 { 133 {
135 return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8); 134 return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
136 } 135 }
137 136
138 static unsigned long partial_crc32(const char *s, unsigned long crc) 137 static unsigned long partial_crc32(const char *s, unsigned long crc)
139 { 138 {
140 while (*s) 139 while (*s)
141 crc = partial_crc32_one(*s++, crc); 140 crc = partial_crc32_one(*s++, crc);
142 return crc; 141 return crc;
143 } 142 }
144 143
145 static unsigned long crc32(const char *s) 144 static unsigned long crc32(const char *s)
146 { 145 {
147 return partial_crc32(s, 0xffffffff) ^ 0xffffffff; 146 return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
148 } 147 }
149 148
150 /*----------------------------------------------------------------------*/ 149 /*----------------------------------------------------------------------*/
151 150
152 static enum symbol_type map_to_ns(enum symbol_type t) 151 static enum symbol_type map_to_ns(enum symbol_type t)
153 { 152 {
154 switch (t) { 153 switch (t) {
155 case SYM_ENUM_CONST: 154 case SYM_ENUM_CONST:
156 case SYM_NORMAL: 155 case SYM_NORMAL:
157 case SYM_TYPEDEF: 156 case SYM_TYPEDEF:
158 return SYM_NORMAL; 157 return SYM_NORMAL;
159 case SYM_ENUM: 158 case SYM_ENUM:
160 case SYM_STRUCT: 159 case SYM_STRUCT:
161 case SYM_UNION: 160 case SYM_UNION:
162 return SYM_STRUCT; 161 return SYM_STRUCT;
163 } 162 }
164 return t; 163 return t;
165 } 164 }
166 165
167 struct symbol *find_symbol(const char *name, enum symbol_type ns, int exact) 166 struct symbol *find_symbol(const char *name, enum symbol_type ns, int exact)
168 { 167 {
169 unsigned long h = crc32(name) % HASH_BUCKETS; 168 unsigned long h = crc32(name) % HASH_BUCKETS;
170 struct symbol *sym; 169 struct symbol *sym;
171 170
172 for (sym = symtab[h]; sym; sym = sym->hash_next) 171 for (sym = symtab[h]; sym; sym = sym->hash_next)
173 if (map_to_ns(sym->type) == map_to_ns(ns) && 172 if (map_to_ns(sym->type) == map_to_ns(ns) &&
174 strcmp(name, sym->name) == 0 && 173 strcmp(name, sym->name) == 0 &&
175 sym->is_declared) 174 sym->is_declared)
176 break; 175 break;
177 176
178 if (exact && sym && sym->type != ns) 177 if (exact && sym && sym->type != ns)
179 return NULL; 178 return NULL;
180 return sym; 179 return sym;
181 } 180 }
182 181
183 static int is_unknown_symbol(struct symbol *sym) 182 static int is_unknown_symbol(struct symbol *sym)
184 { 183 {
185 struct string_list *defn; 184 struct string_list *defn;
186 185
187 return ((sym->type == SYM_STRUCT || 186 return ((sym->type == SYM_STRUCT ||
188 sym->type == SYM_UNION || 187 sym->type == SYM_UNION ||
189 sym->type == SYM_ENUM) && 188 sym->type == SYM_ENUM) &&
190 (defn = sym->defn) && defn->tag == SYM_NORMAL && 189 (defn = sym->defn) && defn->tag == SYM_NORMAL &&
191 strcmp(defn->string, "}") == 0 && 190 strcmp(defn->string, "}") == 0 &&
192 (defn = defn->next) && defn->tag == SYM_NORMAL && 191 (defn = defn->next) && defn->tag == SYM_NORMAL &&
193 strcmp(defn->string, "UNKNOWN") == 0 && 192 strcmp(defn->string, "UNKNOWN") == 0 &&
194 (defn = defn->next) && defn->tag == SYM_NORMAL && 193 (defn = defn->next) && defn->tag == SYM_NORMAL &&
195 strcmp(defn->string, "{") == 0); 194 strcmp(defn->string, "{") == 0);
196 } 195 }
197 196
198 static struct symbol *__add_symbol(const char *name, enum symbol_type type, 197 static struct symbol *__add_symbol(const char *name, enum symbol_type type,
199 struct string_list *defn, int is_extern, 198 struct string_list *defn, int is_extern,
200 int is_reference) 199 int is_reference)
201 { 200 {
202 unsigned long h; 201 unsigned long h;
203 struct symbol *sym; 202 struct symbol *sym;
204 enum symbol_status status = STATUS_UNCHANGED; 203 enum symbol_status status = STATUS_UNCHANGED;
205 /* The parser adds symbols in the order their declaration completes, 204 /* The parser adds symbols in the order their declaration completes,
206 * so it is safe to store the value of the previous enum constant in 205 * so it is safe to store the value of the previous enum constant in
207 * a static variable. 206 * a static variable.
208 */ 207 */
209 static int enum_counter; 208 static int enum_counter;
210 static struct string_list *last_enum_expr; 209 static struct string_list *last_enum_expr;
211 210
212 if (type == SYM_ENUM_CONST) { 211 if (type == SYM_ENUM_CONST) {
213 if (defn) { 212 if (defn) {
214 free_list(last_enum_expr, NULL); 213 free_list(last_enum_expr, NULL);
215 last_enum_expr = copy_list_range(defn, NULL); 214 last_enum_expr = copy_list_range(defn, NULL);
216 enum_counter = 1; 215 enum_counter = 1;
217 } else { 216 } else {
218 struct string_list *expr; 217 struct string_list *expr;
219 char buf[20]; 218 char buf[20];
220 219
221 snprintf(buf, sizeof(buf), "%d", enum_counter++); 220 snprintf(buf, sizeof(buf), "%d", enum_counter++);
222 if (last_enum_expr) { 221 if (last_enum_expr) {
223 expr = copy_list_range(last_enum_expr, NULL); 222 expr = copy_list_range(last_enum_expr, NULL);
224 defn = concat_list(mk_node("("), 223 defn = concat_list(mk_node("("),
225 expr, 224 expr,
226 mk_node(")"), 225 mk_node(")"),
227 mk_node("+"), 226 mk_node("+"),
228 mk_node(buf), NULL); 227 mk_node(buf), NULL);
229 } else { 228 } else {
230 defn = mk_node(buf); 229 defn = mk_node(buf);
231 } 230 }
232 } 231 }
233 } else if (type == SYM_ENUM) { 232 } else if (type == SYM_ENUM) {
234 free_list(last_enum_expr, NULL); 233 free_list(last_enum_expr, NULL);
235 last_enum_expr = NULL; 234 last_enum_expr = NULL;
236 enum_counter = 0; 235 enum_counter = 0;
237 if (!name) 236 if (!name)
238 /* Anonymous enum definition, nothing more to do */ 237 /* Anonymous enum definition, nothing more to do */
239 return NULL; 238 return NULL;
240 } 239 }
241 240
242 h = crc32(name) % HASH_BUCKETS; 241 h = crc32(name) % HASH_BUCKETS;
243 for (sym = symtab[h]; sym; sym = sym->hash_next) { 242 for (sym = symtab[h]; sym; sym = sym->hash_next) {
244 if (map_to_ns(sym->type) == map_to_ns(type) && 243 if (map_to_ns(sym->type) == map_to_ns(type) &&
245 strcmp(name, sym->name) == 0) { 244 strcmp(name, sym->name) == 0) {
246 if (is_reference) 245 if (is_reference)
247 /* fall through */ ; 246 /* fall through */ ;
248 else if (sym->type == type && 247 else if (sym->type == type &&
249 equal_list(sym->defn, defn)) { 248 equal_list(sym->defn, defn)) {
250 if (!sym->is_declared && sym->is_override) { 249 if (!sym->is_declared && sym->is_override) {
251 print_location(); 250 print_location();
252 print_type_name(type, name); 251 print_type_name(type, name);
253 fprintf(stderr, " modversion is " 252 fprintf(stderr, " modversion is "
254 "unchanged\n"); 253 "unchanged\n");
255 } 254 }
256 sym->is_declared = 1; 255 sym->is_declared = 1;
257 return sym; 256 return sym;
258 } else if (!sym->is_declared) { 257 } else if (!sym->is_declared) {
259 if (sym->is_override && flag_preserve) { 258 if (sym->is_override && flag_preserve) {
260 print_location(); 259 print_location();
261 fprintf(stderr, "ignoring "); 260 fprintf(stderr, "ignoring ");
262 print_type_name(type, name); 261 print_type_name(type, name);
263 fprintf(stderr, " modversion change\n"); 262 fprintf(stderr, " modversion change\n");
264 sym->is_declared = 1; 263 sym->is_declared = 1;
265 return sym; 264 return sym;
266 } else { 265 } else {
267 status = is_unknown_symbol(sym) ? 266 status = is_unknown_symbol(sym) ?
268 STATUS_DEFINED : STATUS_MODIFIED; 267 STATUS_DEFINED : STATUS_MODIFIED;
269 } 268 }
270 } else { 269 } else {
271 error_with_pos("redefinition of %s", name); 270 error_with_pos("redefinition of %s", name);
272 return sym; 271 return sym;
273 } 272 }
274 break; 273 break;
275 } 274 }
276 } 275 }
277 276
278 if (sym) { 277 if (sym) {
279 struct symbol **psym; 278 struct symbol **psym;
280 279
281 for (psym = &symtab[h]; *psym; psym = &(*psym)->hash_next) { 280 for (psym = &symtab[h]; *psym; psym = &(*psym)->hash_next) {
282 if (*psym == sym) { 281 if (*psym == sym) {
283 *psym = sym->hash_next; 282 *psym = sym->hash_next;
284 break; 283 break;
285 } 284 }
286 } 285 }
287 --nsyms; 286 --nsyms;
288 } 287 }
289 288
290 sym = xmalloc(sizeof(*sym)); 289 sym = xmalloc(sizeof(*sym));
291 sym->name = name; 290 sym->name = name;
292 sym->type = type; 291 sym->type = type;
293 sym->defn = defn; 292 sym->defn = defn;
294 sym->expansion_trail = NULL; 293 sym->expansion_trail = NULL;
295 sym->visited = NULL; 294 sym->visited = NULL;
296 sym->is_extern = is_extern; 295 sym->is_extern = is_extern;
297 296
298 sym->hash_next = symtab[h]; 297 sym->hash_next = symtab[h];
299 symtab[h] = sym; 298 symtab[h] = sym;
300 299
301 sym->is_declared = !is_reference; 300 sym->is_declared = !is_reference;
302 sym->status = status; 301 sym->status = status;
303 sym->is_override = 0; 302 sym->is_override = 0;
304 303
305 if (flag_debug) { 304 if (flag_debug) {
306 if (symbol_types[type].name) 305 if (symbol_types[type].name)
307 fprintf(debugfile, "Defn for %s %s == <", 306 fprintf(debugfile, "Defn for %s %s == <",
308 symbol_types[type].name, name); 307 symbol_types[type].name, name);
309 else 308 else
310 fprintf(debugfile, "Defn for type%d %s == <", 309 fprintf(debugfile, "Defn for type%d %s == <",
311 type, name); 310 type, name);
312 if (is_extern) 311 if (is_extern)
313 fputs("extern ", debugfile); 312 fputs("extern ", debugfile);
314 print_list(debugfile, defn); 313 print_list(debugfile, defn);
315 fputs(">\n", debugfile); 314 fputs(">\n", debugfile);
316 } 315 }
317 316
318 ++nsyms; 317 ++nsyms;
319 return sym; 318 return sym;
320 } 319 }
321 320
322 struct symbol *add_symbol(const char *name, enum symbol_type type, 321 struct symbol *add_symbol(const char *name, enum symbol_type type,
323 struct string_list *defn, int is_extern) 322 struct string_list *defn, int is_extern)
324 { 323 {
325 return __add_symbol(name, type, defn, is_extern, 0); 324 return __add_symbol(name, type, defn, is_extern, 0);
326 } 325 }
327 326
328 static struct symbol *add_reference_symbol(const char *name, enum symbol_type type, 327 static struct symbol *add_reference_symbol(const char *name, enum symbol_type type,
329 struct string_list *defn, int is_extern) 328 struct string_list *defn, int is_extern)
330 { 329 {
331 return __add_symbol(name, type, defn, is_extern, 1); 330 return __add_symbol(name, type, defn, is_extern, 1);
332 } 331 }
333 332
334 /*----------------------------------------------------------------------*/ 333 /*----------------------------------------------------------------------*/
335 334
336 void free_node(struct string_list *node) 335 void free_node(struct string_list *node)
337 { 336 {
338 free(node->string); 337 free(node->string);
339 free(node); 338 free(node);
340 } 339 }
341 340
342 void free_list(struct string_list *s, struct string_list *e) 341 void free_list(struct string_list *s, struct string_list *e)
343 { 342 {
344 while (s != e) { 343 while (s != e) {
345 struct string_list *next = s->next; 344 struct string_list *next = s->next;
346 free_node(s); 345 free_node(s);
347 s = next; 346 s = next;
348 } 347 }
349 } 348 }
350 349
351 static struct string_list *mk_node(const char *string) 350 static struct string_list *mk_node(const char *string)
352 { 351 {
353 struct string_list *newnode; 352 struct string_list *newnode;
354 353
355 newnode = xmalloc(sizeof(*newnode)); 354 newnode = xmalloc(sizeof(*newnode));
356 newnode->string = xstrdup(string); 355 newnode->string = xstrdup(string);
357 newnode->tag = SYM_NORMAL; 356 newnode->tag = SYM_NORMAL;
358 newnode->next = NULL; 357 newnode->next = NULL;
359 358
360 return newnode; 359 return newnode;
361 } 360 }
362 361
363 static struct string_list *concat_list(struct string_list *start, ...) 362 static struct string_list *concat_list(struct string_list *start, ...)
364 { 363 {
365 va_list ap; 364 va_list ap;
366 struct string_list *n, *n2; 365 struct string_list *n, *n2;
367 366
368 if (!start) 367 if (!start)
369 return NULL; 368 return NULL;
370 for (va_start(ap, start); (n = va_arg(ap, struct string_list *));) { 369 for (va_start(ap, start); (n = va_arg(ap, struct string_list *));) {
371 for (n2 = n; n2->next; n2 = n2->next) 370 for (n2 = n; n2->next; n2 = n2->next)
372 ; 371 ;
373 n2->next = start; 372 n2->next = start;
374 start = n; 373 start = n;
375 } 374 }
376 va_end(ap); 375 va_end(ap);
377 return start; 376 return start;
378 } 377 }
379 378
380 struct string_list *copy_node(struct string_list *node) 379 struct string_list *copy_node(struct string_list *node)
381 { 380 {
382 struct string_list *newnode; 381 struct string_list *newnode;
383 382
384 newnode = xmalloc(sizeof(*newnode)); 383 newnode = xmalloc(sizeof(*newnode));
385 newnode->string = xstrdup(node->string); 384 newnode->string = xstrdup(node->string);
386 newnode->tag = node->tag; 385 newnode->tag = node->tag;
387 386
388 return newnode; 387 return newnode;
389 } 388 }
390 389
391 struct string_list *copy_list_range(struct string_list *start, 390 struct string_list *copy_list_range(struct string_list *start,
392 struct string_list *end) 391 struct string_list *end)
393 { 392 {
394 struct string_list *res, *n; 393 struct string_list *res, *n;
395 394
396 if (start == end) 395 if (start == end)
397 return NULL; 396 return NULL;
398 n = res = copy_node(start); 397 n = res = copy_node(start);
399 for (start = start->next; start != end; start = start->next) { 398 for (start = start->next; start != end; start = start->next) {
400 n->next = copy_node(start); 399 n->next = copy_node(start);
401 n = n->next; 400 n = n->next;
402 } 401 }
403 n->next = NULL; 402 n->next = NULL;
404 return res; 403 return res;
405 } 404 }
406 405
407 static int equal_list(struct string_list *a, struct string_list *b) 406 static int equal_list(struct string_list *a, struct string_list *b)
408 { 407 {
409 while (a && b) { 408 while (a && b) {
410 if (a->tag != b->tag || strcmp(a->string, b->string)) 409 if (a->tag != b->tag || strcmp(a->string, b->string))
411 return 0; 410 return 0;
412 a = a->next; 411 a = a->next;
413 b = b->next; 412 b = b->next;
414 } 413 }
415 414
416 return !a && !b; 415 return !a && !b;
417 } 416 }
418 417
419 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) 418 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
420 419
421 static struct string_list *read_node(FILE *f) 420 static struct string_list *read_node(FILE *f)
422 { 421 {
423 char buffer[256]; 422 char buffer[256];
424 struct string_list node = { 423 struct string_list node = {
425 .string = buffer, 424 .string = buffer,
426 .tag = SYM_NORMAL }; 425 .tag = SYM_NORMAL };
427 int c; 426 int c;
428 427
429 while ((c = fgetc(f)) != EOF) { 428 while ((c = fgetc(f)) != EOF) {
430 if (c == ' ') { 429 if (c == ' ') {
431 if (node.string == buffer) 430 if (node.string == buffer)
432 continue; 431 continue;
433 break; 432 break;
434 } else if (c == '\n') { 433 } else if (c == '\n') {
435 if (node.string == buffer) 434 if (node.string == buffer)
436 return NULL; 435 return NULL;
437 ungetc(c, f); 436 ungetc(c, f);
438 break; 437 break;
439 } 438 }
440 if (node.string >= buffer + sizeof(buffer) - 1) { 439 if (node.string >= buffer + sizeof(buffer) - 1) {
441 fprintf(stderr, "Token too long\n"); 440 fprintf(stderr, "Token too long\n");
442 exit(1); 441 exit(1);
443 } 442 }
444 *node.string++ = c; 443 *node.string++ = c;
445 } 444 }
446 if (node.string == buffer) 445 if (node.string == buffer)
447 return NULL; 446 return NULL;
448 *node.string = 0; 447 *node.string = 0;
449 node.string = buffer; 448 node.string = buffer;
450 449
451 if (node.string[1] == '#') { 450 if (node.string[1] == '#') {
452 size_t n; 451 size_t n;
453 452
454 for (n = 0; n < ARRAY_SIZE(symbol_types); n++) { 453 for (n = 0; n < ARRAY_SIZE(symbol_types); n++) {
455 if (node.string[0] == symbol_types[n].n) { 454 if (node.string[0] == symbol_types[n].n) {
456 node.tag = n; 455 node.tag = n;
457 node.string += 2; 456 node.string += 2;
458 return copy_node(&node); 457 return copy_node(&node);
459 } 458 }
460 } 459 }
461 fprintf(stderr, "Unknown type %c\n", node.string[0]); 460 fprintf(stderr, "Unknown type %c\n", node.string[0]);
462 exit(1); 461 exit(1);
463 } 462 }
464 return copy_node(&node); 463 return copy_node(&node);
465 } 464 }
466 465
467 static void read_reference(FILE *f) 466 static void read_reference(FILE *f)
468 { 467 {
469 while (!feof(f)) { 468 while (!feof(f)) {
470 struct string_list *defn = NULL; 469 struct string_list *defn = NULL;
471 struct string_list *sym, *def; 470 struct string_list *sym, *def;
472 int is_extern = 0, is_override = 0; 471 int is_extern = 0, is_override = 0;
473 struct symbol *subsym; 472 struct symbol *subsym;
474 473
475 sym = read_node(f); 474 sym = read_node(f);
476 if (sym && sym->tag == SYM_NORMAL && 475 if (sym && sym->tag == SYM_NORMAL &&
477 !strcmp(sym->string, "override")) { 476 !strcmp(sym->string, "override")) {
478 is_override = 1; 477 is_override = 1;
479 free_node(sym); 478 free_node(sym);
480 sym = read_node(f); 479 sym = read_node(f);
481 } 480 }
482 if (!sym) 481 if (!sym)
483 continue; 482 continue;
484 def = read_node(f); 483 def = read_node(f);
485 if (def && def->tag == SYM_NORMAL && 484 if (def && def->tag == SYM_NORMAL &&
486 !strcmp(def->string, "extern")) { 485 !strcmp(def->string, "extern")) {
487 is_extern = 1; 486 is_extern = 1;
488 free_node(def); 487 free_node(def);
489 def = read_node(f); 488 def = read_node(f);
490 } 489 }
491 while (def) { 490 while (def) {
492 def->next = defn; 491 def->next = defn;
493 defn = def; 492 defn = def;
494 def = read_node(f); 493 def = read_node(f);
495 } 494 }
496 subsym = add_reference_symbol(xstrdup(sym->string), sym->tag, 495 subsym = add_reference_symbol(xstrdup(sym->string), sym->tag,
497 defn, is_extern); 496 defn, is_extern);
498 subsym->is_override = is_override; 497 subsym->is_override = is_override;
499 free_node(sym); 498 free_node(sym);
500 } 499 }
501 } 500 }
502 501
503 static void print_node(FILE * f, struct string_list *list) 502 static void print_node(FILE * f, struct string_list *list)
504 { 503 {
505 if (symbol_types[list->tag].n) { 504 if (symbol_types[list->tag].n) {
506 putc(symbol_types[list->tag].n, f); 505 putc(symbol_types[list->tag].n, f);
507 putc('#', f); 506 putc('#', f);
508 } 507 }
509 fputs(list->string, f); 508 fputs(list->string, f);
510 } 509 }
511 510
512 static void print_list(FILE * f, struct string_list *list) 511 static void print_list(FILE * f, struct string_list *list)
513 { 512 {
514 struct string_list **e, **b; 513 struct string_list **e, **b;
515 struct string_list *tmp, **tmp2; 514 struct string_list *tmp, **tmp2;
516 int elem = 1; 515 int elem = 1;
517 516
518 if (list == NULL) { 517 if (list == NULL) {
519 fputs("(nil)", f); 518 fputs("(nil)", f);
520 return; 519 return;
521 } 520 }
522 521
523 tmp = list; 522 tmp = list;
524 while ((tmp = tmp->next) != NULL) 523 while ((tmp = tmp->next) != NULL)
525 elem++; 524 elem++;
526 525
527 b = alloca(elem * sizeof(*e)); 526 b = alloca(elem * sizeof(*e));
528 e = b + elem; 527 e = b + elem;
529 tmp2 = e - 1; 528 tmp2 = e - 1;
530 529
531 (*tmp2--) = list; 530 (*tmp2--) = list;
532 while ((list = list->next) != NULL) 531 while ((list = list->next) != NULL)
533 *(tmp2--) = list; 532 *(tmp2--) = list;
534 533
535 while (b != e) { 534 while (b != e) {
536 print_node(f, *b++); 535 print_node(f, *b++);
537 putc(' ', f); 536 putc(' ', f);
538 } 537 }
539 } 538 }
540 539
541 static unsigned long expand_and_crc_sym(struct symbol *sym, unsigned long crc) 540 static unsigned long expand_and_crc_sym(struct symbol *sym, unsigned long crc)
542 { 541 {
543 struct string_list *list = sym->defn; 542 struct string_list *list = sym->defn;
544 struct string_list **e, **b; 543 struct string_list **e, **b;
545 struct string_list *tmp, **tmp2; 544 struct string_list *tmp, **tmp2;
546 int elem = 1; 545 int elem = 1;
547 546
548 if (!list) 547 if (!list)
549 return crc; 548 return crc;
550 549
551 tmp = list; 550 tmp = list;
552 while ((tmp = tmp->next) != NULL) 551 while ((tmp = tmp->next) != NULL)
553 elem++; 552 elem++;
554 553
555 b = alloca(elem * sizeof(*e)); 554 b = alloca(elem * sizeof(*e));
556 e = b + elem; 555 e = b + elem;
557 tmp2 = e - 1; 556 tmp2 = e - 1;
558 557
559 *(tmp2--) = list; 558 *(tmp2--) = list;
560 while ((list = list->next) != NULL) 559 while ((list = list->next) != NULL)
561 *(tmp2--) = list; 560 *(tmp2--) = list;
562 561
563 while (b != e) { 562 while (b != e) {
564 struct string_list *cur; 563 struct string_list *cur;
565 struct symbol *subsym; 564 struct symbol *subsym;
566 565
567 cur = *(b++); 566 cur = *(b++);
568 switch (cur->tag) { 567 switch (cur->tag) {
569 case SYM_NORMAL: 568 case SYM_NORMAL:
570 if (flag_dump_defs) 569 if (flag_dump_defs)
571 fprintf(debugfile, "%s ", cur->string); 570 fprintf(debugfile, "%s ", cur->string);
572 crc = partial_crc32(cur->string, crc); 571 crc = partial_crc32(cur->string, crc);
573 crc = partial_crc32_one(' ', crc); 572 crc = partial_crc32_one(' ', crc);
574 break; 573 break;
575 574
576 case SYM_ENUM_CONST: 575 case SYM_ENUM_CONST:
577 case SYM_TYPEDEF: 576 case SYM_TYPEDEF:
578 subsym = find_symbol(cur->string, cur->tag, 0); 577 subsym = find_symbol(cur->string, cur->tag, 0);
579 /* FIXME: Bad reference files can segfault here. */ 578 /* FIXME: Bad reference files can segfault here. */
580 if (subsym->expansion_trail) { 579 if (subsym->expansion_trail) {
581 if (flag_dump_defs) 580 if (flag_dump_defs)
582 fprintf(debugfile, "%s ", cur->string); 581 fprintf(debugfile, "%s ", cur->string);
583 crc = partial_crc32(cur->string, crc); 582 crc = partial_crc32(cur->string, crc);
584 crc = partial_crc32_one(' ', crc); 583 crc = partial_crc32_one(' ', crc);
585 } else { 584 } else {
586 subsym->expansion_trail = expansion_trail; 585 subsym->expansion_trail = expansion_trail;
587 expansion_trail = subsym; 586 expansion_trail = subsym;
588 crc = expand_and_crc_sym(subsym, crc); 587 crc = expand_and_crc_sym(subsym, crc);
589 } 588 }
590 break; 589 break;
591 590
592 case SYM_STRUCT: 591 case SYM_STRUCT:
593 case SYM_UNION: 592 case SYM_UNION:
594 case SYM_ENUM: 593 case SYM_ENUM:
595 subsym = find_symbol(cur->string, cur->tag, 0); 594 subsym = find_symbol(cur->string, cur->tag, 0);
596 if (!subsym) { 595 if (!subsym) {
597 struct string_list *n; 596 struct string_list *n;
598 597
599 error_with_pos("expand undefined %s %s", 598 error_with_pos("expand undefined %s %s",
600 symbol_types[cur->tag].name, 599 symbol_types[cur->tag].name,
601 cur->string); 600 cur->string);
602 n = concat_list(mk_node 601 n = concat_list(mk_node
603 (symbol_types[cur->tag].name), 602 (symbol_types[cur->tag].name),
604 mk_node(cur->string), 603 mk_node(cur->string),
605 mk_node("{"), 604 mk_node("{"),
606 mk_node("UNKNOWN"), 605 mk_node("UNKNOWN"),
607 mk_node("}"), NULL); 606 mk_node("}"), NULL);
608 subsym = 607 subsym =
609 add_symbol(cur->string, cur->tag, n, 0); 608 add_symbol(cur->string, cur->tag, n, 0);
610 } 609 }
611 if (subsym->expansion_trail) { 610 if (subsym->expansion_trail) {
612 if (flag_dump_defs) { 611 if (flag_dump_defs) {
613 fprintf(debugfile, "%s %s ", 612 fprintf(debugfile, "%s %s ",
614 symbol_types[cur->tag].name, 613 symbol_types[cur->tag].name,
615 cur->string); 614 cur->string);
616 } 615 }
617 616
618 crc = partial_crc32(symbol_types[cur->tag].name, 617 crc = partial_crc32(symbol_types[cur->tag].name,
619 crc); 618 crc);
620 crc = partial_crc32_one(' ', crc); 619 crc = partial_crc32_one(' ', crc);
621 crc = partial_crc32(cur->string, crc); 620 crc = partial_crc32(cur->string, crc);
622 crc = partial_crc32_one(' ', crc); 621 crc = partial_crc32_one(' ', crc);
623 } else { 622 } else {
624 subsym->expansion_trail = expansion_trail; 623 subsym->expansion_trail = expansion_trail;
625 expansion_trail = subsym; 624 expansion_trail = subsym;
626 crc = expand_and_crc_sym(subsym, crc); 625 crc = expand_and_crc_sym(subsym, crc);
627 } 626 }
628 break; 627 break;
629 } 628 }
630 } 629 }
631 630
632 { 631 {
633 static struct symbol **end = &visited_symbols; 632 static struct symbol **end = &visited_symbols;
634 633
635 if (!sym->visited) { 634 if (!sym->visited) {
636 *end = sym; 635 *end = sym;
637 end = &sym->visited; 636 end = &sym->visited;
638 sym->visited = (struct symbol *)-1L; 637 sym->visited = (struct symbol *)-1L;
639 } 638 }
640 } 639 }
641 640
642 return crc; 641 return crc;
643 } 642 }
644 643
645 void export_symbol(const char *name) 644 void export_symbol(const char *name)
646 { 645 {
647 struct symbol *sym; 646 struct symbol *sym;
648 647
649 sym = find_symbol(name, SYM_NORMAL, 0); 648 sym = find_symbol(name, SYM_NORMAL, 0);
650 if (!sym) 649 if (!sym)
651 error_with_pos("export undefined symbol %s", name); 650 error_with_pos("export undefined symbol %s", name);
652 else { 651 else {
653 unsigned long crc; 652 unsigned long crc;
654 int has_changed = 0; 653 int has_changed = 0;
655 654
656 if (flag_dump_defs) 655 if (flag_dump_defs)
657 fprintf(debugfile, "Export %s == <", name); 656 fprintf(debugfile, "Export %s == <", name);
658 657
659 expansion_trail = (struct symbol *)-1L; 658 expansion_trail = (struct symbol *)-1L;
660 659
661 sym->expansion_trail = expansion_trail; 660 sym->expansion_trail = expansion_trail;
662 expansion_trail = sym; 661 expansion_trail = sym;
663 crc = expand_and_crc_sym(sym, 0xffffffff) ^ 0xffffffff; 662 crc = expand_and_crc_sym(sym, 0xffffffff) ^ 0xffffffff;
664 663
665 sym = expansion_trail; 664 sym = expansion_trail;
666 while (sym != (struct symbol *)-1L) { 665 while (sym != (struct symbol *)-1L) {
667 struct symbol *n = sym->expansion_trail; 666 struct symbol *n = sym->expansion_trail;
668 667
669 if (sym->status != STATUS_UNCHANGED) { 668 if (sym->status != STATUS_UNCHANGED) {
670 if (!has_changed) { 669 if (!has_changed) {
671 print_location(); 670 print_location();
672 fprintf(stderr, "%s: %s: modversion " 671 fprintf(stderr, "%s: %s: modversion "
673 "changed because of changes " 672 "changed because of changes "
674 "in ", flag_preserve ? "error" : 673 "in ", flag_preserve ? "error" :
675 "warning", name); 674 "warning", name);
676 } else 675 } else
677 fprintf(stderr, ", "); 676 fprintf(stderr, ", ");
678 print_type_name(sym->type, sym->name); 677 print_type_name(sym->type, sym->name);
679 if (sym->status == STATUS_DEFINED) 678 if (sym->status == STATUS_DEFINED)
680 fprintf(stderr, " (became defined)"); 679 fprintf(stderr, " (became defined)");
681 has_changed = 1; 680 has_changed = 1;
682 if (flag_preserve) 681 if (flag_preserve)
683 errors++; 682 errors++;
684 } 683 }
685 sym->expansion_trail = 0; 684 sym->expansion_trail = 0;
686 sym = n; 685 sym = n;
687 } 686 }
688 if (has_changed) 687 if (has_changed)
689 fprintf(stderr, "\n"); 688 fprintf(stderr, "\n");
690 689
691 if (flag_dump_defs) 690 if (flag_dump_defs)
692 fputs(">\n", debugfile); 691 fputs(">\n", debugfile);
693 692
694 /* Used as a linker script. */ 693 /* Used as a linker script. */
695 printf("%s__crc_%s = 0x%08lx ;\n", mod_prefix, name, crc); 694 printf("%s__crc_%s = 0x%08lx ;\n", mod_prefix, name, crc);
696 } 695 }
697 } 696 }
698 697
699 /*----------------------------------------------------------------------*/ 698 /*----------------------------------------------------------------------*/
700 699
701 static void print_location(void) 700 static void print_location(void)
702 { 701 {
703 fprintf(stderr, "%s:%d: ", cur_filename ? : "<stdin>", cur_line); 702 fprintf(stderr, "%s:%d: ", cur_filename ? : "<stdin>", cur_line);
704 } 703 }
705 704
706 static void print_type_name(enum symbol_type type, const char *name) 705 static void print_type_name(enum symbol_type type, const char *name)
707 { 706 {
708 if (symbol_types[type].name) 707 if (symbol_types[type].name)
709 fprintf(stderr, "%s %s", symbol_types[type].name, name); 708 fprintf(stderr, "%s %s", symbol_types[type].name, name);
710 else 709 else
711 fprintf(stderr, "%s", name); 710 fprintf(stderr, "%s", name);
712 } 711 }
713 712
714 void error_with_pos(const char *fmt, ...) 713 void error_with_pos(const char *fmt, ...)
715 { 714 {
716 va_list args; 715 va_list args;
717 716
718 if (flag_warnings) { 717 if (flag_warnings) {
719 print_location(); 718 print_location();
720 719
721 va_start(args, fmt); 720 va_start(args, fmt);
722 vfprintf(stderr, fmt, args); 721 vfprintf(stderr, fmt, args);
723 va_end(args); 722 va_end(args);
724 putc('\n', stderr); 723 putc('\n', stderr);
725 724
726 errors++; 725 errors++;
727 } 726 }
728 } 727 }
729 728
730 static void genksyms_usage(void) 729 static void genksyms_usage(void)
731 { 730 {
732 fputs("Usage:\n" "genksyms [-adDTwqhV] > /path/to/.tmp_obj.ver\n" "\n" 731 fputs("Usage:\n" "genksyms [-adDTwqhV] > /path/to/.tmp_obj.ver\n" "\n"
733 #ifdef __GNU_LIBRARY__ 732 #ifdef __GNU_LIBRARY__
734 " -a, --arch Select architecture\n" 733 " -s, --symbol-prefix Select symbol prefix\n"
735 " -d, --debug Increment the debug level (repeatable)\n" 734 " -d, --debug Increment the debug level (repeatable)\n"
736 " -D, --dump Dump expanded symbol defs (for debugging only)\n" 735 " -D, --dump Dump expanded symbol defs (for debugging only)\n"
737 " -r, --reference file Read reference symbols from a file\n" 736 " -r, --reference file Read reference symbols from a file\n"
738 " -T, --dump-types file Dump expanded types into file\n" 737 " -T, --dump-types file Dump expanded types into file\n"
739 " -p, --preserve Preserve reference modversions or fail\n" 738 " -p, --preserve Preserve reference modversions or fail\n"
740 " -w, --warnings Enable warnings\n" 739 " -w, --warnings Enable warnings\n"
741 " -q, --quiet Disable warnings (default)\n" 740 " -q, --quiet Disable warnings (default)\n"
742 " -h, --help Print this message\n" 741 " -h, --help Print this message\n"
743 " -V, --version Print the release version\n" 742 " -V, --version Print the release version\n"
744 #else /* __GNU_LIBRARY__ */ 743 #else /* __GNU_LIBRARY__ */
745 " -a Select architecture\n" 744 " -s Select symbol prefix\n"
746 " -d Increment the debug level (repeatable)\n" 745 " -d Increment the debug level (repeatable)\n"
747 " -D Dump expanded symbol defs (for debugging only)\n" 746 " -D Dump expanded symbol defs (for debugging only)\n"
748 " -r file Read reference symbols from a file\n" 747 " -r file Read reference symbols from a file\n"
749 " -T file Dump expanded types into file\n" 748 " -T file Dump expanded types into file\n"
750 " -p Preserve reference modversions or fail\n" 749 " -p Preserve reference modversions or fail\n"
751 " -w Enable warnings\n" 750 " -w Enable warnings\n"
752 " -q Disable warnings (default)\n" 751 " -q Disable warnings (default)\n"
753 " -h Print this message\n" 752 " -h Print this message\n"
754 " -V Print the release version\n" 753 " -V Print the release version\n"
755 #endif /* __GNU_LIBRARY__ */ 754 #endif /* __GNU_LIBRARY__ */
756 , stderr); 755 , stderr);
757 } 756 }
758 757
759 int main(int argc, char **argv) 758 int main(int argc, char **argv)
760 { 759 {
761 FILE *dumpfile = NULL, *ref_file = NULL; 760 FILE *dumpfile = NULL, *ref_file = NULL;
762 int o; 761 int o;
763 762
764 #ifdef __GNU_LIBRARY__ 763 #ifdef __GNU_LIBRARY__
765 struct option long_opts[] = { 764 struct option long_opts[] = {
766 {"arch", 1, 0, 'a'}, 765 {"symbol-prefix", 1, 0, 's'},
767 {"debug", 0, 0, 'd'}, 766 {"debug", 0, 0, 'd'},
768 {"warnings", 0, 0, 'w'}, 767 {"warnings", 0, 0, 'w'},
769 {"quiet", 0, 0, 'q'}, 768 {"quiet", 0, 0, 'q'},
770 {"dump", 0, 0, 'D'}, 769 {"dump", 0, 0, 'D'},
771 {"reference", 1, 0, 'r'}, 770 {"reference", 1, 0, 'r'},
772 {"dump-types", 1, 0, 'T'}, 771 {"dump-types", 1, 0, 'T'},
773 {"preserve", 0, 0, 'p'}, 772 {"preserve", 0, 0, 'p'},
774 {"version", 0, 0, 'V'}, 773 {"version", 0, 0, 'V'},
775 {"help", 0, 0, 'h'}, 774 {"help", 0, 0, 'h'},
776 {0, 0, 0, 0} 775 {0, 0, 0, 0}
777 }; 776 };
778 777
779 while ((o = getopt_long(argc, argv, "a:dwqVDr:T:ph", 778 while ((o = getopt_long(argc, argv, "s:dwqVDr:T:ph",
780 &long_opts[0], NULL)) != EOF) 779 &long_opts[0], NULL)) != EOF)
781 #else /* __GNU_LIBRARY__ */ 780 #else /* __GNU_LIBRARY__ */
782 while ((o = getopt(argc, argv, "a:dwqVDr:T:ph")) != EOF) 781 while ((o = getopt(argc, argv, "s:dwqVDr:T:ph")) != EOF)
783 #endif /* __GNU_LIBRARY__ */ 782 #endif /* __GNU_LIBRARY__ */
784 switch (o) { 783 switch (o) {
785 case 'a': 784 case 's':
786 arch = optarg; 785 mod_prefix = optarg;
787 break; 786 break;
788 case 'd': 787 case 'd':
789 flag_debug++; 788 flag_debug++;
790 break; 789 break;
791 case 'w': 790 case 'w':
792 flag_warnings = 1; 791 flag_warnings = 1;
793 break; 792 break;
794 case 'q': 793 case 'q':
795 flag_warnings = 0; 794 flag_warnings = 0;
796 break; 795 break;
797 case 'V': 796 case 'V':
798 fputs("genksyms version 2.5.60\n", stderr); 797 fputs("genksyms version 2.5.60\n", stderr);
799 break; 798 break;
800 case 'D': 799 case 'D':
801 flag_dump_defs = 1; 800 flag_dump_defs = 1;
802 break; 801 break;
803 case 'r': 802 case 'r':
804 flag_reference = 1; 803 flag_reference = 1;
805 ref_file = fopen(optarg, "r"); 804 ref_file = fopen(optarg, "r");
806 if (!ref_file) { 805 if (!ref_file) {
807 perror(optarg); 806 perror(optarg);
808 return 1; 807 return 1;
809 } 808 }
810 break; 809 break;
811 case 'T': 810 case 'T':
812 flag_dump_types = 1; 811 flag_dump_types = 1;
813 dumpfile = fopen(optarg, "w"); 812 dumpfile = fopen(optarg, "w");
814 if (!dumpfile) { 813 if (!dumpfile) {
815 perror(optarg); 814 perror(optarg);
816 return 1; 815 return 1;
817 } 816 }
818 break; 817 break;
819 case 'p': 818 case 'p':
820 flag_preserve = 1; 819 flag_preserve = 1;
821 break; 820 break;
822 case 'h': 821 case 'h':
823 genksyms_usage(); 822 genksyms_usage();
824 return 0; 823 return 0;
825 default: 824 default:
826 genksyms_usage(); 825 genksyms_usage();
827 return 1; 826 return 1;
828 } 827 }
829 if ((strcmp(arch, "h8300") == 0) || (strcmp(arch, "blackfin") == 0) ||
830 (strcmp(arch, "metag") == 0))
831 mod_prefix = "_";
832 { 828 {
833 extern int yydebug; 829 extern int yydebug;
834 extern int yy_flex_debug; 830 extern int yy_flex_debug;
835 831
836 yydebug = (flag_debug > 1); 832 yydebug = (flag_debug > 1);
837 yy_flex_debug = (flag_debug > 2); 833 yy_flex_debug = (flag_debug > 2);
838 834
839 debugfile = stderr; 835 debugfile = stderr;
840 /* setlinebuf(debugfile); */ 836 /* setlinebuf(debugfile); */
841 } 837 }
842 838
843 if (flag_reference) { 839 if (flag_reference) {
844 read_reference(ref_file); 840 read_reference(ref_file);
845 fclose(ref_file); 841 fclose(ref_file);
846 } 842 }
847 843
848 yyparse(); 844 yyparse();
849 845
850 if (flag_dump_types && visited_symbols) { 846 if (flag_dump_types && visited_symbols) {
851 while (visited_symbols != (struct symbol *)-1L) { 847 while (visited_symbols != (struct symbol *)-1L) {
852 struct symbol *sym = visited_symbols; 848 struct symbol *sym = visited_symbols;
853 849
854 if (sym->is_override) 850 if (sym->is_override)
855 fputs("override ", dumpfile); 851 fputs("override ", dumpfile);
856 if (symbol_types[sym->type].n) { 852 if (symbol_types[sym->type].n) {
857 putc(symbol_types[sym->type].n, dumpfile); 853 putc(symbol_types[sym->type].n, dumpfile);
858 putc('#', dumpfile); 854 putc('#', dumpfile);
859 } 855 }
860 fputs(sym->name, dumpfile); 856 fputs(sym->name, dumpfile);
861 putc(' ', dumpfile); 857 putc(' ', dumpfile);
862 if (sym->is_extern) 858 if (sym->is_extern)
863 fputs("extern ", dumpfile); 859 fputs("extern ", dumpfile);
864 print_list(dumpfile, sym->defn); 860 print_list(dumpfile, sym->defn);
865 putc('\n', dumpfile); 861 putc('\n', dumpfile);
866 862
867 visited_symbols = sym->visited; 863 visited_symbols = sym->visited;
868 sym->visited = NULL; 864 sym->visited = NULL;
869 } 865 }
870 } 866 }
871 867
872 if (flag_debug) { 868 if (flag_debug) {
873 fprintf(debugfile, "Hash table occupancy %d/%d = %g\n", 869 fprintf(debugfile, "Hash table occupancy %d/%d = %g\n",
874 nsyms, HASH_BUCKETS, 870 nsyms, HASH_BUCKETS,
875 (double)nsyms / (double)HASH_BUCKETS); 871 (double)nsyms / (double)HASH_BUCKETS);
876 } 872 }
877 873
878 return errors != 0; 874 return errors != 0;
879 } 875 }
880 876
scripts/link-vmlinux.sh
1 #!/bin/sh 1 #!/bin/sh
2 # 2 #
3 # link vmlinux 3 # link vmlinux
4 # 4 #
5 # vmlinux is linked from the objects selected by $(KBUILD_VMLINUX_INIT) and 5 # vmlinux is linked from the objects selected by $(KBUILD_VMLINUX_INIT) and
6 # $(KBUILD_VMLINUX_MAIN). Most are built-in.o files from top-level directories 6 # $(KBUILD_VMLINUX_MAIN). Most are built-in.o files from top-level directories
7 # in the kernel tree, others are specified in arch/$(ARCH)/Makefile. 7 # in the kernel tree, others are specified in arch/$(ARCH)/Makefile.
8 # Ordering when linking is important, and $(KBUILD_VMLINUX_INIT) must be first. 8 # Ordering when linking is important, and $(KBUILD_VMLINUX_INIT) must be first.
9 # 9 #
10 # vmlinux 10 # vmlinux
11 # ^ 11 # ^
12 # | 12 # |
13 # +-< $(KBUILD_VMLINUX_INIT) 13 # +-< $(KBUILD_VMLINUX_INIT)
14 # | +--< init/version.o + more 14 # | +--< init/version.o + more
15 # | 15 # |
16 # +--< $(KBUILD_VMLINUX_MAIN) 16 # +--< $(KBUILD_VMLINUX_MAIN)
17 # | +--< drivers/built-in.o mm/built-in.o + more 17 # | +--< drivers/built-in.o mm/built-in.o + more
18 # | 18 # |
19 # +-< ${kallsymso} (see description in KALLSYMS section) 19 # +-< ${kallsymso} (see description in KALLSYMS section)
20 # 20 #
21 # vmlinux version (uname -v) cannot be updated during normal 21 # vmlinux version (uname -v) cannot be updated during normal
22 # descending-into-subdirs phase since we do not yet know if we need to 22 # descending-into-subdirs phase since we do not yet know if we need to
23 # update vmlinux. 23 # update vmlinux.
24 # Therefore this step is delayed until just before final link of vmlinux. 24 # Therefore this step is delayed until just before final link of vmlinux.
25 # 25 #
26 # System.map is generated to document addresses of all kernel symbols 26 # System.map is generated to document addresses of all kernel symbols
27 27
28 # Error out on error 28 # Error out on error
29 set -e 29 set -e
30 30
31 # Nice output in kbuild format 31 # Nice output in kbuild format
32 # Will be supressed by "make -s" 32 # Will be supressed by "make -s"
33 info() 33 info()
34 { 34 {
35 if [ "${quiet}" != "silent_" ]; then 35 if [ "${quiet}" != "silent_" ]; then
36 printf " %-7s %s\n" ${1} ${2} 36 printf " %-7s %s\n" ${1} ${2}
37 fi 37 fi
38 } 38 }
39 39
40 # Link of vmlinux.o used for section mismatch analysis 40 # Link of vmlinux.o used for section mismatch analysis
41 # ${1} output file 41 # ${1} output file
42 modpost_link() 42 modpost_link()
43 { 43 {
44 ${LD} ${LDFLAGS} -r -o ${1} ${KBUILD_VMLINUX_INIT} \ 44 ${LD} ${LDFLAGS} -r -o ${1} ${KBUILD_VMLINUX_INIT} \
45 --start-group ${KBUILD_VMLINUX_MAIN} --end-group 45 --start-group ${KBUILD_VMLINUX_MAIN} --end-group
46 } 46 }
47 47
48 # Link of vmlinux 48 # Link of vmlinux
49 # ${1} - optional extra .o files 49 # ${1} - optional extra .o files
50 # ${2} - output file 50 # ${2} - output file
51 vmlinux_link() 51 vmlinux_link()
52 { 52 {
53 local lds="${objtree}/${KBUILD_LDS}" 53 local lds="${objtree}/${KBUILD_LDS}"
54 54
55 if [ "${SRCARCH}" != "um" ]; then 55 if [ "${SRCARCH}" != "um" ]; then
56 ${LD} ${LDFLAGS} ${LDFLAGS_vmlinux} -o ${2} \ 56 ${LD} ${LDFLAGS} ${LDFLAGS_vmlinux} -o ${2} \
57 -T ${lds} ${KBUILD_VMLINUX_INIT} \ 57 -T ${lds} ${KBUILD_VMLINUX_INIT} \
58 --start-group ${KBUILD_VMLINUX_MAIN} --end-group ${1} 58 --start-group ${KBUILD_VMLINUX_MAIN} --end-group ${1}
59 else 59 else
60 ${CC} ${CFLAGS_vmlinux} -o ${2} \ 60 ${CC} ${CFLAGS_vmlinux} -o ${2} \
61 -Wl,-T,${lds} ${KBUILD_VMLINUX_INIT} \ 61 -Wl,-T,${lds} ${KBUILD_VMLINUX_INIT} \
62 -Wl,--start-group \ 62 -Wl,--start-group \
63 ${KBUILD_VMLINUX_MAIN} \ 63 ${KBUILD_VMLINUX_MAIN} \
64 -Wl,--end-group \ 64 -Wl,--end-group \
65 -lutil ${1} 65 -lutil ${1}
66 rm -f linux 66 rm -f linux
67 fi 67 fi
68 } 68 }
69 69
70 70
71 # Create ${2} .o file with all symbols from the ${1} object file 71 # Create ${2} .o file with all symbols from the ${1} object file
72 kallsyms() 72 kallsyms()
73 { 73 {
74 info KSYM ${2} 74 info KSYM ${2}
75 local kallsymopt; 75 local kallsymopt;
76 76
77 if [ -n "${CONFIG_SYMBOL_PREFIX}" ]; then 77 if [ -n "${CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX}" ]; then
78 kallsymopt="${kallsymopt} \ 78 kallsymopt="${kallsymopt} --symbol-prefix=_"
79 --symbol-prefix=${CONFIG_SYMBOL_PREFIX}"
80 fi 79 fi
81 80
82 if [ -n "${CONFIG_KALLSYMS_ALL}" ]; then 81 if [ -n "${CONFIG_KALLSYMS_ALL}" ]; then
83 kallsymopt="${kallsymopt} --all-symbols" 82 kallsymopt="${kallsymopt} --all-symbols"
84 fi 83 fi
85 84
86 local aflags="${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \ 85 local aflags="${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \
87 ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS}" 86 ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS}"
88 87
89 ${NM} -n ${1} | \ 88 ${NM} -n ${1} | \
90 scripts/kallsyms ${kallsymopt} | \ 89 scripts/kallsyms ${kallsymopt} | \
91 ${CC} ${aflags} -c -o ${2} -x assembler-with-cpp - 90 ${CC} ${aflags} -c -o ${2} -x assembler-with-cpp -
92 } 91 }
93 92
94 # Create map file with all symbols from ${1} 93 # Create map file with all symbols from ${1}
95 # See mksymap for additional details 94 # See mksymap for additional details
96 mksysmap() 95 mksysmap()
97 { 96 {
98 ${CONFIG_SHELL} "${srctree}/scripts/mksysmap" ${1} ${2} 97 ${CONFIG_SHELL} "${srctree}/scripts/mksysmap" ${1} ${2}
99 } 98 }
100 99
101 sortextable() 100 sortextable()
102 { 101 {
103 ${objtree}/scripts/sortextable ${1} 102 ${objtree}/scripts/sortextable ${1}
104 } 103 }
105 104
106 # Delete output files in case of error 105 # Delete output files in case of error
107 trap cleanup SIGHUP SIGINT SIGQUIT SIGTERM ERR 106 trap cleanup SIGHUP SIGINT SIGQUIT SIGTERM ERR
108 cleanup() 107 cleanup()
109 { 108 {
110 rm -f .old_version 109 rm -f .old_version
111 rm -f .tmp_System.map 110 rm -f .tmp_System.map
112 rm -f .tmp_kallsyms* 111 rm -f .tmp_kallsyms*
113 rm -f .tmp_version 112 rm -f .tmp_version
114 rm -f .tmp_vmlinux* 113 rm -f .tmp_vmlinux*
115 rm -f System.map 114 rm -f System.map
116 rm -f vmlinux 115 rm -f vmlinux
117 rm -f vmlinux.o 116 rm -f vmlinux.o
118 } 117 }
119 118
120 # 119 #
121 # 120 #
122 # Use "make V=1" to debug this script 121 # Use "make V=1" to debug this script
123 case "${KBUILD_VERBOSE}" in 122 case "${KBUILD_VERBOSE}" in
124 *1*) 123 *1*)
125 set -x 124 set -x
126 ;; 125 ;;
127 esac 126 esac
128 127
129 if [ "$1" = "clean" ]; then 128 if [ "$1" = "clean" ]; then
130 cleanup 129 cleanup
131 exit 0 130 exit 0
132 fi 131 fi
133 132
134 # We need access to CONFIG_ symbols 133 # We need access to CONFIG_ symbols
135 case "${KCONFIG_CONFIG}" in 134 case "${KCONFIG_CONFIG}" in
136 */*) 135 */*)
137 . "${KCONFIG_CONFIG}" 136 . "${KCONFIG_CONFIG}"
138 ;; 137 ;;
139 *) 138 *)
140 # Force using a file from the current directory 139 # Force using a file from the current directory
141 . "./${KCONFIG_CONFIG}" 140 . "./${KCONFIG_CONFIG}"
142 esac 141 esac
143 142
144 #link vmlinux.o 143 #link vmlinux.o
145 info LD vmlinux.o 144 info LD vmlinux.o
146 modpost_link vmlinux.o 145 modpost_link vmlinux.o
147 146
148 # modpost vmlinux.o to check for section mismatches 147 # modpost vmlinux.o to check for section mismatches
149 ${MAKE} -f "${srctree}/scripts/Makefile.modpost" vmlinux.o 148 ${MAKE} -f "${srctree}/scripts/Makefile.modpost" vmlinux.o
150 149
151 # Update version 150 # Update version
152 info GEN .version 151 info GEN .version
153 if [ ! -r .version ]; then 152 if [ ! -r .version ]; then
154 rm -f .version; 153 rm -f .version;
155 echo 1 >.version; 154 echo 1 >.version;
156 else 155 else
157 mv .version .old_version; 156 mv .version .old_version;
158 expr 0$(cat .old_version) + 1 >.version; 157 expr 0$(cat .old_version) + 1 >.version;
159 fi; 158 fi;
160 159
161 # final build of init/ 160 # final build of init/
162 ${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init 161 ${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
163 162
164 kallsymso="" 163 kallsymso=""
165 kallsyms_vmlinux="" 164 kallsyms_vmlinux=""
166 if [ -n "${CONFIG_KALLSYMS}" ]; then 165 if [ -n "${CONFIG_KALLSYMS}" ]; then
167 166
168 # kallsyms support 167 # kallsyms support
169 # Generate section listing all symbols and add it into vmlinux 168 # Generate section listing all symbols and add it into vmlinux
170 # It's a three step process: 169 # It's a three step process:
171 # 1) Link .tmp_vmlinux1 so it has all symbols and sections, 170 # 1) Link .tmp_vmlinux1 so it has all symbols and sections,
172 # but __kallsyms is empty. 171 # but __kallsyms is empty.
173 # Running kallsyms on that gives us .tmp_kallsyms1.o with 172 # Running kallsyms on that gives us .tmp_kallsyms1.o with
174 # the right size 173 # the right size
175 # 2) Link .tmp_vmlinux2 so it now has a __kallsyms section of 174 # 2) Link .tmp_vmlinux2 so it now has a __kallsyms section of
176 # the right size, but due to the added section, some 175 # the right size, but due to the added section, some
177 # addresses have shifted. 176 # addresses have shifted.
178 # From here, we generate a correct .tmp_kallsyms2.o 177 # From here, we generate a correct .tmp_kallsyms2.o
179 # 2a) We may use an extra pass as this has been necessary to 178 # 2a) We may use an extra pass as this has been necessary to
180 # woraround some alignment related bugs. 179 # woraround some alignment related bugs.
181 # KALLSYMS_EXTRA_PASS=1 is used to trigger this. 180 # KALLSYMS_EXTRA_PASS=1 is used to trigger this.
182 # 3) The correct ${kallsymso} is linked into the final vmlinux. 181 # 3) The correct ${kallsymso} is linked into the final vmlinux.
183 # 182 #
184 # a) Verify that the System.map from vmlinux matches the map from 183 # a) Verify that the System.map from vmlinux matches the map from
185 # ${kallsymso}. 184 # ${kallsymso}.
186 185
187 kallsymso=.tmp_kallsyms2.o 186 kallsymso=.tmp_kallsyms2.o
188 kallsyms_vmlinux=.tmp_vmlinux2 187 kallsyms_vmlinux=.tmp_vmlinux2
189 188
190 # step 1 189 # step 1
191 vmlinux_link "" .tmp_vmlinux1 190 vmlinux_link "" .tmp_vmlinux1
192 kallsyms .tmp_vmlinux1 .tmp_kallsyms1.o 191 kallsyms .tmp_vmlinux1 .tmp_kallsyms1.o
193 192
194 # step 2 193 # step 2
195 vmlinux_link .tmp_kallsyms1.o .tmp_vmlinux2 194 vmlinux_link .tmp_kallsyms1.o .tmp_vmlinux2
196 kallsyms .tmp_vmlinux2 .tmp_kallsyms2.o 195 kallsyms .tmp_vmlinux2 .tmp_kallsyms2.o
197 196
198 # step 2a 197 # step 2a
199 if [ -n "${KALLSYMS_EXTRA_PASS}" ]; then 198 if [ -n "${KALLSYMS_EXTRA_PASS}" ]; then
200 kallsymso=.tmp_kallsyms3.o 199 kallsymso=.tmp_kallsyms3.o
201 kallsyms_vmlinux=.tmp_vmlinux3 200 kallsyms_vmlinux=.tmp_vmlinux3
202 201
203 vmlinux_link .tmp_kallsyms2.o .tmp_vmlinux3 202 vmlinux_link .tmp_kallsyms2.o .tmp_vmlinux3
204 203
205 kallsyms .tmp_vmlinux3 .tmp_kallsyms3.o 204 kallsyms .tmp_vmlinux3 .tmp_kallsyms3.o
206 fi 205 fi
207 fi 206 fi
208 207
209 info LD vmlinux 208 info LD vmlinux
210 vmlinux_link "${kallsymso}" vmlinux 209 vmlinux_link "${kallsymso}" vmlinux
211 210
212 if [ -n "${CONFIG_BUILDTIME_EXTABLE_SORT}" ]; then 211 if [ -n "${CONFIG_BUILDTIME_EXTABLE_SORT}" ]; then
213 info SORTEX vmlinux 212 info SORTEX vmlinux
214 sortextable vmlinux 213 sortextable vmlinux
215 fi 214 fi
216 215
217 info SYSMAP System.map 216 info SYSMAP System.map
218 mksysmap vmlinux System.map 217 mksysmap vmlinux System.map
219 218
220 # step a (see comment above) 219 # step a (see comment above)
221 if [ -n "${CONFIG_KALLSYMS}" ]; then 220 if [ -n "${CONFIG_KALLSYMS}" ]; then
222 mksysmap ${kallsyms_vmlinux} .tmp_System.map 221 mksysmap ${kallsyms_vmlinux} .tmp_System.map
223 222
224 if ! cmp -s System.map .tmp_System.map; then 223 if ! cmp -s System.map .tmp_System.map; then
225 echo >&2 Inconsistent kallsyms data 224 echo >&2 Inconsistent kallsyms data
226 echo >&2 Try "make KALLSYMS_EXTRA_PASS=1" as a workaround 225 echo >&2 Try "make KALLSYMS_EXTRA_PASS=1" as a workaround
227 cleanup 226 cleanup
228 exit 1 227 exit 1
229 fi 228 fi
230 fi 229 fi
231 230
232 # We made a new kernel - delete old version file 231 # We made a new kernel - delete old version file
233 rm -f .old_version 232 rm -f .old_version
234 233
scripts/mod/modpost.c
1 /* Postprocess module symbol versions 1 /* Postprocess module symbol versions
2 * 2 *
3 * Copyright 2003 Kai Germaschewski 3 * Copyright 2003 Kai Germaschewski
4 * Copyright 2002-2004 Rusty Russell, IBM Corporation 4 * Copyright 2002-2004 Rusty Russell, IBM Corporation
5 * Copyright 2006-2008 Sam Ravnborg 5 * Copyright 2006-2008 Sam Ravnborg
6 * Based in part on module-init-tools/depmod.c,file2alias 6 * Based in part on module-init-tools/depmod.c,file2alias
7 * 7 *
8 * This software may be used and distributed according to the terms 8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference. 9 * of the GNU General Public License, incorporated herein by reference.
10 * 10 *
11 * Usage: modpost vmlinux module1.o module2.o ... 11 * Usage: modpost vmlinux module1.o module2.o ...
12 */ 12 */
13 13
14 #define _GNU_SOURCE 14 #define _GNU_SOURCE
15 #include <stdio.h> 15 #include <stdio.h>
16 #include <ctype.h> 16 #include <ctype.h>
17 #include <string.h> 17 #include <string.h>
18 #include <limits.h>
19 #include <stdbool.h>
18 #include "modpost.h" 20 #include "modpost.h"
19 #include "../../include/generated/autoconf.h" 21 #include "../../include/generated/autoconf.h"
20 #include "../../include/linux/license.h" 22 #include "../../include/linux/license.h"
23 #include "../../include/linux/export.h"
21 24
22 /* Some toolchains use a `_' prefix for all user symbols. */
23 #ifdef CONFIG_SYMBOL_PREFIX
24 #define MODULE_SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX
25 #else
26 #define MODULE_SYMBOL_PREFIX ""
27 #endif
28
29
30 /* Are we using CONFIG_MODVERSIONS? */ 25 /* Are we using CONFIG_MODVERSIONS? */
31 int modversions = 0; 26 int modversions = 0;
32 /* Warn about undefined symbols? (do so if we have vmlinux) */ 27 /* Warn about undefined symbols? (do so if we have vmlinux) */
33 int have_vmlinux = 0; 28 int have_vmlinux = 0;
34 /* Is CONFIG_MODULE_SRCVERSION_ALL set? */ 29 /* Is CONFIG_MODULE_SRCVERSION_ALL set? */
35 static int all_versions = 0; 30 static int all_versions = 0;
36 /* If we are modposting external module set to 1 */ 31 /* If we are modposting external module set to 1 */
37 static int external_module = 0; 32 static int external_module = 0;
38 /* Warn about section mismatch in vmlinux if set to 1 */ 33 /* Warn about section mismatch in vmlinux if set to 1 */
39 static int vmlinux_section_warnings = 1; 34 static int vmlinux_section_warnings = 1;
40 /* Only warn about unresolved symbols */ 35 /* Only warn about unresolved symbols */
41 static int warn_unresolved = 0; 36 static int warn_unresolved = 0;
42 /* How a symbol is exported */ 37 /* How a symbol is exported */
43 static int sec_mismatch_count = 0; 38 static int sec_mismatch_count = 0;
44 static int sec_mismatch_verbose = 1; 39 static int sec_mismatch_verbose = 1;
45 40
46 enum export { 41 enum export {
47 export_plain, export_unused, export_gpl, 42 export_plain, export_unused, export_gpl,
48 export_unused_gpl, export_gpl_future, export_unknown 43 export_unused_gpl, export_gpl_future, export_unknown
49 }; 44 };
50 45
51 #define PRINTF __attribute__ ((format (printf, 1, 2))) 46 #define PRINTF __attribute__ ((format (printf, 1, 2)))
52 47
53 PRINTF void fatal(const char *fmt, ...) 48 PRINTF void fatal(const char *fmt, ...)
54 { 49 {
55 va_list arglist; 50 va_list arglist;
56 51
57 fprintf(stderr, "FATAL: "); 52 fprintf(stderr, "FATAL: ");
58 53
59 va_start(arglist, fmt); 54 va_start(arglist, fmt);
60 vfprintf(stderr, fmt, arglist); 55 vfprintf(stderr, fmt, arglist);
61 va_end(arglist); 56 va_end(arglist);
62 57
63 exit(1); 58 exit(1);
64 } 59 }
65 60
66 PRINTF void warn(const char *fmt, ...) 61 PRINTF void warn(const char *fmt, ...)
67 { 62 {
68 va_list arglist; 63 va_list arglist;
69 64
70 fprintf(stderr, "WARNING: "); 65 fprintf(stderr, "WARNING: ");
71 66
72 va_start(arglist, fmt); 67 va_start(arglist, fmt);
73 vfprintf(stderr, fmt, arglist); 68 vfprintf(stderr, fmt, arglist);
74 va_end(arglist); 69 va_end(arglist);
75 } 70 }
76 71
77 PRINTF void merror(const char *fmt, ...) 72 PRINTF void merror(const char *fmt, ...)
78 { 73 {
79 va_list arglist; 74 va_list arglist;
80 75
81 fprintf(stderr, "ERROR: "); 76 fprintf(stderr, "ERROR: ");
82 77
83 va_start(arglist, fmt); 78 va_start(arglist, fmt);
84 vfprintf(stderr, fmt, arglist); 79 vfprintf(stderr, fmt, arglist);
85 va_end(arglist); 80 va_end(arglist);
86 } 81 }
87 82
83 static inline bool strends(const char *str, const char *postfix)
84 {
85 if (strlen(str) < strlen(postfix))
86 return false;
87
88 return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0;
89 }
90
88 static int is_vmlinux(const char *modname) 91 static int is_vmlinux(const char *modname)
89 { 92 {
90 const char *myname; 93 const char *myname;
91 94
92 myname = strrchr(modname, '/'); 95 myname = strrchr(modname, '/');
93 if (myname) 96 if (myname)
94 myname++; 97 myname++;
95 else 98 else
96 myname = modname; 99 myname = modname;
97 100
98 return (strcmp(myname, "vmlinux") == 0) || 101 return (strcmp(myname, "vmlinux") == 0) ||
99 (strcmp(myname, "vmlinux.o") == 0); 102 (strcmp(myname, "vmlinux.o") == 0);
100 } 103 }
101 104
102 void *do_nofail(void *ptr, const char *expr) 105 void *do_nofail(void *ptr, const char *expr)
103 { 106 {
104 if (!ptr) 107 if (!ptr)
105 fatal("modpost: Memory allocation failure: %s.\n", expr); 108 fatal("modpost: Memory allocation failure: %s.\n", expr);
106 109
107 return ptr; 110 return ptr;
108 } 111 }
109 112
110 /* A list of all modules we processed */ 113 /* A list of all modules we processed */
111 static struct module *modules; 114 static struct module *modules;
112 115
113 static struct module *find_module(char *modname) 116 static struct module *find_module(char *modname)
114 { 117 {
115 struct module *mod; 118 struct module *mod;
116 119
117 for (mod = modules; mod; mod = mod->next) 120 for (mod = modules; mod; mod = mod->next)
118 if (strcmp(mod->name, modname) == 0) 121 if (strcmp(mod->name, modname) == 0)
119 break; 122 break;
120 return mod; 123 return mod;
121 } 124 }
122 125
123 static struct module *new_module(char *modname) 126 static struct module *new_module(const char *modname)
124 { 127 {
125 struct module *mod; 128 struct module *mod;
126 char *p, *s; 129 char *p;
127 130
128 mod = NOFAIL(malloc(sizeof(*mod))); 131 mod = NOFAIL(malloc(sizeof(*mod)));
129 memset(mod, 0, sizeof(*mod)); 132 memset(mod, 0, sizeof(*mod));
130 p = NOFAIL(strdup(modname)); 133 p = NOFAIL(strdup(modname));
131 134
132 /* strip trailing .o */ 135 /* strip trailing .o */
133 s = strrchr(p, '.'); 136 if (strends(p, ".o")) {
134 if (s != NULL) 137 p[strlen(p) - 2] = '\0';
135 if (strcmp(s, ".o") == 0) { 138 mod->is_dot_o = 1;
136 *s = '\0'; 139 }
137 mod->is_dot_o = 1;
138 }
139 140
140 /* add to list */ 141 /* add to list */
141 mod->name = p; 142 mod->name = p;
142 mod->gpl_compatible = -1; 143 mod->gpl_compatible = -1;
143 mod->next = modules; 144 mod->next = modules;
144 modules = mod; 145 modules = mod;
145 146
146 return mod; 147 return mod;
147 } 148 }
148 149
149 /* A hash of all exported symbols, 150 /* A hash of all exported symbols,
150 * struct symbol is also used for lists of unresolved symbols */ 151 * struct symbol is also used for lists of unresolved symbols */
151 152
152 #define SYMBOL_HASH_SIZE 1024 153 #define SYMBOL_HASH_SIZE 1024
153 154
154 struct symbol { 155 struct symbol {
155 struct symbol *next; 156 struct symbol *next;
156 struct module *module; 157 struct module *module;
157 unsigned int crc; 158 unsigned int crc;
158 int crc_valid; 159 int crc_valid;
159 unsigned int weak:1; 160 unsigned int weak:1;
160 unsigned int vmlinux:1; /* 1 if symbol is defined in vmlinux */ 161 unsigned int vmlinux:1; /* 1 if symbol is defined in vmlinux */
161 unsigned int kernel:1; /* 1 if symbol is from kernel 162 unsigned int kernel:1; /* 1 if symbol is from kernel
162 * (only for external modules) **/ 163 * (only for external modules) **/
163 unsigned int preloaded:1; /* 1 if symbol from Module.symvers */ 164 unsigned int preloaded:1; /* 1 if symbol from Module.symvers */
164 enum export export; /* Type of export */ 165 enum export export; /* Type of export */
165 char name[0]; 166 char name[0];
166 }; 167 };
167 168
168 static struct symbol *symbolhash[SYMBOL_HASH_SIZE]; 169 static struct symbol *symbolhash[SYMBOL_HASH_SIZE];
169 170
170 /* This is based on the hash agorithm from gdbm, via tdb */ 171 /* This is based on the hash agorithm from gdbm, via tdb */
171 static inline unsigned int tdb_hash(const char *name) 172 static inline unsigned int tdb_hash(const char *name)
172 { 173 {
173 unsigned value; /* Used to compute the hash value. */ 174 unsigned value; /* Used to compute the hash value. */
174 unsigned i; /* Used to cycle through random values. */ 175 unsigned i; /* Used to cycle through random values. */
175 176
176 /* Set the initial value from the key size. */ 177 /* Set the initial value from the key size. */
177 for (value = 0x238F13AF * strlen(name), i = 0; name[i]; i++) 178 for (value = 0x238F13AF * strlen(name), i = 0; name[i]; i++)
178 value = (value + (((unsigned char *)name)[i] << (i*5 % 24))); 179 value = (value + (((unsigned char *)name)[i] << (i*5 % 24)));
179 180
180 return (1103515243 * value + 12345); 181 return (1103515243 * value + 12345);
181 } 182 }
182 183
183 /** 184 /**
184 * Allocate a new symbols for use in the hash of exported symbols or 185 * Allocate a new symbols for use in the hash of exported symbols or
185 * the list of unresolved symbols per module 186 * the list of unresolved symbols per module
186 **/ 187 **/
187 static struct symbol *alloc_symbol(const char *name, unsigned int weak, 188 static struct symbol *alloc_symbol(const char *name, unsigned int weak,
188 struct symbol *next) 189 struct symbol *next)
189 { 190 {
190 struct symbol *s = NOFAIL(malloc(sizeof(*s) + strlen(name) + 1)); 191 struct symbol *s = NOFAIL(malloc(sizeof(*s) + strlen(name) + 1));
191 192
192 memset(s, 0, sizeof(*s)); 193 memset(s, 0, sizeof(*s));
193 strcpy(s->name, name); 194 strcpy(s->name, name);
194 s->weak = weak; 195 s->weak = weak;
195 s->next = next; 196 s->next = next;
196 return s; 197 return s;
197 } 198 }
198 199
199 /* For the hash of exported symbols */ 200 /* For the hash of exported symbols */
200 static struct symbol *new_symbol(const char *name, struct module *module, 201 static struct symbol *new_symbol(const char *name, struct module *module,
201 enum export export) 202 enum export export)
202 { 203 {
203 unsigned int hash; 204 unsigned int hash;
204 struct symbol *new; 205 struct symbol *new;
205 206
206 hash = tdb_hash(name) % SYMBOL_HASH_SIZE; 207 hash = tdb_hash(name) % SYMBOL_HASH_SIZE;
207 new = symbolhash[hash] = alloc_symbol(name, 0, symbolhash[hash]); 208 new = symbolhash[hash] = alloc_symbol(name, 0, symbolhash[hash]);
208 new->module = module; 209 new->module = module;
209 new->export = export; 210 new->export = export;
210 return new; 211 return new;
211 } 212 }
212 213
213 static struct symbol *find_symbol(const char *name) 214 static struct symbol *find_symbol(const char *name)
214 { 215 {
215 struct symbol *s; 216 struct symbol *s;
216 217
217 /* For our purposes, .foo matches foo. PPC64 needs this. */ 218 /* For our purposes, .foo matches foo. PPC64 needs this. */
218 if (name[0] == '.') 219 if (name[0] == '.')
219 name++; 220 name++;
220 221
221 for (s = symbolhash[tdb_hash(name) % SYMBOL_HASH_SIZE]; s; s = s->next) { 222 for (s = symbolhash[tdb_hash(name) % SYMBOL_HASH_SIZE]; s; s = s->next) {
222 if (strcmp(s->name, name) == 0) 223 if (strcmp(s->name, name) == 0)
223 return s; 224 return s;
224 } 225 }
225 return NULL; 226 return NULL;
226 } 227 }
227 228
228 static struct { 229 static struct {
229 const char *str; 230 const char *str;
230 enum export export; 231 enum export export;
231 } export_list[] = { 232 } export_list[] = {
232 { .str = "EXPORT_SYMBOL", .export = export_plain }, 233 { .str = "EXPORT_SYMBOL", .export = export_plain },
233 { .str = "EXPORT_UNUSED_SYMBOL", .export = export_unused }, 234 { .str = "EXPORT_UNUSED_SYMBOL", .export = export_unused },
234 { .str = "EXPORT_SYMBOL_GPL", .export = export_gpl }, 235 { .str = "EXPORT_SYMBOL_GPL", .export = export_gpl },
235 { .str = "EXPORT_UNUSED_SYMBOL_GPL", .export = export_unused_gpl }, 236 { .str = "EXPORT_UNUSED_SYMBOL_GPL", .export = export_unused_gpl },
236 { .str = "EXPORT_SYMBOL_GPL_FUTURE", .export = export_gpl_future }, 237 { .str = "EXPORT_SYMBOL_GPL_FUTURE", .export = export_gpl_future },
237 { .str = "(unknown)", .export = export_unknown }, 238 { .str = "(unknown)", .export = export_unknown },
238 }; 239 };
239 240
240 241
241 static const char *export_str(enum export ex) 242 static const char *export_str(enum export ex)
242 { 243 {
243 return export_list[ex].str; 244 return export_list[ex].str;
244 } 245 }
245 246
246 static enum export export_no(const char *s) 247 static enum export export_no(const char *s)
247 { 248 {
248 int i; 249 int i;
249 250
250 if (!s) 251 if (!s)
251 return export_unknown; 252 return export_unknown;
252 for (i = 0; export_list[i].export != export_unknown; i++) { 253 for (i = 0; export_list[i].export != export_unknown; i++) {
253 if (strcmp(export_list[i].str, s) == 0) 254 if (strcmp(export_list[i].str, s) == 0)
254 return export_list[i].export; 255 return export_list[i].export;
255 } 256 }
256 return export_unknown; 257 return export_unknown;
257 } 258 }
258 259
259 static const char *sec_name(struct elf_info *elf, int secindex); 260 static const char *sec_name(struct elf_info *elf, int secindex);
260 261
261 #define strstarts(str, prefix) (strncmp(str, prefix, strlen(prefix)) == 0) 262 #define strstarts(str, prefix) (strncmp(str, prefix, strlen(prefix)) == 0)
262 263
263 static enum export export_from_secname(struct elf_info *elf, unsigned int sec) 264 static enum export export_from_secname(struct elf_info *elf, unsigned int sec)
264 { 265 {
265 const char *secname = sec_name(elf, sec); 266 const char *secname = sec_name(elf, sec);
266 267
267 if (strstarts(secname, "___ksymtab+")) 268 if (strstarts(secname, "___ksymtab+"))
268 return export_plain; 269 return export_plain;
269 else if (strstarts(secname, "___ksymtab_unused+")) 270 else if (strstarts(secname, "___ksymtab_unused+"))
270 return export_unused; 271 return export_unused;
271 else if (strstarts(secname, "___ksymtab_gpl+")) 272 else if (strstarts(secname, "___ksymtab_gpl+"))
272 return export_gpl; 273 return export_gpl;
273 else if (strstarts(secname, "___ksymtab_unused_gpl+")) 274 else if (strstarts(secname, "___ksymtab_unused_gpl+"))
274 return export_unused_gpl; 275 return export_unused_gpl;
275 else if (strstarts(secname, "___ksymtab_gpl_future+")) 276 else if (strstarts(secname, "___ksymtab_gpl_future+"))
276 return export_gpl_future; 277 return export_gpl_future;
277 else 278 else
278 return export_unknown; 279 return export_unknown;
279 } 280 }
280 281
281 static enum export export_from_sec(struct elf_info *elf, unsigned int sec) 282 static enum export export_from_sec(struct elf_info *elf, unsigned int sec)
282 { 283 {
283 if (sec == elf->export_sec) 284 if (sec == elf->export_sec)
284 return export_plain; 285 return export_plain;
285 else if (sec == elf->export_unused_sec) 286 else if (sec == elf->export_unused_sec)
286 return export_unused; 287 return export_unused;
287 else if (sec == elf->export_gpl_sec) 288 else if (sec == elf->export_gpl_sec)
288 return export_gpl; 289 return export_gpl;
289 else if (sec == elf->export_unused_gpl_sec) 290 else if (sec == elf->export_unused_gpl_sec)
290 return export_unused_gpl; 291 return export_unused_gpl;
291 else if (sec == elf->export_gpl_future_sec) 292 else if (sec == elf->export_gpl_future_sec)
292 return export_gpl_future; 293 return export_gpl_future;
293 else 294 else
294 return export_unknown; 295 return export_unknown;
295 } 296 }
296 297
297 /** 298 /**
298 * Add an exported symbol - it may have already been added without a 299 * Add an exported symbol - it may have already been added without a
299 * CRC, in this case just update the CRC 300 * CRC, in this case just update the CRC
300 **/ 301 **/
301 static struct symbol *sym_add_exported(const char *name, struct module *mod, 302 static struct symbol *sym_add_exported(const char *name, struct module *mod,
302 enum export export) 303 enum export export)
303 { 304 {
304 struct symbol *s = find_symbol(name); 305 struct symbol *s = find_symbol(name);
305 306
306 if (!s) { 307 if (!s) {
307 s = new_symbol(name, mod, export); 308 s = new_symbol(name, mod, export);
308 } else { 309 } else {
309 if (!s->preloaded) { 310 if (!s->preloaded) {
310 warn("%s: '%s' exported twice. Previous export " 311 warn("%s: '%s' exported twice. Previous export "
311 "was in %s%s\n", mod->name, name, 312 "was in %s%s\n", mod->name, name,
312 s->module->name, 313 s->module->name,
313 is_vmlinux(s->module->name) ?"":".ko"); 314 is_vmlinux(s->module->name) ?"":".ko");
314 } else { 315 } else {
315 /* In case Modules.symvers was out of date */ 316 /* In case Modules.symvers was out of date */
316 s->module = mod; 317 s->module = mod;
317 } 318 }
318 } 319 }
319 s->preloaded = 0; 320 s->preloaded = 0;
320 s->vmlinux = is_vmlinux(mod->name); 321 s->vmlinux = is_vmlinux(mod->name);
321 s->kernel = 0; 322 s->kernel = 0;
322 s->export = export; 323 s->export = export;
323 return s; 324 return s;
324 } 325 }
325 326
326 static void sym_update_crc(const char *name, struct module *mod, 327 static void sym_update_crc(const char *name, struct module *mod,
327 unsigned int crc, enum export export) 328 unsigned int crc, enum export export)
328 { 329 {
329 struct symbol *s = find_symbol(name); 330 struct symbol *s = find_symbol(name);
330 331
331 if (!s) 332 if (!s)
332 s = new_symbol(name, mod, export); 333 s = new_symbol(name, mod, export);
333 s->crc = crc; 334 s->crc = crc;
334 s->crc_valid = 1; 335 s->crc_valid = 1;
335 } 336 }
336 337
337 void *grab_file(const char *filename, unsigned long *size) 338 void *grab_file(const char *filename, unsigned long *size)
338 { 339 {
339 struct stat st; 340 struct stat st;
340 void *map = MAP_FAILED; 341 void *map = MAP_FAILED;
341 int fd; 342 int fd;
342 343
343 fd = open(filename, O_RDONLY); 344 fd = open(filename, O_RDONLY);
344 if (fd < 0) 345 if (fd < 0)
345 return NULL; 346 return NULL;
346 if (fstat(fd, &st)) 347 if (fstat(fd, &st))
347 goto failed; 348 goto failed;
348 349
349 *size = st.st_size; 350 *size = st.st_size;
350 map = mmap(NULL, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); 351 map = mmap(NULL, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
351 352
352 failed: 353 failed:
353 close(fd); 354 close(fd);
354 if (map == MAP_FAILED) 355 if (map == MAP_FAILED)
355 return NULL; 356 return NULL;
356 return map; 357 return map;
357 } 358 }
358 359
359 /** 360 /**
360 * Return a copy of the next line in a mmap'ed file. 361 * Return a copy of the next line in a mmap'ed file.
361 * spaces in the beginning of the line is trimmed away. 362 * spaces in the beginning of the line is trimmed away.
362 * Return a pointer to a static buffer. 363 * Return a pointer to a static buffer.
363 **/ 364 **/
364 char *get_next_line(unsigned long *pos, void *file, unsigned long size) 365 char *get_next_line(unsigned long *pos, void *file, unsigned long size)
365 { 366 {
366 static char line[4096]; 367 static char line[4096];
367 int skip = 1; 368 int skip = 1;
368 size_t len = 0; 369 size_t len = 0;
369 signed char *p = (signed char *)file + *pos; 370 signed char *p = (signed char *)file + *pos;
370 char *s = line; 371 char *s = line;
371 372
372 for (; *pos < size ; (*pos)++) { 373 for (; *pos < size ; (*pos)++) {
373 if (skip && isspace(*p)) { 374 if (skip && isspace(*p)) {
374 p++; 375 p++;
375 continue; 376 continue;
376 } 377 }
377 skip = 0; 378 skip = 0;
378 if (*p != '\n' && (*pos < size)) { 379 if (*p != '\n' && (*pos < size)) {
379 len++; 380 len++;
380 *s++ = *p++; 381 *s++ = *p++;
381 if (len > 4095) 382 if (len > 4095)
382 break; /* Too long, stop */ 383 break; /* Too long, stop */
383 } else { 384 } else {
384 /* End of string */ 385 /* End of string */
385 *s = '\0'; 386 *s = '\0';
386 return line; 387 return line;
387 } 388 }
388 } 389 }
389 /* End of buffer */ 390 /* End of buffer */
390 return NULL; 391 return NULL;
391 } 392 }
392 393
393 void release_file(void *file, unsigned long size) 394 void release_file(void *file, unsigned long size)
394 { 395 {
395 munmap(file, size); 396 munmap(file, size);
396 } 397 }
397 398
398 static int parse_elf(struct elf_info *info, const char *filename) 399 static int parse_elf(struct elf_info *info, const char *filename)
399 { 400 {
400 unsigned int i; 401 unsigned int i;
401 Elf_Ehdr *hdr; 402 Elf_Ehdr *hdr;
402 Elf_Shdr *sechdrs; 403 Elf_Shdr *sechdrs;
403 Elf_Sym *sym; 404 Elf_Sym *sym;
404 const char *secstrings; 405 const char *secstrings;
405 unsigned int symtab_idx = ~0U, symtab_shndx_idx = ~0U; 406 unsigned int symtab_idx = ~0U, symtab_shndx_idx = ~0U;
406 407
407 hdr = grab_file(filename, &info->size); 408 hdr = grab_file(filename, &info->size);
408 if (!hdr) { 409 if (!hdr) {
409 perror(filename); 410 perror(filename);
410 exit(1); 411 exit(1);
411 } 412 }
412 info->hdr = hdr; 413 info->hdr = hdr;
413 if (info->size < sizeof(*hdr)) { 414 if (info->size < sizeof(*hdr)) {
414 /* file too small, assume this is an empty .o file */ 415 /* file too small, assume this is an empty .o file */
415 return 0; 416 return 0;
416 } 417 }
417 /* Is this a valid ELF file? */ 418 /* Is this a valid ELF file? */
418 if ((hdr->e_ident[EI_MAG0] != ELFMAG0) || 419 if ((hdr->e_ident[EI_MAG0] != ELFMAG0) ||
419 (hdr->e_ident[EI_MAG1] != ELFMAG1) || 420 (hdr->e_ident[EI_MAG1] != ELFMAG1) ||
420 (hdr->e_ident[EI_MAG2] != ELFMAG2) || 421 (hdr->e_ident[EI_MAG2] != ELFMAG2) ||
421 (hdr->e_ident[EI_MAG3] != ELFMAG3)) { 422 (hdr->e_ident[EI_MAG3] != ELFMAG3)) {
422 /* Not an ELF file - silently ignore it */ 423 /* Not an ELF file - silently ignore it */
423 return 0; 424 return 0;
424 } 425 }
425 /* Fix endianness in ELF header */ 426 /* Fix endianness in ELF header */
426 hdr->e_type = TO_NATIVE(hdr->e_type); 427 hdr->e_type = TO_NATIVE(hdr->e_type);
427 hdr->e_machine = TO_NATIVE(hdr->e_machine); 428 hdr->e_machine = TO_NATIVE(hdr->e_machine);
428 hdr->e_version = TO_NATIVE(hdr->e_version); 429 hdr->e_version = TO_NATIVE(hdr->e_version);
429 hdr->e_entry = TO_NATIVE(hdr->e_entry); 430 hdr->e_entry = TO_NATIVE(hdr->e_entry);
430 hdr->e_phoff = TO_NATIVE(hdr->e_phoff); 431 hdr->e_phoff = TO_NATIVE(hdr->e_phoff);
431 hdr->e_shoff = TO_NATIVE(hdr->e_shoff); 432 hdr->e_shoff = TO_NATIVE(hdr->e_shoff);
432 hdr->e_flags = TO_NATIVE(hdr->e_flags); 433 hdr->e_flags = TO_NATIVE(hdr->e_flags);
433 hdr->e_ehsize = TO_NATIVE(hdr->e_ehsize); 434 hdr->e_ehsize = TO_NATIVE(hdr->e_ehsize);
434 hdr->e_phentsize = TO_NATIVE(hdr->e_phentsize); 435 hdr->e_phentsize = TO_NATIVE(hdr->e_phentsize);
435 hdr->e_phnum = TO_NATIVE(hdr->e_phnum); 436 hdr->e_phnum = TO_NATIVE(hdr->e_phnum);
436 hdr->e_shentsize = TO_NATIVE(hdr->e_shentsize); 437 hdr->e_shentsize = TO_NATIVE(hdr->e_shentsize);
437 hdr->e_shnum = TO_NATIVE(hdr->e_shnum); 438 hdr->e_shnum = TO_NATIVE(hdr->e_shnum);
438 hdr->e_shstrndx = TO_NATIVE(hdr->e_shstrndx); 439 hdr->e_shstrndx = TO_NATIVE(hdr->e_shstrndx);
439 sechdrs = (void *)hdr + hdr->e_shoff; 440 sechdrs = (void *)hdr + hdr->e_shoff;
440 info->sechdrs = sechdrs; 441 info->sechdrs = sechdrs;
441 442
442 /* Check if file offset is correct */ 443 /* Check if file offset is correct */
443 if (hdr->e_shoff > info->size) { 444 if (hdr->e_shoff > info->size) {
444 fatal("section header offset=%lu in file '%s' is bigger than " 445 fatal("section header offset=%lu in file '%s' is bigger than "
445 "filesize=%lu\n", (unsigned long)hdr->e_shoff, 446 "filesize=%lu\n", (unsigned long)hdr->e_shoff,
446 filename, info->size); 447 filename, info->size);
447 return 0; 448 return 0;
448 } 449 }
449 450
450 if (hdr->e_shnum == SHN_UNDEF) { 451 if (hdr->e_shnum == SHN_UNDEF) {
451 /* 452 /*
452 * There are more than 64k sections, 453 * There are more than 64k sections,
453 * read count from .sh_size. 454 * read count from .sh_size.
454 */ 455 */
455 info->num_sections = TO_NATIVE(sechdrs[0].sh_size); 456 info->num_sections = TO_NATIVE(sechdrs[0].sh_size);
456 } 457 }
457 else { 458 else {
458 info->num_sections = hdr->e_shnum; 459 info->num_sections = hdr->e_shnum;
459 } 460 }
460 if (hdr->e_shstrndx == SHN_XINDEX) { 461 if (hdr->e_shstrndx == SHN_XINDEX) {
461 info->secindex_strings = TO_NATIVE(sechdrs[0].sh_link); 462 info->secindex_strings = TO_NATIVE(sechdrs[0].sh_link);
462 } 463 }
463 else { 464 else {
464 info->secindex_strings = hdr->e_shstrndx; 465 info->secindex_strings = hdr->e_shstrndx;
465 } 466 }
466 467
467 /* Fix endianness in section headers */ 468 /* Fix endianness in section headers */
468 for (i = 0; i < info->num_sections; i++) { 469 for (i = 0; i < info->num_sections; i++) {
469 sechdrs[i].sh_name = TO_NATIVE(sechdrs[i].sh_name); 470 sechdrs[i].sh_name = TO_NATIVE(sechdrs[i].sh_name);
470 sechdrs[i].sh_type = TO_NATIVE(sechdrs[i].sh_type); 471 sechdrs[i].sh_type = TO_NATIVE(sechdrs[i].sh_type);
471 sechdrs[i].sh_flags = TO_NATIVE(sechdrs[i].sh_flags); 472 sechdrs[i].sh_flags = TO_NATIVE(sechdrs[i].sh_flags);
472 sechdrs[i].sh_addr = TO_NATIVE(sechdrs[i].sh_addr); 473 sechdrs[i].sh_addr = TO_NATIVE(sechdrs[i].sh_addr);
473 sechdrs[i].sh_offset = TO_NATIVE(sechdrs[i].sh_offset); 474 sechdrs[i].sh_offset = TO_NATIVE(sechdrs[i].sh_offset);
474 sechdrs[i].sh_size = TO_NATIVE(sechdrs[i].sh_size); 475 sechdrs[i].sh_size = TO_NATIVE(sechdrs[i].sh_size);
475 sechdrs[i].sh_link = TO_NATIVE(sechdrs[i].sh_link); 476 sechdrs[i].sh_link = TO_NATIVE(sechdrs[i].sh_link);
476 sechdrs[i].sh_info = TO_NATIVE(sechdrs[i].sh_info); 477 sechdrs[i].sh_info = TO_NATIVE(sechdrs[i].sh_info);
477 sechdrs[i].sh_addralign = TO_NATIVE(sechdrs[i].sh_addralign); 478 sechdrs[i].sh_addralign = TO_NATIVE(sechdrs[i].sh_addralign);
478 sechdrs[i].sh_entsize = TO_NATIVE(sechdrs[i].sh_entsize); 479 sechdrs[i].sh_entsize = TO_NATIVE(sechdrs[i].sh_entsize);
479 } 480 }
480 /* Find symbol table. */ 481 /* Find symbol table. */
481 secstrings = (void *)hdr + sechdrs[info->secindex_strings].sh_offset; 482 secstrings = (void *)hdr + sechdrs[info->secindex_strings].sh_offset;
482 for (i = 1; i < info->num_sections; i++) { 483 for (i = 1; i < info->num_sections; i++) {
483 const char *secname; 484 const char *secname;
484 int nobits = sechdrs[i].sh_type == SHT_NOBITS; 485 int nobits = sechdrs[i].sh_type == SHT_NOBITS;
485 486
486 if (!nobits && sechdrs[i].sh_offset > info->size) { 487 if (!nobits && sechdrs[i].sh_offset > info->size) {
487 fatal("%s is truncated. sechdrs[i].sh_offset=%lu > " 488 fatal("%s is truncated. sechdrs[i].sh_offset=%lu > "
488 "sizeof(*hrd)=%zu\n", filename, 489 "sizeof(*hrd)=%zu\n", filename,
489 (unsigned long)sechdrs[i].sh_offset, 490 (unsigned long)sechdrs[i].sh_offset,
490 sizeof(*hdr)); 491 sizeof(*hdr));
491 return 0; 492 return 0;
492 } 493 }
493 secname = secstrings + sechdrs[i].sh_name; 494 secname = secstrings + sechdrs[i].sh_name;
494 if (strcmp(secname, ".modinfo") == 0) { 495 if (strcmp(secname, ".modinfo") == 0) {
495 if (nobits) 496 if (nobits)
496 fatal("%s has NOBITS .modinfo\n", filename); 497 fatal("%s has NOBITS .modinfo\n", filename);
497 info->modinfo = (void *)hdr + sechdrs[i].sh_offset; 498 info->modinfo = (void *)hdr + sechdrs[i].sh_offset;
498 info->modinfo_len = sechdrs[i].sh_size; 499 info->modinfo_len = sechdrs[i].sh_size;
499 } else if (strcmp(secname, "__ksymtab") == 0) 500 } else if (strcmp(secname, "__ksymtab") == 0)
500 info->export_sec = i; 501 info->export_sec = i;
501 else if (strcmp(secname, "__ksymtab_unused") == 0) 502 else if (strcmp(secname, "__ksymtab_unused") == 0)
502 info->export_unused_sec = i; 503 info->export_unused_sec = i;
503 else if (strcmp(secname, "__ksymtab_gpl") == 0) 504 else if (strcmp(secname, "__ksymtab_gpl") == 0)
504 info->export_gpl_sec = i; 505 info->export_gpl_sec = i;
505 else if (strcmp(secname, "__ksymtab_unused_gpl") == 0) 506 else if (strcmp(secname, "__ksymtab_unused_gpl") == 0)
506 info->export_unused_gpl_sec = i; 507 info->export_unused_gpl_sec = i;
507 else if (strcmp(secname, "__ksymtab_gpl_future") == 0) 508 else if (strcmp(secname, "__ksymtab_gpl_future") == 0)
508 info->export_gpl_future_sec = i; 509 info->export_gpl_future_sec = i;
509 510
510 if (sechdrs[i].sh_type == SHT_SYMTAB) { 511 if (sechdrs[i].sh_type == SHT_SYMTAB) {
511 unsigned int sh_link_idx; 512 unsigned int sh_link_idx;
512 symtab_idx = i; 513 symtab_idx = i;
513 info->symtab_start = (void *)hdr + 514 info->symtab_start = (void *)hdr +
514 sechdrs[i].sh_offset; 515 sechdrs[i].sh_offset;
515 info->symtab_stop = (void *)hdr + 516 info->symtab_stop = (void *)hdr +
516 sechdrs[i].sh_offset + sechdrs[i].sh_size; 517 sechdrs[i].sh_offset + sechdrs[i].sh_size;
517 sh_link_idx = sechdrs[i].sh_link; 518 sh_link_idx = sechdrs[i].sh_link;
518 info->strtab = (void *)hdr + 519 info->strtab = (void *)hdr +
519 sechdrs[sh_link_idx].sh_offset; 520 sechdrs[sh_link_idx].sh_offset;
520 } 521 }
521 522
522 /* 32bit section no. table? ("more than 64k sections") */ 523 /* 32bit section no. table? ("more than 64k sections") */
523 if (sechdrs[i].sh_type == SHT_SYMTAB_SHNDX) { 524 if (sechdrs[i].sh_type == SHT_SYMTAB_SHNDX) {
524 symtab_shndx_idx = i; 525 symtab_shndx_idx = i;
525 info->symtab_shndx_start = (void *)hdr + 526 info->symtab_shndx_start = (void *)hdr +
526 sechdrs[i].sh_offset; 527 sechdrs[i].sh_offset;
527 info->symtab_shndx_stop = (void *)hdr + 528 info->symtab_shndx_stop = (void *)hdr +
528 sechdrs[i].sh_offset + sechdrs[i].sh_size; 529 sechdrs[i].sh_offset + sechdrs[i].sh_size;
529 } 530 }
530 } 531 }
531 if (!info->symtab_start) 532 if (!info->symtab_start)
532 fatal("%s has no symtab?\n", filename); 533 fatal("%s has no symtab?\n", filename);
533 534
534 /* Fix endianness in symbols */ 535 /* Fix endianness in symbols */
535 for (sym = info->symtab_start; sym < info->symtab_stop; sym++) { 536 for (sym = info->symtab_start; sym < info->symtab_stop; sym++) {
536 sym->st_shndx = TO_NATIVE(sym->st_shndx); 537 sym->st_shndx = TO_NATIVE(sym->st_shndx);
537 sym->st_name = TO_NATIVE(sym->st_name); 538 sym->st_name = TO_NATIVE(sym->st_name);
538 sym->st_value = TO_NATIVE(sym->st_value); 539 sym->st_value = TO_NATIVE(sym->st_value);
539 sym->st_size = TO_NATIVE(sym->st_size); 540 sym->st_size = TO_NATIVE(sym->st_size);
540 } 541 }
541 542
542 if (symtab_shndx_idx != ~0U) { 543 if (symtab_shndx_idx != ~0U) {
543 Elf32_Word *p; 544 Elf32_Word *p;
544 if (symtab_idx != sechdrs[symtab_shndx_idx].sh_link) 545 if (symtab_idx != sechdrs[symtab_shndx_idx].sh_link)
545 fatal("%s: SYMTAB_SHNDX has bad sh_link: %u!=%u\n", 546 fatal("%s: SYMTAB_SHNDX has bad sh_link: %u!=%u\n",
546 filename, sechdrs[symtab_shndx_idx].sh_link, 547 filename, sechdrs[symtab_shndx_idx].sh_link,
547 symtab_idx); 548 symtab_idx);
548 /* Fix endianness */ 549 /* Fix endianness */
549 for (p = info->symtab_shndx_start; p < info->symtab_shndx_stop; 550 for (p = info->symtab_shndx_start; p < info->symtab_shndx_stop;
550 p++) 551 p++)
551 *p = TO_NATIVE(*p); 552 *p = TO_NATIVE(*p);
552 } 553 }
553 554
554 return 1; 555 return 1;
555 } 556 }
556 557
557 static void parse_elf_finish(struct elf_info *info) 558 static void parse_elf_finish(struct elf_info *info)
558 { 559 {
559 release_file(info->hdr, info->size); 560 release_file(info->hdr, info->size);
560 } 561 }
561 562
562 static int ignore_undef_symbol(struct elf_info *info, const char *symname) 563 static int ignore_undef_symbol(struct elf_info *info, const char *symname)
563 { 564 {
564 /* ignore __this_module, it will be resolved shortly */ 565 /* ignore __this_module, it will be resolved shortly */
565 if (strcmp(symname, MODULE_SYMBOL_PREFIX "__this_module") == 0) 566 if (strcmp(symname, VMLINUX_SYMBOL_STR(__this_module)) == 0)
566 return 1; 567 return 1;
567 /* ignore global offset table */ 568 /* ignore global offset table */
568 if (strcmp(symname, "_GLOBAL_OFFSET_TABLE_") == 0) 569 if (strcmp(symname, "_GLOBAL_OFFSET_TABLE_") == 0)
569 return 1; 570 return 1;
570 if (info->hdr->e_machine == EM_PPC) 571 if (info->hdr->e_machine == EM_PPC)
571 /* Special register function linked on all modules during final link of .ko */ 572 /* Special register function linked on all modules during final link of .ko */
572 if (strncmp(symname, "_restgpr_", sizeof("_restgpr_") - 1) == 0 || 573 if (strncmp(symname, "_restgpr_", sizeof("_restgpr_") - 1) == 0 ||
573 strncmp(symname, "_savegpr_", sizeof("_savegpr_") - 1) == 0 || 574 strncmp(symname, "_savegpr_", sizeof("_savegpr_") - 1) == 0 ||
574 strncmp(symname, "_rest32gpr_", sizeof("_rest32gpr_") - 1) == 0 || 575 strncmp(symname, "_rest32gpr_", sizeof("_rest32gpr_") - 1) == 0 ||
575 strncmp(symname, "_save32gpr_", sizeof("_save32gpr_") - 1) == 0) 576 strncmp(symname, "_save32gpr_", sizeof("_save32gpr_") - 1) == 0)
576 return 1; 577 return 1;
577 if (info->hdr->e_machine == EM_PPC64) 578 if (info->hdr->e_machine == EM_PPC64)
578 /* Special register function linked on all modules during final link of .ko */ 579 /* Special register function linked on all modules during final link of .ko */
579 if (strncmp(symname, "_restgpr0_", sizeof("_restgpr0_") - 1) == 0 || 580 if (strncmp(symname, "_restgpr0_", sizeof("_restgpr0_") - 1) == 0 ||
580 strncmp(symname, "_savegpr0_", sizeof("_savegpr0_") - 1) == 0) 581 strncmp(symname, "_savegpr0_", sizeof("_savegpr0_") - 1) == 0)
581 return 1; 582 return 1;
582 /* Do not ignore this symbol */ 583 /* Do not ignore this symbol */
583 return 0; 584 return 0;
584 } 585 }
585 586
586 #define CRC_PFX MODULE_SYMBOL_PREFIX "__crc_" 587 #define CRC_PFX VMLINUX_SYMBOL_STR(__crc_)
587 #define KSYMTAB_PFX MODULE_SYMBOL_PREFIX "__ksymtab_" 588 #define KSYMTAB_PFX VMLINUX_SYMBOL_STR(__ksymtab_)
588 589
589 static void handle_modversions(struct module *mod, struct elf_info *info, 590 static void handle_modversions(struct module *mod, struct elf_info *info,
590 Elf_Sym *sym, const char *symname) 591 Elf_Sym *sym, const char *symname)
591 { 592 {
592 unsigned int crc; 593 unsigned int crc;
593 enum export export; 594 enum export export;
594 595
595 if ((!is_vmlinux(mod->name) || mod->is_dot_o) && 596 if ((!is_vmlinux(mod->name) || mod->is_dot_o) &&
596 strncmp(symname, "__ksymtab", 9) == 0) 597 strncmp(symname, "__ksymtab", 9) == 0)
597 export = export_from_secname(info, get_secindex(info, sym)); 598 export = export_from_secname(info, get_secindex(info, sym));
598 else 599 else
599 export = export_from_sec(info, get_secindex(info, sym)); 600 export = export_from_sec(info, get_secindex(info, sym));
600 601
601 switch (sym->st_shndx) { 602 switch (sym->st_shndx) {
602 case SHN_COMMON: 603 case SHN_COMMON:
603 warn("\"%s\" [%s] is COMMON symbol\n", symname, mod->name); 604 warn("\"%s\" [%s] is COMMON symbol\n", symname, mod->name);
604 break; 605 break;
605 case SHN_ABS: 606 case SHN_ABS:
606 /* CRC'd symbol */ 607 /* CRC'd symbol */
607 if (strncmp(symname, CRC_PFX, strlen(CRC_PFX)) == 0) { 608 if (strncmp(symname, CRC_PFX, strlen(CRC_PFX)) == 0) {
608 crc = (unsigned int) sym->st_value; 609 crc = (unsigned int) sym->st_value;
609 sym_update_crc(symname + strlen(CRC_PFX), mod, crc, 610 sym_update_crc(symname + strlen(CRC_PFX), mod, crc,
610 export); 611 export);
611 } 612 }
612 break; 613 break;
613 case SHN_UNDEF: 614 case SHN_UNDEF:
614 /* undefined symbol */ 615 /* undefined symbol */
615 if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL && 616 if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL &&
616 ELF_ST_BIND(sym->st_info) != STB_WEAK) 617 ELF_ST_BIND(sym->st_info) != STB_WEAK)
617 break; 618 break;
618 if (ignore_undef_symbol(info, symname)) 619 if (ignore_undef_symbol(info, symname))
619 break; 620 break;
620 /* cope with newer glibc (2.3.4 or higher) STT_ definition in elf.h */ 621 /* cope with newer glibc (2.3.4 or higher) STT_ definition in elf.h */
621 #if defined(STT_REGISTER) || defined(STT_SPARC_REGISTER) 622 #if defined(STT_REGISTER) || defined(STT_SPARC_REGISTER)
622 /* add compatibility with older glibc */ 623 /* add compatibility with older glibc */
623 #ifndef STT_SPARC_REGISTER 624 #ifndef STT_SPARC_REGISTER
624 #define STT_SPARC_REGISTER STT_REGISTER 625 #define STT_SPARC_REGISTER STT_REGISTER
625 #endif 626 #endif
626 if (info->hdr->e_machine == EM_SPARC || 627 if (info->hdr->e_machine == EM_SPARC ||
627 info->hdr->e_machine == EM_SPARCV9) { 628 info->hdr->e_machine == EM_SPARCV9) {
628 /* Ignore register directives. */ 629 /* Ignore register directives. */
629 if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER) 630 if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER)
630 break; 631 break;
631 if (symname[0] == '.') { 632 if (symname[0] == '.') {
632 char *munged = strdup(symname); 633 char *munged = strdup(symname);
633 munged[0] = '_'; 634 munged[0] = '_';
634 munged[1] = toupper(munged[1]); 635 munged[1] = toupper(munged[1]);
635 symname = munged; 636 symname = munged;
636 } 637 }
637 } 638 }
638 #endif 639 #endif
639 640
640 if (memcmp(symname, MODULE_SYMBOL_PREFIX, 641 #ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX
641 strlen(MODULE_SYMBOL_PREFIX)) == 0) { 642 if (symname[0] != '_')
642 mod->unres = 643 break;
643 alloc_symbol(symname + 644 else
644 strlen(MODULE_SYMBOL_PREFIX), 645 symname++;
645 ELF_ST_BIND(sym->st_info) == STB_WEAK, 646 #endif
646 mod->unres); 647 mod->unres = alloc_symbol(symname,
647 } 648 ELF_ST_BIND(sym->st_info) == STB_WEAK,
649 mod->unres);
648 break; 650 break;
649 default: 651 default:
650 /* All exported symbols */ 652 /* All exported symbols */
651 if (strncmp(symname, KSYMTAB_PFX, strlen(KSYMTAB_PFX)) == 0) { 653 if (strncmp(symname, KSYMTAB_PFX, strlen(KSYMTAB_PFX)) == 0) {
652 sym_add_exported(symname + strlen(KSYMTAB_PFX), mod, 654 sym_add_exported(symname + strlen(KSYMTAB_PFX), mod,
653 export); 655 export);
654 } 656 }
655 if (strcmp(symname, MODULE_SYMBOL_PREFIX "init_module") == 0) 657 if (strcmp(symname, VMLINUX_SYMBOL_STR(init_module)) == 0)
656 mod->has_init = 1; 658 mod->has_init = 1;
657 if (strcmp(symname, MODULE_SYMBOL_PREFIX "cleanup_module") == 0) 659 if (strcmp(symname, VMLINUX_SYMBOL_STR(cleanup_module)) == 0)
658 mod->has_cleanup = 1; 660 mod->has_cleanup = 1;
659 break; 661 break;
660 } 662 }
661 } 663 }
662 664
663 /** 665 /**
664 * Parse tag=value strings from .modinfo section 666 * Parse tag=value strings from .modinfo section
665 **/ 667 **/
666 static char *next_string(char *string, unsigned long *secsize) 668 static char *next_string(char *string, unsigned long *secsize)
667 { 669 {
668 /* Skip non-zero chars */ 670 /* Skip non-zero chars */
669 while (string[0]) { 671 while (string[0]) {
670 string++; 672 string++;
671 if ((*secsize)-- <= 1) 673 if ((*secsize)-- <= 1)
672 return NULL; 674 return NULL;
673 } 675 }
674 676
675 /* Skip any zero padding. */ 677 /* Skip any zero padding. */
676 while (!string[0]) { 678 while (!string[0]) {
677 string++; 679 string++;
678 if ((*secsize)-- <= 1) 680 if ((*secsize)-- <= 1)
679 return NULL; 681 return NULL;
680 } 682 }
681 return string; 683 return string;
682 } 684 }
683 685
684 static char *get_next_modinfo(void *modinfo, unsigned long modinfo_len, 686 static char *get_next_modinfo(void *modinfo, unsigned long modinfo_len,
685 const char *tag, char *info) 687 const char *tag, char *info)
686 { 688 {
687 char *p; 689 char *p;
688 unsigned int taglen = strlen(tag); 690 unsigned int taglen = strlen(tag);
689 unsigned long size = modinfo_len; 691 unsigned long size = modinfo_len;
690 692
691 if (info) { 693 if (info) {
692 size -= info - (char *)modinfo; 694 size -= info - (char *)modinfo;
693 modinfo = next_string(info, &size); 695 modinfo = next_string(info, &size);
694 } 696 }
695 697
696 for (p = modinfo; p; p = next_string(p, &size)) { 698 for (p = modinfo; p; p = next_string(p, &size)) {
697 if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=') 699 if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=')
698 return p + taglen + 1; 700 return p + taglen + 1;
699 } 701 }
700 return NULL; 702 return NULL;
701 } 703 }
702 704
703 static char *get_modinfo(void *modinfo, unsigned long modinfo_len, 705 static char *get_modinfo(void *modinfo, unsigned long modinfo_len,
704 const char *tag) 706 const char *tag)
705 707
706 { 708 {
707 return get_next_modinfo(modinfo, modinfo_len, tag, NULL); 709 return get_next_modinfo(modinfo, modinfo_len, tag, NULL);
708 } 710 }
709 711
710 /** 712 /**
711 * Test if string s ends in string sub 713 * Test if string s ends in string sub
712 * return 0 if match 714 * return 0 if match
713 **/ 715 **/
714 static int strrcmp(const char *s, const char *sub) 716 static int strrcmp(const char *s, const char *sub)
715 { 717 {
716 int slen, sublen; 718 int slen, sublen;
717 719
718 if (!s || !sub) 720 if (!s || !sub)
719 return 1; 721 return 1;
720 722
721 slen = strlen(s); 723 slen = strlen(s);
722 sublen = strlen(sub); 724 sublen = strlen(sub);
723 725
724 if ((slen == 0) || (sublen == 0)) 726 if ((slen == 0) || (sublen == 0))
725 return 1; 727 return 1;
726 728
727 if (sublen > slen) 729 if (sublen > slen)
728 return 1; 730 return 1;
729 731
730 return memcmp(s + slen - sublen, sub, sublen); 732 return memcmp(s + slen - sublen, sub, sublen);
731 } 733 }
732 734
733 static const char *sym_name(struct elf_info *elf, Elf_Sym *sym) 735 static const char *sym_name(struct elf_info *elf, Elf_Sym *sym)
734 { 736 {
735 if (sym) 737 if (sym)
736 return elf->strtab + sym->st_name; 738 return elf->strtab + sym->st_name;
737 else 739 else
738 return "(unknown)"; 740 return "(unknown)";
739 } 741 }
740 742
741 static const char *sec_name(struct elf_info *elf, int secindex) 743 static const char *sec_name(struct elf_info *elf, int secindex)
742 { 744 {
743 Elf_Shdr *sechdrs = elf->sechdrs; 745 Elf_Shdr *sechdrs = elf->sechdrs;
744 return (void *)elf->hdr + 746 return (void *)elf->hdr +
745 elf->sechdrs[elf->secindex_strings].sh_offset + 747 elf->sechdrs[elf->secindex_strings].sh_offset +
746 sechdrs[secindex].sh_name; 748 sechdrs[secindex].sh_name;
747 } 749 }
748 750
749 static const char *sech_name(struct elf_info *elf, Elf_Shdr *sechdr) 751 static const char *sech_name(struct elf_info *elf, Elf_Shdr *sechdr)
750 { 752 {
751 return (void *)elf->hdr + 753 return (void *)elf->hdr +
752 elf->sechdrs[elf->secindex_strings].sh_offset + 754 elf->sechdrs[elf->secindex_strings].sh_offset +
753 sechdr->sh_name; 755 sechdr->sh_name;
754 } 756 }
755 757
756 /* if sym is empty or point to a string 758 /* if sym is empty or point to a string
757 * like ".[0-9]+" then return 1. 759 * like ".[0-9]+" then return 1.
758 * This is the optional prefix added by ld to some sections 760 * This is the optional prefix added by ld to some sections
759 */ 761 */
760 static int number_prefix(const char *sym) 762 static int number_prefix(const char *sym)
761 { 763 {
762 if (*sym++ == '\0') 764 if (*sym++ == '\0')
763 return 1; 765 return 1;
764 if (*sym != '.') 766 if (*sym != '.')
765 return 0; 767 return 0;
766 do { 768 do {
767 char c = *sym++; 769 char c = *sym++;
768 if (c < '0' || c > '9') 770 if (c < '0' || c > '9')
769 return 0; 771 return 0;
770 } while (*sym); 772 } while (*sym);
771 return 1; 773 return 1;
772 } 774 }
773 775
774 /* The pattern is an array of simple patterns. 776 /* The pattern is an array of simple patterns.
775 * "foo" will match an exact string equal to "foo" 777 * "foo" will match an exact string equal to "foo"
776 * "*foo" will match a string that ends with "foo" 778 * "*foo" will match a string that ends with "foo"
777 * "foo*" will match a string that begins with "foo" 779 * "foo*" will match a string that begins with "foo"
778 * "foo$" will match a string equal to "foo" or "foo.1" 780 * "foo$" will match a string equal to "foo" or "foo.1"
779 * where the '1' can be any number including several digits. 781 * where the '1' can be any number including several digits.
780 * The $ syntax is for sections where ld append a dot number 782 * The $ syntax is for sections where ld append a dot number
781 * to make section name unique. 783 * to make section name unique.
782 */ 784 */
783 static int match(const char *sym, const char * const pat[]) 785 static int match(const char *sym, const char * const pat[])
784 { 786 {
785 const char *p; 787 const char *p;
786 while (*pat) { 788 while (*pat) {
787 p = *pat++; 789 p = *pat++;
788 const char *endp = p + strlen(p) - 1; 790 const char *endp = p + strlen(p) - 1;
789 791
790 /* "*foo" */ 792 /* "*foo" */
791 if (*p == '*') { 793 if (*p == '*') {
792 if (strrcmp(sym, p + 1) == 0) 794 if (strrcmp(sym, p + 1) == 0)
793 return 1; 795 return 1;
794 } 796 }
795 /* "foo*" */ 797 /* "foo*" */
796 else if (*endp == '*') { 798 else if (*endp == '*') {
797 if (strncmp(sym, p, strlen(p) - 1) == 0) 799 if (strncmp(sym, p, strlen(p) - 1) == 0)
798 return 1; 800 return 1;
799 } 801 }
800 /* "foo$" */ 802 /* "foo$" */
801 else if (*endp == '$') { 803 else if (*endp == '$') {
802 if (strncmp(sym, p, strlen(p) - 1) == 0) { 804 if (strncmp(sym, p, strlen(p) - 1) == 0) {
803 if (number_prefix(sym + strlen(p) - 1)) 805 if (number_prefix(sym + strlen(p) - 1))
804 return 1; 806 return 1;
805 } 807 }
806 } 808 }
807 /* no wildcards */ 809 /* no wildcards */
808 else { 810 else {
809 if (strcmp(p, sym) == 0) 811 if (strcmp(p, sym) == 0)
810 return 1; 812 return 1;
811 } 813 }
812 } 814 }
813 /* no match */ 815 /* no match */
814 return 0; 816 return 0;
815 } 817 }
816 818
817 /* sections that we do not want to do full section mismatch check on */ 819 /* sections that we do not want to do full section mismatch check on */
818 static const char *section_white_list[] = 820 static const char *section_white_list[] =
819 { 821 {
820 ".comment*", 822 ".comment*",
821 ".debug*", 823 ".debug*",
822 ".zdebug*", /* Compressed debug sections. */ 824 ".zdebug*", /* Compressed debug sections. */
823 ".GCC-command-line", /* mn10300 */ 825 ".GCC-command-line", /* mn10300 */
824 ".GCC.command.line", /* record-gcc-switches, non mn10300 */ 826 ".GCC.command.line", /* record-gcc-switches, non mn10300 */
825 ".mdebug*", /* alpha, score, mips etc. */ 827 ".mdebug*", /* alpha, score, mips etc. */
826 ".pdr", /* alpha, score, mips etc. */ 828 ".pdr", /* alpha, score, mips etc. */
827 ".stab*", 829 ".stab*",
828 ".note*", 830 ".note*",
829 ".got*", 831 ".got*",
830 ".toc*", 832 ".toc*",
831 ".xt.prop", /* xtensa */ 833 ".xt.prop", /* xtensa */
832 ".xt.lit", /* xtensa */ 834 ".xt.lit", /* xtensa */
833 ".arcextmap*", /* arc */ 835 ".arcextmap*", /* arc */
834 ".gnu.linkonce.arcext*", /* arc : modules */ 836 ".gnu.linkonce.arcext*", /* arc : modules */
835 NULL 837 NULL
836 }; 838 };
837 839
838 /* 840 /*
839 * This is used to find sections missing the SHF_ALLOC flag. 841 * This is used to find sections missing the SHF_ALLOC flag.
840 * The cause of this is often a section specified in assembler 842 * The cause of this is often a section specified in assembler
841 * without "ax" / "aw". 843 * without "ax" / "aw".
842 */ 844 */
843 static void check_section(const char *modname, struct elf_info *elf, 845 static void check_section(const char *modname, struct elf_info *elf,
844 Elf_Shdr *sechdr) 846 Elf_Shdr *sechdr)
845 { 847 {
846 const char *sec = sech_name(elf, sechdr); 848 const char *sec = sech_name(elf, sechdr);
847 849
848 if (sechdr->sh_type == SHT_PROGBITS && 850 if (sechdr->sh_type == SHT_PROGBITS &&
849 !(sechdr->sh_flags & SHF_ALLOC) && 851 !(sechdr->sh_flags & SHF_ALLOC) &&
850 !match(sec, section_white_list)) { 852 !match(sec, section_white_list)) {
851 warn("%s (%s): unexpected non-allocatable section.\n" 853 warn("%s (%s): unexpected non-allocatable section.\n"
852 "Did you forget to use \"ax\"/\"aw\" in a .S file?\n" 854 "Did you forget to use \"ax\"/\"aw\" in a .S file?\n"
853 "Note that for example <linux/init.h> contains\n" 855 "Note that for example <linux/init.h> contains\n"
854 "section definitions for use in .S files.\n\n", 856 "section definitions for use in .S files.\n\n",
855 modname, sec); 857 modname, sec);
856 } 858 }
857 } 859 }
858 860
859 861
860 862
861 #define ALL_INIT_DATA_SECTIONS \ 863 #define ALL_INIT_DATA_SECTIONS \
862 ".init.setup$", ".init.rodata$", \ 864 ".init.setup$", ".init.rodata$", \
863 ".cpuinit.rodata$", ".meminit.rodata$", \ 865 ".cpuinit.rodata$", ".meminit.rodata$", \
864 ".init.data$", ".cpuinit.data$", ".meminit.data$" 866 ".init.data$", ".cpuinit.data$", ".meminit.data$"
865 #define ALL_EXIT_DATA_SECTIONS \ 867 #define ALL_EXIT_DATA_SECTIONS \
866 ".exit.data$", ".cpuexit.data$", ".memexit.data$" 868 ".exit.data$", ".cpuexit.data$", ".memexit.data$"
867 869
868 #define ALL_INIT_TEXT_SECTIONS \ 870 #define ALL_INIT_TEXT_SECTIONS \
869 ".init.text$", ".cpuinit.text$", ".meminit.text$" 871 ".init.text$", ".cpuinit.text$", ".meminit.text$"
870 #define ALL_EXIT_TEXT_SECTIONS \ 872 #define ALL_EXIT_TEXT_SECTIONS \
871 ".exit.text$", ".cpuexit.text$", ".memexit.text$" 873 ".exit.text$", ".cpuexit.text$", ".memexit.text$"
872 874
873 #define ALL_PCI_INIT_SECTIONS \ 875 #define ALL_PCI_INIT_SECTIONS \
874 ".pci_fixup_early$", ".pci_fixup_header$", ".pci_fixup_final$", \ 876 ".pci_fixup_early$", ".pci_fixup_header$", ".pci_fixup_final$", \
875 ".pci_fixup_enable$", ".pci_fixup_resume$", \ 877 ".pci_fixup_enable$", ".pci_fixup_resume$", \
876 ".pci_fixup_resume_early$", ".pci_fixup_suspend$" 878 ".pci_fixup_resume_early$", ".pci_fixup_suspend$"
877 879
878 #define ALL_XXXINIT_SECTIONS CPU_INIT_SECTIONS, MEM_INIT_SECTIONS 880 #define ALL_XXXINIT_SECTIONS CPU_INIT_SECTIONS, MEM_INIT_SECTIONS
879 #define ALL_XXXEXIT_SECTIONS CPU_EXIT_SECTIONS, MEM_EXIT_SECTIONS 881 #define ALL_XXXEXIT_SECTIONS CPU_EXIT_SECTIONS, MEM_EXIT_SECTIONS
880 882
881 #define ALL_INIT_SECTIONS INIT_SECTIONS, ALL_XXXINIT_SECTIONS 883 #define ALL_INIT_SECTIONS INIT_SECTIONS, ALL_XXXINIT_SECTIONS
882 #define ALL_EXIT_SECTIONS EXIT_SECTIONS, ALL_XXXEXIT_SECTIONS 884 #define ALL_EXIT_SECTIONS EXIT_SECTIONS, ALL_XXXEXIT_SECTIONS
883 885
884 #define DATA_SECTIONS ".data$", ".data.rel$" 886 #define DATA_SECTIONS ".data$", ".data.rel$"
885 #define TEXT_SECTIONS ".text$" 887 #define TEXT_SECTIONS ".text$"
886 888
887 #define INIT_SECTIONS ".init.*" 889 #define INIT_SECTIONS ".init.*"
888 #define CPU_INIT_SECTIONS ".cpuinit.*" 890 #define CPU_INIT_SECTIONS ".cpuinit.*"
889 #define MEM_INIT_SECTIONS ".meminit.*" 891 #define MEM_INIT_SECTIONS ".meminit.*"
890 892
891 #define EXIT_SECTIONS ".exit.*" 893 #define EXIT_SECTIONS ".exit.*"
892 #define CPU_EXIT_SECTIONS ".cpuexit.*" 894 #define CPU_EXIT_SECTIONS ".cpuexit.*"
893 #define MEM_EXIT_SECTIONS ".memexit.*" 895 #define MEM_EXIT_SECTIONS ".memexit.*"
894 896
895 /* init data sections */ 897 /* init data sections */
896 static const char *init_data_sections[] = { ALL_INIT_DATA_SECTIONS, NULL }; 898 static const char *init_data_sections[] = { ALL_INIT_DATA_SECTIONS, NULL };
897 899
898 /* all init sections */ 900 /* all init sections */
899 static const char *init_sections[] = { ALL_INIT_SECTIONS, NULL }; 901 static const char *init_sections[] = { ALL_INIT_SECTIONS, NULL };
900 902
901 /* All init and exit sections (code + data) */ 903 /* All init and exit sections (code + data) */
902 static const char *init_exit_sections[] = 904 static const char *init_exit_sections[] =
903 {ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS, NULL }; 905 {ALL_INIT_SECTIONS, ALL_EXIT_SECTIONS, NULL };
904 906
905 /* data section */ 907 /* data section */
906 static const char *data_sections[] = { DATA_SECTIONS, NULL }; 908 static const char *data_sections[] = { DATA_SECTIONS, NULL };
907 909
908 910
909 /* symbols in .data that may refer to init/exit sections */ 911 /* symbols in .data that may refer to init/exit sections */
910 #define DEFAULT_SYMBOL_WHITE_LIST \ 912 #define DEFAULT_SYMBOL_WHITE_LIST \
911 "*driver", \ 913 "*driver", \
912 "*_template", /* scsi uses *_template a lot */ \ 914 "*_template", /* scsi uses *_template a lot */ \
913 "*_timer", /* arm uses ops structures named _timer a lot */ \ 915 "*_timer", /* arm uses ops structures named _timer a lot */ \
914 "*_sht", /* scsi also used *_sht to some extent */ \ 916 "*_sht", /* scsi also used *_sht to some extent */ \
915 "*_ops", \ 917 "*_ops", \
916 "*_probe", \ 918 "*_probe", \
917 "*_probe_one", \ 919 "*_probe_one", \
918 "*_console" 920 "*_console"
919 921
920 static const char *head_sections[] = { ".head.text*", NULL }; 922 static const char *head_sections[] = { ".head.text*", NULL };
921 static const char *linker_symbols[] = 923 static const char *linker_symbols[] =
922 { "__init_begin", "_sinittext", "_einittext", NULL }; 924 { "__init_begin", "_sinittext", "_einittext", NULL };
923 925
924 enum mismatch { 926 enum mismatch {
925 TEXT_TO_ANY_INIT, 927 TEXT_TO_ANY_INIT,
926 DATA_TO_ANY_INIT, 928 DATA_TO_ANY_INIT,
927 TEXT_TO_ANY_EXIT, 929 TEXT_TO_ANY_EXIT,
928 DATA_TO_ANY_EXIT, 930 DATA_TO_ANY_EXIT,
929 XXXINIT_TO_SOME_INIT, 931 XXXINIT_TO_SOME_INIT,
930 XXXEXIT_TO_SOME_EXIT, 932 XXXEXIT_TO_SOME_EXIT,
931 ANY_INIT_TO_ANY_EXIT, 933 ANY_INIT_TO_ANY_EXIT,
932 ANY_EXIT_TO_ANY_INIT, 934 ANY_EXIT_TO_ANY_INIT,
933 EXPORT_TO_INIT_EXIT, 935 EXPORT_TO_INIT_EXIT,
934 }; 936 };
935 937
936 struct sectioncheck { 938 struct sectioncheck {
937 const char *fromsec[20]; 939 const char *fromsec[20];
938 const char *tosec[20]; 940 const char *tosec[20];
939 enum mismatch mismatch; 941 enum mismatch mismatch;
940 const char *symbol_white_list[20]; 942 const char *symbol_white_list[20];
941 }; 943 };
942 944
943 const struct sectioncheck sectioncheck[] = { 945 const struct sectioncheck sectioncheck[] = {
944 /* Do not reference init/exit code/data from 946 /* Do not reference init/exit code/data from
945 * normal code and data 947 * normal code and data
946 */ 948 */
947 { 949 {
948 .fromsec = { TEXT_SECTIONS, NULL }, 950 .fromsec = { TEXT_SECTIONS, NULL },
949 .tosec = { ALL_INIT_SECTIONS, NULL }, 951 .tosec = { ALL_INIT_SECTIONS, NULL },
950 .mismatch = TEXT_TO_ANY_INIT, 952 .mismatch = TEXT_TO_ANY_INIT,
951 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 953 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
952 }, 954 },
953 { 955 {
954 .fromsec = { DATA_SECTIONS, NULL }, 956 .fromsec = { DATA_SECTIONS, NULL },
955 .tosec = { ALL_XXXINIT_SECTIONS, NULL }, 957 .tosec = { ALL_XXXINIT_SECTIONS, NULL },
956 .mismatch = DATA_TO_ANY_INIT, 958 .mismatch = DATA_TO_ANY_INIT,
957 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 959 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
958 }, 960 },
959 { 961 {
960 .fromsec = { DATA_SECTIONS, NULL }, 962 .fromsec = { DATA_SECTIONS, NULL },
961 .tosec = { INIT_SECTIONS, NULL }, 963 .tosec = { INIT_SECTIONS, NULL },
962 .mismatch = DATA_TO_ANY_INIT, 964 .mismatch = DATA_TO_ANY_INIT,
963 .symbol_white_list = { 965 .symbol_white_list = {
964 "*_template", "*_timer", "*_sht", "*_ops", 966 "*_template", "*_timer", "*_sht", "*_ops",
965 "*_probe", "*_probe_one", "*_console", NULL 967 "*_probe", "*_probe_one", "*_console", NULL
966 }, 968 },
967 }, 969 },
968 { 970 {
969 .fromsec = { TEXT_SECTIONS, NULL }, 971 .fromsec = { TEXT_SECTIONS, NULL },
970 .tosec = { ALL_EXIT_SECTIONS, NULL }, 972 .tosec = { ALL_EXIT_SECTIONS, NULL },
971 .mismatch = TEXT_TO_ANY_EXIT, 973 .mismatch = TEXT_TO_ANY_EXIT,
972 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 974 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
973 }, 975 },
974 { 976 {
975 .fromsec = { DATA_SECTIONS, NULL }, 977 .fromsec = { DATA_SECTIONS, NULL },
976 .tosec = { ALL_EXIT_SECTIONS, NULL }, 978 .tosec = { ALL_EXIT_SECTIONS, NULL },
977 .mismatch = DATA_TO_ANY_EXIT, 979 .mismatch = DATA_TO_ANY_EXIT,
978 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 980 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
979 }, 981 },
980 /* Do not reference init code/data from cpuinit/meminit code/data */ 982 /* Do not reference init code/data from cpuinit/meminit code/data */
981 { 983 {
982 .fromsec = { ALL_XXXINIT_SECTIONS, NULL }, 984 .fromsec = { ALL_XXXINIT_SECTIONS, NULL },
983 .tosec = { INIT_SECTIONS, NULL }, 985 .tosec = { INIT_SECTIONS, NULL },
984 .mismatch = XXXINIT_TO_SOME_INIT, 986 .mismatch = XXXINIT_TO_SOME_INIT,
985 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 987 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
986 }, 988 },
987 /* Do not reference cpuinit code/data from meminit code/data */ 989 /* Do not reference cpuinit code/data from meminit code/data */
988 { 990 {
989 .fromsec = { MEM_INIT_SECTIONS, NULL }, 991 .fromsec = { MEM_INIT_SECTIONS, NULL },
990 .tosec = { CPU_INIT_SECTIONS, NULL }, 992 .tosec = { CPU_INIT_SECTIONS, NULL },
991 .mismatch = XXXINIT_TO_SOME_INIT, 993 .mismatch = XXXINIT_TO_SOME_INIT,
992 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 994 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
993 }, 995 },
994 /* Do not reference meminit code/data from cpuinit code/data */ 996 /* Do not reference meminit code/data from cpuinit code/data */
995 { 997 {
996 .fromsec = { CPU_INIT_SECTIONS, NULL }, 998 .fromsec = { CPU_INIT_SECTIONS, NULL },
997 .tosec = { MEM_INIT_SECTIONS, NULL }, 999 .tosec = { MEM_INIT_SECTIONS, NULL },
998 .mismatch = XXXINIT_TO_SOME_INIT, 1000 .mismatch = XXXINIT_TO_SOME_INIT,
999 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 1001 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1000 }, 1002 },
1001 /* Do not reference exit code/data from cpuexit/memexit code/data */ 1003 /* Do not reference exit code/data from cpuexit/memexit code/data */
1002 { 1004 {
1003 .fromsec = { ALL_XXXEXIT_SECTIONS, NULL }, 1005 .fromsec = { ALL_XXXEXIT_SECTIONS, NULL },
1004 .tosec = { EXIT_SECTIONS, NULL }, 1006 .tosec = { EXIT_SECTIONS, NULL },
1005 .mismatch = XXXEXIT_TO_SOME_EXIT, 1007 .mismatch = XXXEXIT_TO_SOME_EXIT,
1006 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 1008 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1007 }, 1009 },
1008 /* Do not reference cpuexit code/data from memexit code/data */ 1010 /* Do not reference cpuexit code/data from memexit code/data */
1009 { 1011 {
1010 .fromsec = { MEM_EXIT_SECTIONS, NULL }, 1012 .fromsec = { MEM_EXIT_SECTIONS, NULL },
1011 .tosec = { CPU_EXIT_SECTIONS, NULL }, 1013 .tosec = { CPU_EXIT_SECTIONS, NULL },
1012 .mismatch = XXXEXIT_TO_SOME_EXIT, 1014 .mismatch = XXXEXIT_TO_SOME_EXIT,
1013 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 1015 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1014 }, 1016 },
1015 /* Do not reference memexit code/data from cpuexit code/data */ 1017 /* Do not reference memexit code/data from cpuexit code/data */
1016 { 1018 {
1017 .fromsec = { CPU_EXIT_SECTIONS, NULL }, 1019 .fromsec = { CPU_EXIT_SECTIONS, NULL },
1018 .tosec = { MEM_EXIT_SECTIONS, NULL }, 1020 .tosec = { MEM_EXIT_SECTIONS, NULL },
1019 .mismatch = XXXEXIT_TO_SOME_EXIT, 1021 .mismatch = XXXEXIT_TO_SOME_EXIT,
1020 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 1022 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1021 }, 1023 },
1022 /* Do not use exit code/data from init code */ 1024 /* Do not use exit code/data from init code */
1023 { 1025 {
1024 .fromsec = { ALL_INIT_SECTIONS, NULL }, 1026 .fromsec = { ALL_INIT_SECTIONS, NULL },
1025 .tosec = { ALL_EXIT_SECTIONS, NULL }, 1027 .tosec = { ALL_EXIT_SECTIONS, NULL },
1026 .mismatch = ANY_INIT_TO_ANY_EXIT, 1028 .mismatch = ANY_INIT_TO_ANY_EXIT,
1027 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 1029 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1028 }, 1030 },
1029 /* Do not use init code/data from exit code */ 1031 /* Do not use init code/data from exit code */
1030 { 1032 {
1031 .fromsec = { ALL_EXIT_SECTIONS, NULL }, 1033 .fromsec = { ALL_EXIT_SECTIONS, NULL },
1032 .tosec = { ALL_INIT_SECTIONS, NULL }, 1034 .tosec = { ALL_INIT_SECTIONS, NULL },
1033 .mismatch = ANY_EXIT_TO_ANY_INIT, 1035 .mismatch = ANY_EXIT_TO_ANY_INIT,
1034 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 1036 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1035 }, 1037 },
1036 { 1038 {
1037 .fromsec = { ALL_PCI_INIT_SECTIONS, NULL }, 1039 .fromsec = { ALL_PCI_INIT_SECTIONS, NULL },
1038 .tosec = { INIT_SECTIONS, NULL }, 1040 .tosec = { INIT_SECTIONS, NULL },
1039 .mismatch = ANY_INIT_TO_ANY_EXIT, 1041 .mismatch = ANY_INIT_TO_ANY_EXIT,
1040 .symbol_white_list = { NULL }, 1042 .symbol_white_list = { NULL },
1041 }, 1043 },
1042 /* Do not export init/exit functions or data */ 1044 /* Do not export init/exit functions or data */
1043 { 1045 {
1044 .fromsec = { "__ksymtab*", NULL }, 1046 .fromsec = { "__ksymtab*", NULL },
1045 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL }, 1047 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
1046 .mismatch = EXPORT_TO_INIT_EXIT, 1048 .mismatch = EXPORT_TO_INIT_EXIT,
1047 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL }, 1049 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
1048 } 1050 }
1049 }; 1051 };
1050 1052
1051 static const struct sectioncheck *section_mismatch( 1053 static const struct sectioncheck *section_mismatch(
1052 const char *fromsec, const char *tosec) 1054 const char *fromsec, const char *tosec)
1053 { 1055 {
1054 int i; 1056 int i;
1055 int elems = sizeof(sectioncheck) / sizeof(struct sectioncheck); 1057 int elems = sizeof(sectioncheck) / sizeof(struct sectioncheck);
1056 const struct sectioncheck *check = &sectioncheck[0]; 1058 const struct sectioncheck *check = &sectioncheck[0];
1057 1059
1058 for (i = 0; i < elems; i++) { 1060 for (i = 0; i < elems; i++) {
1059 if (match(fromsec, check->fromsec) && 1061 if (match(fromsec, check->fromsec) &&
1060 match(tosec, check->tosec)) 1062 match(tosec, check->tosec))
1061 return check; 1063 return check;
1062 check++; 1064 check++;
1063 } 1065 }
1064 return NULL; 1066 return NULL;
1065 } 1067 }
1066 1068
1067 /** 1069 /**
1068 * Whitelist to allow certain references to pass with no warning. 1070 * Whitelist to allow certain references to pass with no warning.
1069 * 1071 *
1070 * Pattern 1: 1072 * Pattern 1:
1071 * If a module parameter is declared __initdata and permissions=0 1073 * If a module parameter is declared __initdata and permissions=0
1072 * then this is legal despite the warning generated. 1074 * then this is legal despite the warning generated.
1073 * We cannot see value of permissions here, so just ignore 1075 * We cannot see value of permissions here, so just ignore
1074 * this pattern. 1076 * this pattern.
1075 * The pattern is identified by: 1077 * The pattern is identified by:
1076 * tosec = .init.data 1078 * tosec = .init.data
1077 * fromsec = .data* 1079 * fromsec = .data*
1078 * atsym =__param* 1080 * atsym =__param*
1079 * 1081 *
1080 * Pattern 1a: 1082 * Pattern 1a:
1081 * module_param_call() ops can refer to __init set function if permissions=0 1083 * module_param_call() ops can refer to __init set function if permissions=0
1082 * The pattern is identified by: 1084 * The pattern is identified by:
1083 * tosec = .init.text 1085 * tosec = .init.text
1084 * fromsec = .data* 1086 * fromsec = .data*
1085 * atsym = __param_ops_* 1087 * atsym = __param_ops_*
1086 * 1088 *
1087 * Pattern 2: 1089 * Pattern 2:
1088 * Many drivers utilise a *driver container with references to 1090 * Many drivers utilise a *driver container with references to
1089 * add, remove, probe functions etc. 1091 * add, remove, probe functions etc.
1090 * These functions may often be marked __cpuinit and we do not want to 1092 * These functions may often be marked __cpuinit and we do not want to
1091 * warn here. 1093 * warn here.
1092 * the pattern is identified by: 1094 * the pattern is identified by:
1093 * tosec = init or exit section 1095 * tosec = init or exit section
1094 * fromsec = data section 1096 * fromsec = data section
1095 * atsym = *driver, *_template, *_sht, *_ops, *_probe, 1097 * atsym = *driver, *_template, *_sht, *_ops, *_probe,
1096 * *probe_one, *_console, *_timer 1098 * *probe_one, *_console, *_timer
1097 * 1099 *
1098 * Pattern 3: 1100 * Pattern 3:
1099 * Whitelist all references from .head.text to any init section 1101 * Whitelist all references from .head.text to any init section
1100 * 1102 *
1101 * Pattern 4: 1103 * Pattern 4:
1102 * Some symbols belong to init section but still it is ok to reference 1104 * Some symbols belong to init section but still it is ok to reference
1103 * these from non-init sections as these symbols don't have any memory 1105 * these from non-init sections as these symbols don't have any memory
1104 * allocated for them and symbol address and value are same. So even 1106 * allocated for them and symbol address and value are same. So even
1105 * if init section is freed, its ok to reference those symbols. 1107 * if init section is freed, its ok to reference those symbols.
1106 * For ex. symbols marking the init section boundaries. 1108 * For ex. symbols marking the init section boundaries.
1107 * This pattern is identified by 1109 * This pattern is identified by
1108 * refsymname = __init_begin, _sinittext, _einittext 1110 * refsymname = __init_begin, _sinittext, _einittext
1109 * 1111 *
1110 **/ 1112 **/
1111 static int secref_whitelist(const struct sectioncheck *mismatch, 1113 static int secref_whitelist(const struct sectioncheck *mismatch,
1112 const char *fromsec, const char *fromsym, 1114 const char *fromsec, const char *fromsym,
1113 const char *tosec, const char *tosym) 1115 const char *tosec, const char *tosym)
1114 { 1116 {
1115 /* Check for pattern 1 */ 1117 /* Check for pattern 1 */
1116 if (match(tosec, init_data_sections) && 1118 if (match(tosec, init_data_sections) &&
1117 match(fromsec, data_sections) && 1119 match(fromsec, data_sections) &&
1118 (strncmp(fromsym, "__param", strlen("__param")) == 0)) 1120 (strncmp(fromsym, "__param", strlen("__param")) == 0))
1119 return 0; 1121 return 0;
1120 1122
1121 /* Check for pattern 1a */ 1123 /* Check for pattern 1a */
1122 if (strcmp(tosec, ".init.text") == 0 && 1124 if (strcmp(tosec, ".init.text") == 0 &&
1123 match(fromsec, data_sections) && 1125 match(fromsec, data_sections) &&
1124 (strncmp(fromsym, "__param_ops_", strlen("__param_ops_")) == 0)) 1126 (strncmp(fromsym, "__param_ops_", strlen("__param_ops_")) == 0))
1125 return 0; 1127 return 0;
1126 1128
1127 /* Check for pattern 2 */ 1129 /* Check for pattern 2 */
1128 if (match(tosec, init_exit_sections) && 1130 if (match(tosec, init_exit_sections) &&
1129 match(fromsec, data_sections) && 1131 match(fromsec, data_sections) &&
1130 match(fromsym, mismatch->symbol_white_list)) 1132 match(fromsym, mismatch->symbol_white_list))
1131 return 0; 1133 return 0;
1132 1134
1133 /* Check for pattern 3 */ 1135 /* Check for pattern 3 */
1134 if (match(fromsec, head_sections) && 1136 if (match(fromsec, head_sections) &&
1135 match(tosec, init_sections)) 1137 match(tosec, init_sections))
1136 return 0; 1138 return 0;
1137 1139
1138 /* Check for pattern 4 */ 1140 /* Check for pattern 4 */
1139 if (match(tosym, linker_symbols)) 1141 if (match(tosym, linker_symbols))
1140 return 0; 1142 return 0;
1141 1143
1142 return 1; 1144 return 1;
1143 } 1145 }
1144 1146
1145 /** 1147 /**
1146 * Find symbol based on relocation record info. 1148 * Find symbol based on relocation record info.
1147 * In some cases the symbol supplied is a valid symbol so 1149 * In some cases the symbol supplied is a valid symbol so
1148 * return refsym. If st_name != 0 we assume this is a valid symbol. 1150 * return refsym. If st_name != 0 we assume this is a valid symbol.
1149 * In other cases the symbol needs to be looked up in the symbol table 1151 * In other cases the symbol needs to be looked up in the symbol table
1150 * based on section and address. 1152 * based on section and address.
1151 * **/ 1153 * **/
1152 static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr, 1154 static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
1153 Elf_Sym *relsym) 1155 Elf_Sym *relsym)
1154 { 1156 {
1155 Elf_Sym *sym; 1157 Elf_Sym *sym;
1156 Elf_Sym *near = NULL; 1158 Elf_Sym *near = NULL;
1157 Elf64_Sword distance = 20; 1159 Elf64_Sword distance = 20;
1158 Elf64_Sword d; 1160 Elf64_Sword d;
1159 unsigned int relsym_secindex; 1161 unsigned int relsym_secindex;
1160 1162
1161 if (relsym->st_name != 0) 1163 if (relsym->st_name != 0)
1162 return relsym; 1164 return relsym;
1163 1165
1164 relsym_secindex = get_secindex(elf, relsym); 1166 relsym_secindex = get_secindex(elf, relsym);
1165 for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) { 1167 for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) {
1166 if (get_secindex(elf, sym) != relsym_secindex) 1168 if (get_secindex(elf, sym) != relsym_secindex)
1167 continue; 1169 continue;
1168 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION) 1170 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
1169 continue; 1171 continue;
1170 if (sym->st_value == addr) 1172 if (sym->st_value == addr)
1171 return sym; 1173 return sym;
1172 /* Find a symbol nearby - addr are maybe negative */ 1174 /* Find a symbol nearby - addr are maybe negative */
1173 d = sym->st_value - addr; 1175 d = sym->st_value - addr;
1174 if (d < 0) 1176 if (d < 0)
1175 d = addr - sym->st_value; 1177 d = addr - sym->st_value;
1176 if (d < distance) { 1178 if (d < distance) {
1177 distance = d; 1179 distance = d;
1178 near = sym; 1180 near = sym;
1179 } 1181 }
1180 } 1182 }
1181 /* We need a close match */ 1183 /* We need a close match */
1182 if (distance < 20) 1184 if (distance < 20)
1183 return near; 1185 return near;
1184 else 1186 else
1185 return NULL; 1187 return NULL;
1186 } 1188 }
1187 1189
1188 static inline int is_arm_mapping_symbol(const char *str) 1190 static inline int is_arm_mapping_symbol(const char *str)
1189 { 1191 {
1190 return str[0] == '$' && strchr("atd", str[1]) 1192 return str[0] == '$' && strchr("atd", str[1])
1191 && (str[2] == '\0' || str[2] == '.'); 1193 && (str[2] == '\0' || str[2] == '.');
1192 } 1194 }
1193 1195
1194 /* 1196 /*
1195 * If there's no name there, ignore it; likewise, ignore it if it's 1197 * If there's no name there, ignore it; likewise, ignore it if it's
1196 * one of the magic symbols emitted used by current ARM tools. 1198 * one of the magic symbols emitted used by current ARM tools.
1197 * 1199 *
1198 * Otherwise if find_symbols_between() returns those symbols, they'll 1200 * Otherwise if find_symbols_between() returns those symbols, they'll
1199 * fail the whitelist tests and cause lots of false alarms ... fixable 1201 * fail the whitelist tests and cause lots of false alarms ... fixable
1200 * only by merging __exit and __init sections into __text, bloating 1202 * only by merging __exit and __init sections into __text, bloating
1201 * the kernel (which is especially evil on embedded platforms). 1203 * the kernel (which is especially evil on embedded platforms).
1202 */ 1204 */
1203 static inline int is_valid_name(struct elf_info *elf, Elf_Sym *sym) 1205 static inline int is_valid_name(struct elf_info *elf, Elf_Sym *sym)
1204 { 1206 {
1205 const char *name = elf->strtab + sym->st_name; 1207 const char *name = elf->strtab + sym->st_name;
1206 1208
1207 if (!name || !strlen(name)) 1209 if (!name || !strlen(name))
1208 return 0; 1210 return 0;
1209 return !is_arm_mapping_symbol(name); 1211 return !is_arm_mapping_symbol(name);
1210 } 1212 }
1211 1213
1212 /* 1214 /*
1213 * Find symbols before or equal addr and after addr - in the section sec. 1215 * Find symbols before or equal addr and after addr - in the section sec.
1214 * If we find two symbols with equal offset prefer one with a valid name. 1216 * If we find two symbols with equal offset prefer one with a valid name.
1215 * The ELF format may have a better way to detect what type of symbol 1217 * The ELF format may have a better way to detect what type of symbol
1216 * it is, but this works for now. 1218 * it is, but this works for now.
1217 **/ 1219 **/
1218 static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr, 1220 static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr,
1219 const char *sec) 1221 const char *sec)
1220 { 1222 {
1221 Elf_Sym *sym; 1223 Elf_Sym *sym;
1222 Elf_Sym *near = NULL; 1224 Elf_Sym *near = NULL;
1223 Elf_Addr distance = ~0; 1225 Elf_Addr distance = ~0;
1224 1226
1225 for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) { 1227 for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) {
1226 const char *symsec; 1228 const char *symsec;
1227 1229
1228 if (is_shndx_special(sym->st_shndx)) 1230 if (is_shndx_special(sym->st_shndx))
1229 continue; 1231 continue;
1230 symsec = sec_name(elf, get_secindex(elf, sym)); 1232 symsec = sec_name(elf, get_secindex(elf, sym));
1231 if (strcmp(symsec, sec) != 0) 1233 if (strcmp(symsec, sec) != 0)
1232 continue; 1234 continue;
1233 if (!is_valid_name(elf, sym)) 1235 if (!is_valid_name(elf, sym))
1234 continue; 1236 continue;
1235 if (sym->st_value <= addr) { 1237 if (sym->st_value <= addr) {
1236 if ((addr - sym->st_value) < distance) { 1238 if ((addr - sym->st_value) < distance) {
1237 distance = addr - sym->st_value; 1239 distance = addr - sym->st_value;
1238 near = sym; 1240 near = sym;
1239 } else if ((addr - sym->st_value) == distance) { 1241 } else if ((addr - sym->st_value) == distance) {
1240 near = sym; 1242 near = sym;
1241 } 1243 }
1242 } 1244 }
1243 } 1245 }
1244 return near; 1246 return near;
1245 } 1247 }
1246 1248
1247 /* 1249 /*
1248 * Convert a section name to the function/data attribute 1250 * Convert a section name to the function/data attribute
1249 * .init.text => __init 1251 * .init.text => __init
1250 * .cpuinit.data => __cpudata 1252 * .cpuinit.data => __cpudata
1251 * .memexitconst => __memconst 1253 * .memexitconst => __memconst
1252 * etc. 1254 * etc.
1253 * 1255 *
1254 * The memory of returned value has been allocated on a heap. The user of this 1256 * The memory of returned value has been allocated on a heap. The user of this
1255 * method should free it after usage. 1257 * method should free it after usage.
1256 */ 1258 */
1257 static char *sec2annotation(const char *s) 1259 static char *sec2annotation(const char *s)
1258 { 1260 {
1259 if (match(s, init_exit_sections)) { 1261 if (match(s, init_exit_sections)) {
1260 char *p = malloc(20); 1262 char *p = malloc(20);
1261 char *r = p; 1263 char *r = p;
1262 1264
1263 *p++ = '_'; 1265 *p++ = '_';
1264 *p++ = '_'; 1266 *p++ = '_';
1265 if (*s == '.') 1267 if (*s == '.')
1266 s++; 1268 s++;
1267 while (*s && *s != '.') 1269 while (*s && *s != '.')
1268 *p++ = *s++; 1270 *p++ = *s++;
1269 *p = '\0'; 1271 *p = '\0';
1270 if (*s == '.') 1272 if (*s == '.')
1271 s++; 1273 s++;
1272 if (strstr(s, "rodata") != NULL) 1274 if (strstr(s, "rodata") != NULL)
1273 strcat(p, "const "); 1275 strcat(p, "const ");
1274 else if (strstr(s, "data") != NULL) 1276 else if (strstr(s, "data") != NULL)
1275 strcat(p, "data "); 1277 strcat(p, "data ");
1276 else 1278 else
1277 strcat(p, " "); 1279 strcat(p, " ");
1278 return r; 1280 return r;
1279 } else { 1281 } else {
1280 return strdup(""); 1282 return strdup("");
1281 } 1283 }
1282 } 1284 }
1283 1285
1284 static int is_function(Elf_Sym *sym) 1286 static int is_function(Elf_Sym *sym)
1285 { 1287 {
1286 if (sym) 1288 if (sym)
1287 return ELF_ST_TYPE(sym->st_info) == STT_FUNC; 1289 return ELF_ST_TYPE(sym->st_info) == STT_FUNC;
1288 else 1290 else
1289 return -1; 1291 return -1;
1290 } 1292 }
1291 1293
1292 static void print_section_list(const char * const list[20]) 1294 static void print_section_list(const char * const list[20])
1293 { 1295 {
1294 const char *const *s = list; 1296 const char *const *s = list;
1295 1297
1296 while (*s) { 1298 while (*s) {
1297 fprintf(stderr, "%s", *s); 1299 fprintf(stderr, "%s", *s);
1298 s++; 1300 s++;
1299 if (*s) 1301 if (*s)
1300 fprintf(stderr, ", "); 1302 fprintf(stderr, ", ");
1301 } 1303 }
1302 fprintf(stderr, "\n"); 1304 fprintf(stderr, "\n");
1303 } 1305 }
1304 1306
1305 /* 1307 /*
1306 * Print a warning about a section mismatch. 1308 * Print a warning about a section mismatch.
1307 * Try to find symbols near it so user can find it. 1309 * Try to find symbols near it so user can find it.
1308 * Check whitelist before warning - it may be a false positive. 1310 * Check whitelist before warning - it may be a false positive.
1309 */ 1311 */
1310 static void report_sec_mismatch(const char *modname, 1312 static void report_sec_mismatch(const char *modname,
1311 const struct sectioncheck *mismatch, 1313 const struct sectioncheck *mismatch,
1312 const char *fromsec, 1314 const char *fromsec,
1313 unsigned long long fromaddr, 1315 unsigned long long fromaddr,
1314 const char *fromsym, 1316 const char *fromsym,
1315 int from_is_func, 1317 int from_is_func,
1316 const char *tosec, const char *tosym, 1318 const char *tosec, const char *tosym,
1317 int to_is_func) 1319 int to_is_func)
1318 { 1320 {
1319 const char *from, *from_p; 1321 const char *from, *from_p;
1320 const char *to, *to_p; 1322 const char *to, *to_p;
1321 char *prl_from; 1323 char *prl_from;
1322 char *prl_to; 1324 char *prl_to;
1323 1325
1324 switch (from_is_func) { 1326 switch (from_is_func) {
1325 case 0: from = "variable"; from_p = ""; break; 1327 case 0: from = "variable"; from_p = ""; break;
1326 case 1: from = "function"; from_p = "()"; break; 1328 case 1: from = "function"; from_p = "()"; break;
1327 default: from = "(unknown reference)"; from_p = ""; break; 1329 default: from = "(unknown reference)"; from_p = ""; break;
1328 } 1330 }
1329 switch (to_is_func) { 1331 switch (to_is_func) {
1330 case 0: to = "variable"; to_p = ""; break; 1332 case 0: to = "variable"; to_p = ""; break;
1331 case 1: to = "function"; to_p = "()"; break; 1333 case 1: to = "function"; to_p = "()"; break;
1332 default: to = "(unknown reference)"; to_p = ""; break; 1334 default: to = "(unknown reference)"; to_p = ""; break;
1333 } 1335 }
1334 1336
1335 sec_mismatch_count++; 1337 sec_mismatch_count++;
1336 if (!sec_mismatch_verbose) 1338 if (!sec_mismatch_verbose)
1337 return; 1339 return;
1338 1340
1339 warn("%s(%s+0x%llx): Section mismatch in reference from the %s %s%s " 1341 warn("%s(%s+0x%llx): Section mismatch in reference from the %s %s%s "
1340 "to the %s %s:%s%s\n", 1342 "to the %s %s:%s%s\n",
1341 modname, fromsec, fromaddr, from, fromsym, from_p, to, tosec, 1343 modname, fromsec, fromaddr, from, fromsym, from_p, to, tosec,
1342 tosym, to_p); 1344 tosym, to_p);
1343 1345
1344 switch (mismatch->mismatch) { 1346 switch (mismatch->mismatch) {
1345 case TEXT_TO_ANY_INIT: 1347 case TEXT_TO_ANY_INIT:
1346 prl_from = sec2annotation(fromsec); 1348 prl_from = sec2annotation(fromsec);
1347 prl_to = sec2annotation(tosec); 1349 prl_to = sec2annotation(tosec);
1348 fprintf(stderr, 1350 fprintf(stderr,
1349 "The function %s%s() references\n" 1351 "The function %s%s() references\n"
1350 "the %s %s%s%s.\n" 1352 "the %s %s%s%s.\n"
1351 "This is often because %s lacks a %s\n" 1353 "This is often because %s lacks a %s\n"
1352 "annotation or the annotation of %s is wrong.\n", 1354 "annotation or the annotation of %s is wrong.\n",
1353 prl_from, fromsym, 1355 prl_from, fromsym,
1354 to, prl_to, tosym, to_p, 1356 to, prl_to, tosym, to_p,
1355 fromsym, prl_to, tosym); 1357 fromsym, prl_to, tosym);
1356 free(prl_from); 1358 free(prl_from);
1357 free(prl_to); 1359 free(prl_to);
1358 break; 1360 break;
1359 case DATA_TO_ANY_INIT: { 1361 case DATA_TO_ANY_INIT: {
1360 prl_to = sec2annotation(tosec); 1362 prl_to = sec2annotation(tosec);
1361 fprintf(stderr, 1363 fprintf(stderr,
1362 "The variable %s references\n" 1364 "The variable %s references\n"
1363 "the %s %s%s%s\n" 1365 "the %s %s%s%s\n"
1364 "If the reference is valid then annotate the\n" 1366 "If the reference is valid then annotate the\n"
1365 "variable with __init* or __refdata (see linux/init.h) " 1367 "variable with __init* or __refdata (see linux/init.h) "
1366 "or name the variable:\n", 1368 "or name the variable:\n",
1367 fromsym, to, prl_to, tosym, to_p); 1369 fromsym, to, prl_to, tosym, to_p);
1368 print_section_list(mismatch->symbol_white_list); 1370 print_section_list(mismatch->symbol_white_list);
1369 free(prl_to); 1371 free(prl_to);
1370 break; 1372 break;
1371 } 1373 }
1372 case TEXT_TO_ANY_EXIT: 1374 case TEXT_TO_ANY_EXIT:
1373 prl_to = sec2annotation(tosec); 1375 prl_to = sec2annotation(tosec);
1374 fprintf(stderr, 1376 fprintf(stderr,
1375 "The function %s() references a %s in an exit section.\n" 1377 "The function %s() references a %s in an exit section.\n"
1376 "Often the %s %s%s has valid usage outside the exit section\n" 1378 "Often the %s %s%s has valid usage outside the exit section\n"
1377 "and the fix is to remove the %sannotation of %s.\n", 1379 "and the fix is to remove the %sannotation of %s.\n",
1378 fromsym, to, to, tosym, to_p, prl_to, tosym); 1380 fromsym, to, to, tosym, to_p, prl_to, tosym);
1379 free(prl_to); 1381 free(prl_to);
1380 break; 1382 break;
1381 case DATA_TO_ANY_EXIT: { 1383 case DATA_TO_ANY_EXIT: {
1382 prl_to = sec2annotation(tosec); 1384 prl_to = sec2annotation(tosec);
1383 fprintf(stderr, 1385 fprintf(stderr,
1384 "The variable %s references\n" 1386 "The variable %s references\n"
1385 "the %s %s%s%s\n" 1387 "the %s %s%s%s\n"
1386 "If the reference is valid then annotate the\n" 1388 "If the reference is valid then annotate the\n"
1387 "variable with __exit* (see linux/init.h) or " 1389 "variable with __exit* (see linux/init.h) or "
1388 "name the variable:\n", 1390 "name the variable:\n",
1389 fromsym, to, prl_to, tosym, to_p); 1391 fromsym, to, prl_to, tosym, to_p);
1390 print_section_list(mismatch->symbol_white_list); 1392 print_section_list(mismatch->symbol_white_list);
1391 free(prl_to); 1393 free(prl_to);
1392 break; 1394 break;
1393 } 1395 }
1394 case XXXINIT_TO_SOME_INIT: 1396 case XXXINIT_TO_SOME_INIT:
1395 case XXXEXIT_TO_SOME_EXIT: 1397 case XXXEXIT_TO_SOME_EXIT:
1396 prl_from = sec2annotation(fromsec); 1398 prl_from = sec2annotation(fromsec);
1397 prl_to = sec2annotation(tosec); 1399 prl_to = sec2annotation(tosec);
1398 fprintf(stderr, 1400 fprintf(stderr,
1399 "The %s %s%s%s references\n" 1401 "The %s %s%s%s references\n"
1400 "a %s %s%s%s.\n" 1402 "a %s %s%s%s.\n"
1401 "If %s is only used by %s then\n" 1403 "If %s is only used by %s then\n"
1402 "annotate %s with a matching annotation.\n", 1404 "annotate %s with a matching annotation.\n",
1403 from, prl_from, fromsym, from_p, 1405 from, prl_from, fromsym, from_p,
1404 to, prl_to, tosym, to_p, 1406 to, prl_to, tosym, to_p,
1405 tosym, fromsym, tosym); 1407 tosym, fromsym, tosym);
1406 free(prl_from); 1408 free(prl_from);
1407 free(prl_to); 1409 free(prl_to);
1408 break; 1410 break;
1409 case ANY_INIT_TO_ANY_EXIT: 1411 case ANY_INIT_TO_ANY_EXIT:
1410 prl_from = sec2annotation(fromsec); 1412 prl_from = sec2annotation(fromsec);
1411 prl_to = sec2annotation(tosec); 1413 prl_to = sec2annotation(tosec);
1412 fprintf(stderr, 1414 fprintf(stderr,
1413 "The %s %s%s%s references\n" 1415 "The %s %s%s%s references\n"
1414 "a %s %s%s%s.\n" 1416 "a %s %s%s%s.\n"
1415 "This is often seen when error handling " 1417 "This is often seen when error handling "
1416 "in the init function\n" 1418 "in the init function\n"
1417 "uses functionality in the exit path.\n" 1419 "uses functionality in the exit path.\n"
1418 "The fix is often to remove the %sannotation of\n" 1420 "The fix is often to remove the %sannotation of\n"
1419 "%s%s so it may be used outside an exit section.\n", 1421 "%s%s so it may be used outside an exit section.\n",
1420 from, prl_from, fromsym, from_p, 1422 from, prl_from, fromsym, from_p,
1421 to, prl_to, tosym, to_p, 1423 to, prl_to, tosym, to_p,
1422 prl_to, tosym, to_p); 1424 prl_to, tosym, to_p);
1423 free(prl_from); 1425 free(prl_from);
1424 free(prl_to); 1426 free(prl_to);
1425 break; 1427 break;
1426 case ANY_EXIT_TO_ANY_INIT: 1428 case ANY_EXIT_TO_ANY_INIT:
1427 prl_from = sec2annotation(fromsec); 1429 prl_from = sec2annotation(fromsec);
1428 prl_to = sec2annotation(tosec); 1430 prl_to = sec2annotation(tosec);
1429 fprintf(stderr, 1431 fprintf(stderr,
1430 "The %s %s%s%s references\n" 1432 "The %s %s%s%s references\n"
1431 "a %s %s%s%s.\n" 1433 "a %s %s%s%s.\n"
1432 "This is often seen when error handling " 1434 "This is often seen when error handling "
1433 "in the exit function\n" 1435 "in the exit function\n"
1434 "uses functionality in the init path.\n" 1436 "uses functionality in the init path.\n"
1435 "The fix is often to remove the %sannotation of\n" 1437 "The fix is often to remove the %sannotation of\n"
1436 "%s%s so it may be used outside an init section.\n", 1438 "%s%s so it may be used outside an init section.\n",
1437 from, prl_from, fromsym, from_p, 1439 from, prl_from, fromsym, from_p,
1438 to, prl_to, tosym, to_p, 1440 to, prl_to, tosym, to_p,
1439 prl_to, tosym, to_p); 1441 prl_to, tosym, to_p);
1440 free(prl_from); 1442 free(prl_from);
1441 free(prl_to); 1443 free(prl_to);
1442 break; 1444 break;
1443 case EXPORT_TO_INIT_EXIT: 1445 case EXPORT_TO_INIT_EXIT:
1444 prl_to = sec2annotation(tosec); 1446 prl_to = sec2annotation(tosec);
1445 fprintf(stderr, 1447 fprintf(stderr,
1446 "The symbol %s is exported and annotated %s\n" 1448 "The symbol %s is exported and annotated %s\n"
1447 "Fix this by removing the %sannotation of %s " 1449 "Fix this by removing the %sannotation of %s "
1448 "or drop the export.\n", 1450 "or drop the export.\n",
1449 tosym, prl_to, prl_to, tosym); 1451 tosym, prl_to, prl_to, tosym);
1450 free(prl_to); 1452 free(prl_to);
1451 break; 1453 break;
1452 } 1454 }
1453 fprintf(stderr, "\n"); 1455 fprintf(stderr, "\n");
1454 } 1456 }
1455 1457
1456 static void check_section_mismatch(const char *modname, struct elf_info *elf, 1458 static void check_section_mismatch(const char *modname, struct elf_info *elf,
1457 Elf_Rela *r, Elf_Sym *sym, const char *fromsec) 1459 Elf_Rela *r, Elf_Sym *sym, const char *fromsec)
1458 { 1460 {
1459 const char *tosec; 1461 const char *tosec;
1460 const struct sectioncheck *mismatch; 1462 const struct sectioncheck *mismatch;
1461 1463
1462 tosec = sec_name(elf, get_secindex(elf, sym)); 1464 tosec = sec_name(elf, get_secindex(elf, sym));
1463 mismatch = section_mismatch(fromsec, tosec); 1465 mismatch = section_mismatch(fromsec, tosec);
1464 if (mismatch) { 1466 if (mismatch) {
1465 Elf_Sym *to; 1467 Elf_Sym *to;
1466 Elf_Sym *from; 1468 Elf_Sym *from;
1467 const char *tosym; 1469 const char *tosym;
1468 const char *fromsym; 1470 const char *fromsym;
1469 1471
1470 from = find_elf_symbol2(elf, r->r_offset, fromsec); 1472 from = find_elf_symbol2(elf, r->r_offset, fromsec);
1471 fromsym = sym_name(elf, from); 1473 fromsym = sym_name(elf, from);
1472 to = find_elf_symbol(elf, r->r_addend, sym); 1474 to = find_elf_symbol(elf, r->r_addend, sym);
1473 tosym = sym_name(elf, to); 1475 tosym = sym_name(elf, to);
1474 1476
1475 /* check whitelist - we may ignore it */ 1477 /* check whitelist - we may ignore it */
1476 if (secref_whitelist(mismatch, 1478 if (secref_whitelist(mismatch,
1477 fromsec, fromsym, tosec, tosym)) { 1479 fromsec, fromsym, tosec, tosym)) {
1478 report_sec_mismatch(modname, mismatch, 1480 report_sec_mismatch(modname, mismatch,
1479 fromsec, r->r_offset, fromsym, 1481 fromsec, r->r_offset, fromsym,
1480 is_function(from), tosec, tosym, 1482 is_function(from), tosec, tosym,
1481 is_function(to)); 1483 is_function(to));
1482 } 1484 }
1483 } 1485 }
1484 } 1486 }
1485 1487
1486 static unsigned int *reloc_location(struct elf_info *elf, 1488 static unsigned int *reloc_location(struct elf_info *elf,
1487 Elf_Shdr *sechdr, Elf_Rela *r) 1489 Elf_Shdr *sechdr, Elf_Rela *r)
1488 { 1490 {
1489 Elf_Shdr *sechdrs = elf->sechdrs; 1491 Elf_Shdr *sechdrs = elf->sechdrs;
1490 int section = sechdr->sh_info; 1492 int section = sechdr->sh_info;
1491 1493
1492 return (void *)elf->hdr + sechdrs[section].sh_offset + 1494 return (void *)elf->hdr + sechdrs[section].sh_offset +
1493 r->r_offset; 1495 r->r_offset;
1494 } 1496 }
1495 1497
1496 static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) 1498 static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
1497 { 1499 {
1498 unsigned int r_typ = ELF_R_TYPE(r->r_info); 1500 unsigned int r_typ = ELF_R_TYPE(r->r_info);
1499 unsigned int *location = reloc_location(elf, sechdr, r); 1501 unsigned int *location = reloc_location(elf, sechdr, r);
1500 1502
1501 switch (r_typ) { 1503 switch (r_typ) {
1502 case R_386_32: 1504 case R_386_32:
1503 r->r_addend = TO_NATIVE(*location); 1505 r->r_addend = TO_NATIVE(*location);
1504 break; 1506 break;
1505 case R_386_PC32: 1507 case R_386_PC32:
1506 r->r_addend = TO_NATIVE(*location) + 4; 1508 r->r_addend = TO_NATIVE(*location) + 4;
1507 /* For CONFIG_RELOCATABLE=y */ 1509 /* For CONFIG_RELOCATABLE=y */
1508 if (elf->hdr->e_type == ET_EXEC) 1510 if (elf->hdr->e_type == ET_EXEC)
1509 r->r_addend += r->r_offset; 1511 r->r_addend += r->r_offset;
1510 break; 1512 break;
1511 } 1513 }
1512 return 0; 1514 return 0;
1513 } 1515 }
1514 1516
1515 #ifndef R_ARM_CALL 1517 #ifndef R_ARM_CALL
1516 #define R_ARM_CALL 28 1518 #define R_ARM_CALL 28
1517 #endif 1519 #endif
1518 #ifndef R_ARM_JUMP24 1520 #ifndef R_ARM_JUMP24
1519 #define R_ARM_JUMP24 29 1521 #define R_ARM_JUMP24 29
1520 #endif 1522 #endif
1521 1523
1522 static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) 1524 static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
1523 { 1525 {
1524 unsigned int r_typ = ELF_R_TYPE(r->r_info); 1526 unsigned int r_typ = ELF_R_TYPE(r->r_info);
1525 1527
1526 switch (r_typ) { 1528 switch (r_typ) {
1527 case R_ARM_ABS32: 1529 case R_ARM_ABS32:
1528 /* From ARM ABI: (S + A) | T */ 1530 /* From ARM ABI: (S + A) | T */
1529 r->r_addend = (int)(long) 1531 r->r_addend = (int)(long)
1530 (elf->symtab_start + ELF_R_SYM(r->r_info)); 1532 (elf->symtab_start + ELF_R_SYM(r->r_info));
1531 break; 1533 break;
1532 case R_ARM_PC24: 1534 case R_ARM_PC24:
1533 case R_ARM_CALL: 1535 case R_ARM_CALL:
1534 case R_ARM_JUMP24: 1536 case R_ARM_JUMP24:
1535 /* From ARM ABI: ((S + A) | T) - P */ 1537 /* From ARM ABI: ((S + A) | T) - P */
1536 r->r_addend = (int)(long)(elf->hdr + 1538 r->r_addend = (int)(long)(elf->hdr +
1537 sechdr->sh_offset + 1539 sechdr->sh_offset +
1538 (r->r_offset - sechdr->sh_addr)); 1540 (r->r_offset - sechdr->sh_addr));
1539 break; 1541 break;
1540 default: 1542 default:
1541 return 1; 1543 return 1;
1542 } 1544 }
1543 return 0; 1545 return 0;
1544 } 1546 }
1545 1547
1546 static int addend_mips_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) 1548 static int addend_mips_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
1547 { 1549 {
1548 unsigned int r_typ = ELF_R_TYPE(r->r_info); 1550 unsigned int r_typ = ELF_R_TYPE(r->r_info);
1549 unsigned int *location = reloc_location(elf, sechdr, r); 1551 unsigned int *location = reloc_location(elf, sechdr, r);
1550 unsigned int inst; 1552 unsigned int inst;
1551 1553
1552 if (r_typ == R_MIPS_HI16) 1554 if (r_typ == R_MIPS_HI16)
1553 return 1; /* skip this */ 1555 return 1; /* skip this */
1554 inst = TO_NATIVE(*location); 1556 inst = TO_NATIVE(*location);
1555 switch (r_typ) { 1557 switch (r_typ) {
1556 case R_MIPS_LO16: 1558 case R_MIPS_LO16:
1557 r->r_addend = inst & 0xffff; 1559 r->r_addend = inst & 0xffff;
1558 break; 1560 break;
1559 case R_MIPS_26: 1561 case R_MIPS_26:
1560 r->r_addend = (inst & 0x03ffffff) << 2; 1562 r->r_addend = (inst & 0x03ffffff) << 2;
1561 break; 1563 break;
1562 case R_MIPS_32: 1564 case R_MIPS_32:
1563 r->r_addend = inst; 1565 r->r_addend = inst;
1564 break; 1566 break;
1565 } 1567 }
1566 return 0; 1568 return 0;
1567 } 1569 }
1568 1570
1569 static void section_rela(const char *modname, struct elf_info *elf, 1571 static void section_rela(const char *modname, struct elf_info *elf,
1570 Elf_Shdr *sechdr) 1572 Elf_Shdr *sechdr)
1571 { 1573 {
1572 Elf_Sym *sym; 1574 Elf_Sym *sym;
1573 Elf_Rela *rela; 1575 Elf_Rela *rela;
1574 Elf_Rela r; 1576 Elf_Rela r;
1575 unsigned int r_sym; 1577 unsigned int r_sym;
1576 const char *fromsec; 1578 const char *fromsec;
1577 1579
1578 Elf_Rela *start = (void *)elf->hdr + sechdr->sh_offset; 1580 Elf_Rela *start = (void *)elf->hdr + sechdr->sh_offset;
1579 Elf_Rela *stop = (void *)start + sechdr->sh_size; 1581 Elf_Rela *stop = (void *)start + sechdr->sh_size;
1580 1582
1581 fromsec = sech_name(elf, sechdr); 1583 fromsec = sech_name(elf, sechdr);
1582 fromsec += strlen(".rela"); 1584 fromsec += strlen(".rela");
1583 /* if from section (name) is know good then skip it */ 1585 /* if from section (name) is know good then skip it */
1584 if (match(fromsec, section_white_list)) 1586 if (match(fromsec, section_white_list))
1585 return; 1587 return;
1586 1588
1587 for (rela = start; rela < stop; rela++) { 1589 for (rela = start; rela < stop; rela++) {
1588 r.r_offset = TO_NATIVE(rela->r_offset); 1590 r.r_offset = TO_NATIVE(rela->r_offset);
1589 #if KERNEL_ELFCLASS == ELFCLASS64 1591 #if KERNEL_ELFCLASS == ELFCLASS64
1590 if (elf->hdr->e_machine == EM_MIPS) { 1592 if (elf->hdr->e_machine == EM_MIPS) {
1591 unsigned int r_typ; 1593 unsigned int r_typ;
1592 r_sym = ELF64_MIPS_R_SYM(rela->r_info); 1594 r_sym = ELF64_MIPS_R_SYM(rela->r_info);
1593 r_sym = TO_NATIVE(r_sym); 1595 r_sym = TO_NATIVE(r_sym);
1594 r_typ = ELF64_MIPS_R_TYPE(rela->r_info); 1596 r_typ = ELF64_MIPS_R_TYPE(rela->r_info);
1595 r.r_info = ELF64_R_INFO(r_sym, r_typ); 1597 r.r_info = ELF64_R_INFO(r_sym, r_typ);
1596 } else { 1598 } else {
1597 r.r_info = TO_NATIVE(rela->r_info); 1599 r.r_info = TO_NATIVE(rela->r_info);
1598 r_sym = ELF_R_SYM(r.r_info); 1600 r_sym = ELF_R_SYM(r.r_info);
1599 } 1601 }
1600 #else 1602 #else
1601 r.r_info = TO_NATIVE(rela->r_info); 1603 r.r_info = TO_NATIVE(rela->r_info);
1602 r_sym = ELF_R_SYM(r.r_info); 1604 r_sym = ELF_R_SYM(r.r_info);
1603 #endif 1605 #endif
1604 r.r_addend = TO_NATIVE(rela->r_addend); 1606 r.r_addend = TO_NATIVE(rela->r_addend);
1605 sym = elf->symtab_start + r_sym; 1607 sym = elf->symtab_start + r_sym;
1606 /* Skip special sections */ 1608 /* Skip special sections */
1607 if (is_shndx_special(sym->st_shndx)) 1609 if (is_shndx_special(sym->st_shndx))
1608 continue; 1610 continue;
1609 check_section_mismatch(modname, elf, &r, sym, fromsec); 1611 check_section_mismatch(modname, elf, &r, sym, fromsec);
1610 } 1612 }
1611 } 1613 }
1612 1614
1613 static void section_rel(const char *modname, struct elf_info *elf, 1615 static void section_rel(const char *modname, struct elf_info *elf,
1614 Elf_Shdr *sechdr) 1616 Elf_Shdr *sechdr)
1615 { 1617 {
1616 Elf_Sym *sym; 1618 Elf_Sym *sym;
1617 Elf_Rel *rel; 1619 Elf_Rel *rel;
1618 Elf_Rela r; 1620 Elf_Rela r;
1619 unsigned int r_sym; 1621 unsigned int r_sym;
1620 const char *fromsec; 1622 const char *fromsec;
1621 1623
1622 Elf_Rel *start = (void *)elf->hdr + sechdr->sh_offset; 1624 Elf_Rel *start = (void *)elf->hdr + sechdr->sh_offset;
1623 Elf_Rel *stop = (void *)start + sechdr->sh_size; 1625 Elf_Rel *stop = (void *)start + sechdr->sh_size;
1624 1626
1625 fromsec = sech_name(elf, sechdr); 1627 fromsec = sech_name(elf, sechdr);
1626 fromsec += strlen(".rel"); 1628 fromsec += strlen(".rel");
1627 /* if from section (name) is know good then skip it */ 1629 /* if from section (name) is know good then skip it */
1628 if (match(fromsec, section_white_list)) 1630 if (match(fromsec, section_white_list))
1629 return; 1631 return;
1630 1632
1631 for (rel = start; rel < stop; rel++) { 1633 for (rel = start; rel < stop; rel++) {
1632 r.r_offset = TO_NATIVE(rel->r_offset); 1634 r.r_offset = TO_NATIVE(rel->r_offset);
1633 #if KERNEL_ELFCLASS == ELFCLASS64 1635 #if KERNEL_ELFCLASS == ELFCLASS64
1634 if (elf->hdr->e_machine == EM_MIPS) { 1636 if (elf->hdr->e_machine == EM_MIPS) {
1635 unsigned int r_typ; 1637 unsigned int r_typ;
1636 r_sym = ELF64_MIPS_R_SYM(rel->r_info); 1638 r_sym = ELF64_MIPS_R_SYM(rel->r_info);
1637 r_sym = TO_NATIVE(r_sym); 1639 r_sym = TO_NATIVE(r_sym);
1638 r_typ = ELF64_MIPS_R_TYPE(rel->r_info); 1640 r_typ = ELF64_MIPS_R_TYPE(rel->r_info);
1639 r.r_info = ELF64_R_INFO(r_sym, r_typ); 1641 r.r_info = ELF64_R_INFO(r_sym, r_typ);
1640 } else { 1642 } else {
1641 r.r_info = TO_NATIVE(rel->r_info); 1643 r.r_info = TO_NATIVE(rel->r_info);
1642 r_sym = ELF_R_SYM(r.r_info); 1644 r_sym = ELF_R_SYM(r.r_info);
1643 } 1645 }
1644 #else 1646 #else
1645 r.r_info = TO_NATIVE(rel->r_info); 1647 r.r_info = TO_NATIVE(rel->r_info);
1646 r_sym = ELF_R_SYM(r.r_info); 1648 r_sym = ELF_R_SYM(r.r_info);
1647 #endif 1649 #endif
1648 r.r_addend = 0; 1650 r.r_addend = 0;
1649 switch (elf->hdr->e_machine) { 1651 switch (elf->hdr->e_machine) {
1650 case EM_386: 1652 case EM_386:
1651 if (addend_386_rel(elf, sechdr, &r)) 1653 if (addend_386_rel(elf, sechdr, &r))
1652 continue; 1654 continue;
1653 break; 1655 break;
1654 case EM_ARM: 1656 case EM_ARM:
1655 if (addend_arm_rel(elf, sechdr, &r)) 1657 if (addend_arm_rel(elf, sechdr, &r))
1656 continue; 1658 continue;
1657 break; 1659 break;
1658 case EM_MIPS: 1660 case EM_MIPS:
1659 if (addend_mips_rel(elf, sechdr, &r)) 1661 if (addend_mips_rel(elf, sechdr, &r))
1660 continue; 1662 continue;
1661 break; 1663 break;
1662 } 1664 }
1663 sym = elf->symtab_start + r_sym; 1665 sym = elf->symtab_start + r_sym;
1664 /* Skip special sections */ 1666 /* Skip special sections */
1665 if (is_shndx_special(sym->st_shndx)) 1667 if (is_shndx_special(sym->st_shndx))
1666 continue; 1668 continue;
1667 check_section_mismatch(modname, elf, &r, sym, fromsec); 1669 check_section_mismatch(modname, elf, &r, sym, fromsec);
1668 } 1670 }
1669 } 1671 }
1670 1672
1671 /** 1673 /**
1672 * A module includes a number of sections that are discarded 1674 * A module includes a number of sections that are discarded
1673 * either when loaded or when used as built-in. 1675 * either when loaded or when used as built-in.
1674 * For loaded modules all functions marked __init and all data 1676 * For loaded modules all functions marked __init and all data
1675 * marked __initdata will be discarded when the module has been initialized. 1677 * marked __initdata will be discarded when the module has been initialized.
1676 * Likewise for modules used built-in the sections marked __exit 1678 * Likewise for modules used built-in the sections marked __exit
1677 * are discarded because __exit marked function are supposed to be called 1679 * are discarded because __exit marked function are supposed to be called
1678 * only when a module is unloaded which never happens for built-in modules. 1680 * only when a module is unloaded which never happens for built-in modules.
1679 * The check_sec_ref() function traverses all relocation records 1681 * The check_sec_ref() function traverses all relocation records
1680 * to find all references to a section that reference a section that will 1682 * to find all references to a section that reference a section that will
1681 * be discarded and warns about it. 1683 * be discarded and warns about it.
1682 **/ 1684 **/
1683 static void check_sec_ref(struct module *mod, const char *modname, 1685 static void check_sec_ref(struct module *mod, const char *modname,
1684 struct elf_info *elf) 1686 struct elf_info *elf)
1685 { 1687 {
1686 int i; 1688 int i;
1687 Elf_Shdr *sechdrs = elf->sechdrs; 1689 Elf_Shdr *sechdrs = elf->sechdrs;
1688 1690
1689 /* Walk through all sections */ 1691 /* Walk through all sections */
1690 for (i = 0; i < elf->num_sections; i++) { 1692 for (i = 0; i < elf->num_sections; i++) {
1691 check_section(modname, elf, &elf->sechdrs[i]); 1693 check_section(modname, elf, &elf->sechdrs[i]);
1692 /* We want to process only relocation sections and not .init */ 1694 /* We want to process only relocation sections and not .init */
1693 if (sechdrs[i].sh_type == SHT_RELA) 1695 if (sechdrs[i].sh_type == SHT_RELA)
1694 section_rela(modname, elf, &elf->sechdrs[i]); 1696 section_rela(modname, elf, &elf->sechdrs[i]);
1695 else if (sechdrs[i].sh_type == SHT_REL) 1697 else if (sechdrs[i].sh_type == SHT_REL)
1696 section_rel(modname, elf, &elf->sechdrs[i]); 1698 section_rel(modname, elf, &elf->sechdrs[i]);
1697 } 1699 }
1698 } 1700 }
1699 1701
1700 static void read_symbols(char *modname) 1702 static void read_symbols(char *modname)
1701 { 1703 {
1702 const char *symname; 1704 const char *symname;
1703 char *version; 1705 char *version;
1704 char *license; 1706 char *license;
1705 struct module *mod; 1707 struct module *mod;
1706 struct elf_info info = { }; 1708 struct elf_info info = { };
1707 Elf_Sym *sym; 1709 Elf_Sym *sym;
1708 1710
1709 if (!parse_elf(&info, modname)) 1711 if (!parse_elf(&info, modname))
1710 return; 1712 return;
1711 1713
1712 mod = new_module(modname); 1714 mod = new_module(modname);
1713 1715
1714 /* When there's no vmlinux, don't print warnings about 1716 /* When there's no vmlinux, don't print warnings about
1715 * unresolved symbols (since there'll be too many ;) */ 1717 * unresolved symbols (since there'll be too many ;) */
1716 if (is_vmlinux(modname)) { 1718 if (is_vmlinux(modname)) {
1717 have_vmlinux = 1; 1719 have_vmlinux = 1;
1718 mod->skip = 1; 1720 mod->skip = 1;
1719 } 1721 }
1720 1722
1721 license = get_modinfo(info.modinfo, info.modinfo_len, "license"); 1723 license = get_modinfo(info.modinfo, info.modinfo_len, "license");
1722 if (info.modinfo && !license && !is_vmlinux(modname)) 1724 if (info.modinfo && !license && !is_vmlinux(modname))
1723 warn("modpost: missing MODULE_LICENSE() in %s\n" 1725 warn("modpost: missing MODULE_LICENSE() in %s\n"
1724 "see include/linux/module.h for " 1726 "see include/linux/module.h for "
1725 "more information\n", modname); 1727 "more information\n", modname);
1726 while (license) { 1728 while (license) {
1727 if (license_is_gpl_compatible(license)) 1729 if (license_is_gpl_compatible(license))
1728 mod->gpl_compatible = 1; 1730 mod->gpl_compatible = 1;
1729 else { 1731 else {
1730 mod->gpl_compatible = 0; 1732 mod->gpl_compatible = 0;
1731 break; 1733 break;
1732 } 1734 }
1733 license = get_next_modinfo(info.modinfo, info.modinfo_len, 1735 license = get_next_modinfo(info.modinfo, info.modinfo_len,
1734 "license", license); 1736 "license", license);
1735 } 1737 }
1736 1738
1737 for (sym = info.symtab_start; sym < info.symtab_stop; sym++) { 1739 for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
1738 symname = info.strtab + sym->st_name; 1740 symname = info.strtab + sym->st_name;
1739 1741
1740 handle_modversions(mod, &info, sym, symname); 1742 handle_modversions(mod, &info, sym, symname);
1741 handle_moddevtable(mod, &info, sym, symname); 1743 handle_moddevtable(mod, &info, sym, symname);
1742 } 1744 }
1743 if (!is_vmlinux(modname) || 1745 if (!is_vmlinux(modname) ||
1744 (is_vmlinux(modname) && vmlinux_section_warnings)) 1746 (is_vmlinux(modname) && vmlinux_section_warnings))
1745 check_sec_ref(mod, modname, &info); 1747 check_sec_ref(mod, modname, &info);
1746 1748
1747 version = get_modinfo(info.modinfo, info.modinfo_len, "version"); 1749 version = get_modinfo(info.modinfo, info.modinfo_len, "version");
1748 if (version) 1750 if (version)
1749 maybe_frob_rcs_version(modname, version, info.modinfo, 1751 maybe_frob_rcs_version(modname, version, info.modinfo,
1750 version - (char *)info.hdr); 1752 version - (char *)info.hdr);
1751 if (version || (all_versions && !is_vmlinux(modname))) 1753 if (version || (all_versions && !is_vmlinux(modname)))
1752 get_src_version(modname, mod->srcversion, 1754 get_src_version(modname, mod->srcversion,
1753 sizeof(mod->srcversion)-1); 1755 sizeof(mod->srcversion)-1);
1754 1756
1755 parse_elf_finish(&info); 1757 parse_elf_finish(&info);
1756 1758
1757 /* Our trick to get versioning for module struct etc. - it's 1759 /* Our trick to get versioning for module struct etc. - it's
1758 * never passed as an argument to an exported function, so 1760 * never passed as an argument to an exported function, so
1759 * the automatic versioning doesn't pick it up, but it's really 1761 * the automatic versioning doesn't pick it up, but it's really
1760 * important anyhow */ 1762 * important anyhow */
1761 if (modversions) 1763 if (modversions)
1762 mod->unres = alloc_symbol("module_layout", 0, mod->unres); 1764 mod->unres = alloc_symbol("module_layout", 0, mod->unres);
1763 } 1765 }
1764 1766
1767 static void read_symbols_from_files(const char *filename)
1768 {
1769 FILE *in = stdin;
1770 char fname[PATH_MAX];
1771
1772 if (strcmp(filename, "-") != 0) {
1773 in = fopen(filename, "r");
1774 if (!in)
1775 fatal("Can't open filenames file %s: %m", filename);
1776 }
1777
1778 while (fgets(fname, PATH_MAX, in) != NULL) {
1779 if (strends(fname, "\n"))
1780 fname[strlen(fname)-1] = '\0';
1781 read_symbols(fname);
1782 }
1783
1784 if (in != stdin)
1785 fclose(in);
1786 }
1787
1765 #define SZ 500 1788 #define SZ 500
1766 1789
1767 /* We first write the generated file into memory using the 1790 /* We first write the generated file into memory using the
1768 * following helper, then compare to the file on disk and 1791 * following helper, then compare to the file on disk and
1769 * only update the later if anything changed */ 1792 * only update the later if anything changed */
1770 1793
1771 void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf, 1794 void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
1772 const char *fmt, ...) 1795 const char *fmt, ...)
1773 { 1796 {
1774 char tmp[SZ]; 1797 char tmp[SZ];
1775 int len; 1798 int len;
1776 va_list ap; 1799 va_list ap;
1777 1800
1778 va_start(ap, fmt); 1801 va_start(ap, fmt);
1779 len = vsnprintf(tmp, SZ, fmt, ap); 1802 len = vsnprintf(tmp, SZ, fmt, ap);
1780 buf_write(buf, tmp, len); 1803 buf_write(buf, tmp, len);
1781 va_end(ap); 1804 va_end(ap);
1782 } 1805 }
1783 1806
1784 void buf_write(struct buffer *buf, const char *s, int len) 1807 void buf_write(struct buffer *buf, const char *s, int len)
1785 { 1808 {
1786 if (buf->size - buf->pos < len) { 1809 if (buf->size - buf->pos < len) {
1787 buf->size += len + SZ; 1810 buf->size += len + SZ;
1788 buf->p = realloc(buf->p, buf->size); 1811 buf->p = realloc(buf->p, buf->size);
1789 } 1812 }
1790 strncpy(buf->p + buf->pos, s, len); 1813 strncpy(buf->p + buf->pos, s, len);
1791 buf->pos += len; 1814 buf->pos += len;
1792 } 1815 }
1793 1816
1794 static void check_for_gpl_usage(enum export exp, const char *m, const char *s) 1817 static void check_for_gpl_usage(enum export exp, const char *m, const char *s)
1795 { 1818 {
1796 const char *e = is_vmlinux(m) ?"":".ko"; 1819 const char *e = is_vmlinux(m) ?"":".ko";
1797 1820
1798 switch (exp) { 1821 switch (exp) {
1799 case export_gpl: 1822 case export_gpl:
1800 fatal("modpost: GPL-incompatible module %s%s " 1823 fatal("modpost: GPL-incompatible module %s%s "
1801 "uses GPL-only symbol '%s'\n", m, e, s); 1824 "uses GPL-only symbol '%s'\n", m, e, s);
1802 break; 1825 break;
1803 case export_unused_gpl: 1826 case export_unused_gpl:
1804 fatal("modpost: GPL-incompatible module %s%s " 1827 fatal("modpost: GPL-incompatible module %s%s "
1805 "uses GPL-only symbol marked UNUSED '%s'\n", m, e, s); 1828 "uses GPL-only symbol marked UNUSED '%s'\n", m, e, s);
1806 break; 1829 break;
1807 case export_gpl_future: 1830 case export_gpl_future:
1808 warn("modpost: GPL-incompatible module %s%s " 1831 warn("modpost: GPL-incompatible module %s%s "
1809 "uses future GPL-only symbol '%s'\n", m, e, s); 1832 "uses future GPL-only symbol '%s'\n", m, e, s);
1810 break; 1833 break;
1811 case export_plain: 1834 case export_plain:
1812 case export_unused: 1835 case export_unused:
1813 case export_unknown: 1836 case export_unknown:
1814 /* ignore */ 1837 /* ignore */
1815 break; 1838 break;
1816 } 1839 }
1817 } 1840 }
1818 1841
1819 static void check_for_unused(enum export exp, const char *m, const char *s) 1842 static void check_for_unused(enum export exp, const char *m, const char *s)
1820 { 1843 {
1821 const char *e = is_vmlinux(m) ?"":".ko"; 1844 const char *e = is_vmlinux(m) ?"":".ko";
1822 1845
1823 switch (exp) { 1846 switch (exp) {
1824 case export_unused: 1847 case export_unused:
1825 case export_unused_gpl: 1848 case export_unused_gpl:
1826 warn("modpost: module %s%s " 1849 warn("modpost: module %s%s "
1827 "uses symbol '%s' marked UNUSED\n", m, e, s); 1850 "uses symbol '%s' marked UNUSED\n", m, e, s);
1828 break; 1851 break;
1829 default: 1852 default:
1830 /* ignore */ 1853 /* ignore */
1831 break; 1854 break;
1832 } 1855 }
1833 } 1856 }
1834 1857
1835 static void check_exports(struct module *mod) 1858 static void check_exports(struct module *mod)
1836 { 1859 {
1837 struct symbol *s, *exp; 1860 struct symbol *s, *exp;
1838 1861
1839 for (s = mod->unres; s; s = s->next) { 1862 for (s = mod->unres; s; s = s->next) {
1840 const char *basename; 1863 const char *basename;
1841 exp = find_symbol(s->name); 1864 exp = find_symbol(s->name);
1842 if (!exp || exp->module == mod) 1865 if (!exp || exp->module == mod)
1843 continue; 1866 continue;
1844 basename = strrchr(mod->name, '/'); 1867 basename = strrchr(mod->name, '/');
1845 if (basename) 1868 if (basename)
1846 basename++; 1869 basename++;
1847 else 1870 else
1848 basename = mod->name; 1871 basename = mod->name;
1849 if (!mod->gpl_compatible) 1872 if (!mod->gpl_compatible)
1850 check_for_gpl_usage(exp->export, basename, exp->name); 1873 check_for_gpl_usage(exp->export, basename, exp->name);
1851 check_for_unused(exp->export, basename, exp->name); 1874 check_for_unused(exp->export, basename, exp->name);
1852 } 1875 }
1853 } 1876 }
1854 1877
1855 /** 1878 /**
1856 * Header for the generated file 1879 * Header for the generated file
1857 **/ 1880 **/
1858 static void add_header(struct buffer *b, struct module *mod) 1881 static void add_header(struct buffer *b, struct module *mod)
1859 { 1882 {
1860 buf_printf(b, "#include <linux/module.h>\n"); 1883 buf_printf(b, "#include <linux/module.h>\n");
1861 buf_printf(b, "#include <linux/vermagic.h>\n"); 1884 buf_printf(b, "#include <linux/vermagic.h>\n");
1862 buf_printf(b, "#include <linux/compiler.h>\n"); 1885 buf_printf(b, "#include <linux/compiler.h>\n");
1863 buf_printf(b, "\n"); 1886 buf_printf(b, "\n");
1864 buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n"); 1887 buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n");
1865 buf_printf(b, "\n"); 1888 buf_printf(b, "\n");
1866 buf_printf(b, "struct module __this_module\n"); 1889 buf_printf(b, "struct module __this_module\n");
1867 buf_printf(b, "__attribute__((section(\".gnu.linkonce.this_module\"))) = {\n"); 1890 buf_printf(b, "__attribute__((section(\".gnu.linkonce.this_module\"))) = {\n");
1868 buf_printf(b, "\t.name = KBUILD_MODNAME,\n"); 1891 buf_printf(b, "\t.name = KBUILD_MODNAME,\n");
1869 if (mod->has_init) 1892 if (mod->has_init)
1870 buf_printf(b, "\t.init = init_module,\n"); 1893 buf_printf(b, "\t.init = init_module,\n");
1871 if (mod->has_cleanup) 1894 if (mod->has_cleanup)
1872 buf_printf(b, "#ifdef CONFIG_MODULE_UNLOAD\n" 1895 buf_printf(b, "#ifdef CONFIG_MODULE_UNLOAD\n"
1873 "\t.exit = cleanup_module,\n" 1896 "\t.exit = cleanup_module,\n"
1874 "#endif\n"); 1897 "#endif\n");
1875 buf_printf(b, "\t.arch = MODULE_ARCH_INIT,\n"); 1898 buf_printf(b, "\t.arch = MODULE_ARCH_INIT,\n");
1876 buf_printf(b, "};\n"); 1899 buf_printf(b, "};\n");
1877 } 1900 }
1878 1901
1879 static void add_intree_flag(struct buffer *b, int is_intree) 1902 static void add_intree_flag(struct buffer *b, int is_intree)
1880 { 1903 {
1881 if (is_intree) 1904 if (is_intree)
1882 buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n"); 1905 buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n");
1883 } 1906 }
1884 1907
1885 static void add_staging_flag(struct buffer *b, const char *name) 1908 static void add_staging_flag(struct buffer *b, const char *name)
1886 { 1909 {
1887 static const char *staging_dir = "drivers/staging"; 1910 static const char *staging_dir = "drivers/staging";
1888 1911
1889 if (strncmp(staging_dir, name, strlen(staging_dir)) == 0) 1912 if (strncmp(staging_dir, name, strlen(staging_dir)) == 0)
1890 buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n"); 1913 buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n");
1891 } 1914 }
1892 1915
1893 /** 1916 /**
1894 * Record CRCs for unresolved symbols 1917 * Record CRCs for unresolved symbols
1895 **/ 1918 **/
1896 static int add_versions(struct buffer *b, struct module *mod) 1919 static int add_versions(struct buffer *b, struct module *mod)
1897 { 1920 {
1898 struct symbol *s, *exp; 1921 struct symbol *s, *exp;
1899 int err = 0; 1922 int err = 0;
1900 1923
1901 for (s = mod->unres; s; s = s->next) { 1924 for (s = mod->unres; s; s = s->next) {
1902 exp = find_symbol(s->name); 1925 exp = find_symbol(s->name);
1903 if (!exp || exp->module == mod) { 1926 if (!exp || exp->module == mod) {
1904 if (have_vmlinux && !s->weak) { 1927 if (have_vmlinux && !s->weak) {
1905 if (warn_unresolved) { 1928 if (warn_unresolved) {
1906 warn("\"%s\" [%s.ko] undefined!\n", 1929 warn("\"%s\" [%s.ko] undefined!\n",
1907 s->name, mod->name); 1930 s->name, mod->name);
1908 } else { 1931 } else {
1909 merror("\"%s\" [%s.ko] undefined!\n", 1932 merror("\"%s\" [%s.ko] undefined!\n",
1910 s->name, mod->name); 1933 s->name, mod->name);
1911 err = 1; 1934 err = 1;
1912 } 1935 }
1913 } 1936 }
1914 continue; 1937 continue;
1915 } 1938 }
1916 s->module = exp->module; 1939 s->module = exp->module;
1917 s->crc_valid = exp->crc_valid; 1940 s->crc_valid = exp->crc_valid;
1918 s->crc = exp->crc; 1941 s->crc = exp->crc;
1919 } 1942 }
1920 1943
1921 if (!modversions) 1944 if (!modversions)
1922 return err; 1945 return err;
1923 1946
1924 buf_printf(b, "\n"); 1947 buf_printf(b, "\n");
1925 buf_printf(b, "static const struct modversion_info ____versions[]\n"); 1948 buf_printf(b, "static const struct modversion_info ____versions[]\n");
1926 buf_printf(b, "__used\n"); 1949 buf_printf(b, "__used\n");
1927 buf_printf(b, "__attribute__((section(\"__versions\"))) = {\n"); 1950 buf_printf(b, "__attribute__((section(\"__versions\"))) = {\n");
1928 1951
1929 for (s = mod->unres; s; s = s->next) { 1952 for (s = mod->unres; s; s = s->next) {
1930 if (!s->module) 1953 if (!s->module)
1931 continue; 1954 continue;
1932 if (!s->crc_valid) { 1955 if (!s->crc_valid) {
1933 warn("\"%s\" [%s.ko] has no CRC!\n", 1956 warn("\"%s\" [%s.ko] has no CRC!\n",
1934 s->name, mod->name); 1957 s->name, mod->name);
1935 continue; 1958 continue;
1936 } 1959 }
1937 buf_printf(b, "\t{ %#8x, \"%s\" },\n", s->crc, s->name); 1960 buf_printf(b, "\t{ %#8x, __VMLINUX_SYMBOL_STR(%s) },\n",
1961 s->crc, s->name);
1938 } 1962 }
1939 1963
1940 buf_printf(b, "};\n"); 1964 buf_printf(b, "};\n");
1941 1965
1942 return err; 1966 return err;
1943 } 1967 }
1944 1968
1945 static void add_depends(struct buffer *b, struct module *mod, 1969 static void add_depends(struct buffer *b, struct module *mod,
1946 struct module *modules) 1970 struct module *modules)
1947 { 1971 {
1948 struct symbol *s; 1972 struct symbol *s;
1949 struct module *m; 1973 struct module *m;
1950 int first = 1; 1974 int first = 1;
1951 1975
1952 for (m = modules; m; m = m->next) 1976 for (m = modules; m; m = m->next)
1953 m->seen = is_vmlinux(m->name); 1977 m->seen = is_vmlinux(m->name);
1954 1978
1955 buf_printf(b, "\n"); 1979 buf_printf(b, "\n");
1956 buf_printf(b, "static const char __module_depends[]\n"); 1980 buf_printf(b, "static const char __module_depends[]\n");
1957 buf_printf(b, "__used\n"); 1981 buf_printf(b, "__used\n");
1958 buf_printf(b, "__attribute__((section(\".modinfo\"))) =\n"); 1982 buf_printf(b, "__attribute__((section(\".modinfo\"))) =\n");
1959 buf_printf(b, "\"depends="); 1983 buf_printf(b, "\"depends=");
1960 for (s = mod->unres; s; s = s->next) { 1984 for (s = mod->unres; s; s = s->next) {
1961 const char *p; 1985 const char *p;
1962 if (!s->module) 1986 if (!s->module)
1963 continue; 1987 continue;
1964 1988
1965 if (s->module->seen) 1989 if (s->module->seen)
1966 continue; 1990 continue;
1967 1991
1968 s->module->seen = 1; 1992 s->module->seen = 1;
1969 p = strrchr(s->module->name, '/'); 1993 p = strrchr(s->module->name, '/');
1970 if (p) 1994 if (p)
1971 p++; 1995 p++;
1972 else 1996 else
1973 p = s->module->name; 1997 p = s->module->name;
1974 buf_printf(b, "%s%s", first ? "" : ",", p); 1998 buf_printf(b, "%s%s", first ? "" : ",", p);
1975 first = 0; 1999 first = 0;
1976 } 2000 }
1977 buf_printf(b, "\";\n"); 2001 buf_printf(b, "\";\n");
1978 } 2002 }
1979 2003
1980 static void add_srcversion(struct buffer *b, struct module *mod) 2004 static void add_srcversion(struct buffer *b, struct module *mod)
1981 { 2005 {
1982 if (mod->srcversion[0]) { 2006 if (mod->srcversion[0]) {
1983 buf_printf(b, "\n"); 2007 buf_printf(b, "\n");
1984 buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n", 2008 buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n",
1985 mod->srcversion); 2009 mod->srcversion);
1986 } 2010 }
1987 } 2011 }
1988 2012
1989 static void write_if_changed(struct buffer *b, const char *fname) 2013 static void write_if_changed(struct buffer *b, const char *fname)
1990 { 2014 {
1991 char *tmp; 2015 char *tmp;
1992 FILE *file; 2016 FILE *file;
1993 struct stat st; 2017 struct stat st;
1994 2018
1995 file = fopen(fname, "r"); 2019 file = fopen(fname, "r");
1996 if (!file) 2020 if (!file)
1997 goto write; 2021 goto write;
1998 2022
1999 if (fstat(fileno(file), &st) < 0) 2023 if (fstat(fileno(file), &st) < 0)
2000 goto close_write; 2024 goto close_write;
2001 2025
2002 if (st.st_size != b->pos) 2026 if (st.st_size != b->pos)
2003 goto close_write; 2027 goto close_write;
2004 2028
2005 tmp = NOFAIL(malloc(b->pos)); 2029 tmp = NOFAIL(malloc(b->pos));
2006 if (fread(tmp, 1, b->pos, file) != b->pos) 2030 if (fread(tmp, 1, b->pos, file) != b->pos)
2007 goto free_write; 2031 goto free_write;
2008 2032
2009 if (memcmp(tmp, b->p, b->pos) != 0) 2033 if (memcmp(tmp, b->p, b->pos) != 0)
2010 goto free_write; 2034 goto free_write;
2011 2035
2012 free(tmp); 2036 free(tmp);
2013 fclose(file); 2037 fclose(file);
2014 return; 2038 return;
2015 2039
2016 free_write: 2040 free_write:
2017 free(tmp); 2041 free(tmp);
2018 close_write: 2042 close_write:
2019 fclose(file); 2043 fclose(file);
2020 write: 2044 write:
2021 file = fopen(fname, "w"); 2045 file = fopen(fname, "w");
2022 if (!file) { 2046 if (!file) {
2023 perror(fname); 2047 perror(fname);
2024 exit(1); 2048 exit(1);
2025 } 2049 }
2026 if (fwrite(b->p, 1, b->pos, file) != b->pos) { 2050 if (fwrite(b->p, 1, b->pos, file) != b->pos) {
2027 perror(fname); 2051 perror(fname);
2028 exit(1); 2052 exit(1);
2029 } 2053 }
2030 fclose(file); 2054 fclose(file);
2031 } 2055 }
2032 2056
2033 /* parse Module.symvers file. line format: 2057 /* parse Module.symvers file. line format:
2034 * 0x12345678<tab>symbol<tab>module[[<tab>export]<tab>something] 2058 * 0x12345678<tab>symbol<tab>module[[<tab>export]<tab>something]
2035 **/ 2059 **/
2036 static void read_dump(const char *fname, unsigned int kernel) 2060 static void read_dump(const char *fname, unsigned int kernel)
2037 { 2061 {
2038 unsigned long size, pos = 0; 2062 unsigned long size, pos = 0;
2039 void *file = grab_file(fname, &size); 2063 void *file = grab_file(fname, &size);
2040 char *line; 2064 char *line;
2041 2065
2042 if (!file) 2066 if (!file)
2043 /* No symbol versions, silently ignore */ 2067 /* No symbol versions, silently ignore */
2044 return; 2068 return;
2045 2069
2046 while ((line = get_next_line(&pos, file, size))) { 2070 while ((line = get_next_line(&pos, file, size))) {
2047 char *symname, *modname, *d, *export, *end; 2071 char *symname, *modname, *d, *export, *end;
2048 unsigned int crc; 2072 unsigned int crc;
2049 struct module *mod; 2073 struct module *mod;
2050 struct symbol *s; 2074 struct symbol *s;
2051 2075
2052 if (!(symname = strchr(line, '\t'))) 2076 if (!(symname = strchr(line, '\t')))
2053 goto fail; 2077 goto fail;
2054 *symname++ = '\0'; 2078 *symname++ = '\0';
2055 if (!(modname = strchr(symname, '\t'))) 2079 if (!(modname = strchr(symname, '\t')))
2056 goto fail; 2080 goto fail;
2057 *modname++ = '\0'; 2081 *modname++ = '\0';
2058 if ((export = strchr(modname, '\t')) != NULL) 2082 if ((export = strchr(modname, '\t')) != NULL)
2059 *export++ = '\0'; 2083 *export++ = '\0';
2060 if (export && ((end = strchr(export, '\t')) != NULL)) 2084 if (export && ((end = strchr(export, '\t')) != NULL))
2061 *end = '\0'; 2085 *end = '\0';
2062 crc = strtoul(line, &d, 16); 2086 crc = strtoul(line, &d, 16);
2063 if (*symname == '\0' || *modname == '\0' || *d != '\0') 2087 if (*symname == '\0' || *modname == '\0' || *d != '\0')
2064 goto fail; 2088 goto fail;
2065 mod = find_module(modname); 2089 mod = find_module(modname);
2066 if (!mod) { 2090 if (!mod) {
2067 if (is_vmlinux(modname)) 2091 if (is_vmlinux(modname))
2068 have_vmlinux = 1; 2092 have_vmlinux = 1;
2069 mod = new_module(modname); 2093 mod = new_module(modname);
2070 mod->skip = 1; 2094 mod->skip = 1;
2071 } 2095 }
2072 s = sym_add_exported(symname, mod, export_no(export)); 2096 s = sym_add_exported(symname, mod, export_no(export));
2073 s->kernel = kernel; 2097 s->kernel = kernel;
2074 s->preloaded = 1; 2098 s->preloaded = 1;
2075 sym_update_crc(symname, mod, crc, export_no(export)); 2099 sym_update_crc(symname, mod, crc, export_no(export));
2076 } 2100 }
2077 return; 2101 return;
2078 fail: 2102 fail:
2079 fatal("parse error in symbol dump file\n"); 2103 fatal("parse error in symbol dump file\n");
2080 } 2104 }
2081 2105
2082 /* For normal builds always dump all symbols. 2106 /* For normal builds always dump all symbols.
2083 * For external modules only dump symbols 2107 * For external modules only dump symbols
2084 * that are not read from kernel Module.symvers. 2108 * that are not read from kernel Module.symvers.
2085 **/ 2109 **/
2086 static int dump_sym(struct symbol *sym) 2110 static int dump_sym(struct symbol *sym)
2087 { 2111 {
2088 if (!external_module) 2112 if (!external_module)
2089 return 1; 2113 return 1;
2090 if (sym->vmlinux || sym->kernel) 2114 if (sym->vmlinux || sym->kernel)
2091 return 0; 2115 return 0;
2092 return 1; 2116 return 1;
2093 } 2117 }
2094 2118
2095 static void write_dump(const char *fname) 2119 static void write_dump(const char *fname)
2096 { 2120 {
2097 struct buffer buf = { }; 2121 struct buffer buf = { };
2098 struct symbol *symbol; 2122 struct symbol *symbol;
2099 int n; 2123 int n;
2100 2124
2101 for (n = 0; n < SYMBOL_HASH_SIZE ; n++) { 2125 for (n = 0; n < SYMBOL_HASH_SIZE ; n++) {
2102 symbol = symbolhash[n]; 2126 symbol = symbolhash[n];
2103 while (symbol) { 2127 while (symbol) {
2104 if (dump_sym(symbol)) 2128 if (dump_sym(symbol))
2105 buf_printf(&buf, "0x%08x\t%s\t%s\t%s\n", 2129 buf_printf(&buf, "0x%08x\t%s\t%s\t%s\n",
2106 symbol->crc, symbol->name, 2130 symbol->crc, symbol->name,
2107 symbol->module->name, 2131 symbol->module->name,
2108 export_str(symbol->export)); 2132 export_str(symbol->export));
2109 symbol = symbol->next; 2133 symbol = symbol->next;
2110 } 2134 }
2111 } 2135 }
2112 write_if_changed(&buf, fname); 2136 write_if_changed(&buf, fname);
2113 } 2137 }
2114 2138
2115 struct ext_sym_list { 2139 struct ext_sym_list {
2116 struct ext_sym_list *next; 2140 struct ext_sym_list *next;
2117 const char *file; 2141 const char *file;
2118 }; 2142 };
2119 2143
2120 int main(int argc, char **argv) 2144 int main(int argc, char **argv)
2121 { 2145 {
2122 struct module *mod; 2146 struct module *mod;
2123 struct buffer buf = { }; 2147 struct buffer buf = { };
2124 char *kernel_read = NULL, *module_read = NULL; 2148 char *kernel_read = NULL, *module_read = NULL;
2125 char *dump_write = NULL; 2149 char *dump_write = NULL, *files_source = NULL;
2126 int opt; 2150 int opt;
2127 int err; 2151 int err;
2128 struct ext_sym_list *extsym_iter; 2152 struct ext_sym_list *extsym_iter;
2129 struct ext_sym_list *extsym_start = NULL; 2153 struct ext_sym_list *extsym_start = NULL;
2130 2154
2131 while ((opt = getopt(argc, argv, "i:I:e:msSo:awM:K:")) != -1) { 2155 while ((opt = getopt(argc, argv, "i:I:e:msST:o:awM:K:")) != -1) {
2132 switch (opt) { 2156 switch (opt) {
2133 case 'i': 2157 case 'i':
2134 kernel_read = optarg; 2158 kernel_read = optarg;
2135 break; 2159 break;
2136 case 'I': 2160 case 'I':
2137 module_read = optarg; 2161 module_read = optarg;
2138 external_module = 1; 2162 external_module = 1;
2139 break; 2163 break;
2140 case 'e': 2164 case 'e':
2141 external_module = 1; 2165 external_module = 1;
2142 extsym_iter = 2166 extsym_iter =
2143 NOFAIL(malloc(sizeof(*extsym_iter))); 2167 NOFAIL(malloc(sizeof(*extsym_iter)));
2144 extsym_iter->next = extsym_start; 2168 extsym_iter->next = extsym_start;
2145 extsym_iter->file = optarg; 2169 extsym_iter->file = optarg;
2146 extsym_start = extsym_iter; 2170 extsym_start = extsym_iter;
2147 break; 2171 break;
2148 case 'm': 2172 case 'm':
2149 modversions = 1; 2173 modversions = 1;
2150 break; 2174 break;
2151 case 'o': 2175 case 'o':
2152 dump_write = optarg; 2176 dump_write = optarg;
2153 break; 2177 break;
2154 case 'a': 2178 case 'a':
2155 all_versions = 1; 2179 all_versions = 1;
2156 break; 2180 break;
2157 case 's': 2181 case 's':
2158 vmlinux_section_warnings = 0; 2182 vmlinux_section_warnings = 0;
2159 break; 2183 break;
2160 case 'S': 2184 case 'S':
2161 sec_mismatch_verbose = 0; 2185 sec_mismatch_verbose = 0;
2162 break; 2186 break;
2187 case 'T':
2188 files_source = optarg;
2189 break;
2163 case 'w': 2190 case 'w':
2164 warn_unresolved = 1; 2191 warn_unresolved = 1;
2165 break; 2192 break;
2166 default: 2193 default:
2167 exit(1); 2194 exit(1);
2168 } 2195 }
2169 } 2196 }
2170 2197
2171 if (kernel_read) 2198 if (kernel_read)
2172 read_dump(kernel_read, 1); 2199 read_dump(kernel_read, 1);
2173 if (module_read) 2200 if (module_read)
2174 read_dump(module_read, 0); 2201 read_dump(module_read, 0);
2175 while (extsym_start) { 2202 while (extsym_start) {
2176 read_dump(extsym_start->file, 0); 2203 read_dump(extsym_start->file, 0);
2177 extsym_iter = extsym_start->next; 2204 extsym_iter = extsym_start->next;
2178 free(extsym_start); 2205 free(extsym_start);
2179 extsym_start = extsym_iter; 2206 extsym_start = extsym_iter;
2180 } 2207 }
2181 2208
2182 while (optind < argc) 2209 while (optind < argc)
2183 read_symbols(argv[optind++]); 2210 read_symbols(argv[optind++]);
2211
2212 if (files_source)
2213 read_symbols_from_files(files_source);
2184 2214
2185 for (mod = modules; mod; mod = mod->next) { 2215 for (mod = modules; mod; mod = mod->next) {
2186 if (mod->skip) 2216 if (mod->skip)
2187 continue; 2217 continue;
2188 check_exports(mod); 2218 check_exports(mod);
2189 } 2219 }
2190 2220
2191 err = 0; 2221 err = 0;
2192 2222
2193 for (mod = modules; mod; mod = mod->next) { 2223 for (mod = modules; mod; mod = mod->next) {
2194 char fname[strlen(mod->name) + 10]; 2224 char fname[strlen(mod->name) + 10];
2195 2225
2196 if (mod->skip) 2226 if (mod->skip)
2197 continue; 2227 continue;
2198 2228
2199 buf.pos = 0; 2229 buf.pos = 0;
2200 2230
2201 add_header(&buf, mod); 2231 add_header(&buf, mod);
2202 add_intree_flag(&buf, !external_module); 2232 add_intree_flag(&buf, !external_module);
2203 add_staging_flag(&buf, mod->name); 2233 add_staging_flag(&buf, mod->name);
2204 err |= add_versions(&buf, mod); 2234 err |= add_versions(&buf, mod);
2205 add_depends(&buf, mod, modules); 2235 add_depends(&buf, mod, modules);
2206 add_moddevtable(&buf, mod); 2236 add_moddevtable(&buf, mod);
2207 add_srcversion(&buf, mod); 2237 add_srcversion(&buf, mod);
2208 2238
2209 sprintf(fname, "%s.mod.c", mod->name); 2239 sprintf(fname, "%s.mod.c", mod->name);
2210 write_if_changed(&buf, fname); 2240 write_if_changed(&buf, fname);
2211 } 2241 }
2212 2242
2213 if (dump_write) 2243 if (dump_write)