source: mainline/meson/part/compiler_args/meson.build

Last change on this file was 3fcea34, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 10 months ago

Simplify the SYS_THREAD_CREATE syscall interface

Removed the beefy uarg structure. Instead, the syscall gets two
parameters: %pc (program counter) and %sp (stack pointer). It starts
a thread with those values in corresponding registers, with no other
fuss whatsoever.

libc initializes threads by storing any other needed arguments on
the stack and retrieving them in thread_entry. Importantly, this
includes the address of the
thread_main function which is now
called indirectly to fix dynamic linking issues on some archs.

There's a bit of weirdness on SPARC and IA-64, because of their
stacked register handling. The current solution is that we require
some space *above* the stack pointer to be available for those
architectures. I think for SPARC, it can be made more normal.

For the remaining ones, we can (probably) just set the initial
%sp to the top edge of the stack. There's some lingering offsets
on some archs just because I didn't want to accidentally break
anything. The initial thread bringup should be functionally
unchanged from the previous state, and no binaries are currently
multithreaded except thread1 test, so there should be minimal
risk of breakage. Naturally, I tested all available emulator
builds, save for msim.

  • Property mode set to 100644
File size: 4.5 KB
Line 
1#
2# Copyright (c) 2019 Jiří Zárevúcky
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8#
9# - Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# - Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution.
14# - The name of the author may not be used to endorse or promote products
15# derived from this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27#
28
29# This file sets the architecture-independent compiler flags used throughout
30# this repository.
31# For architecture-specific flags, see $srcroot/meson/cross/$arch.
32
33add_project_arguments(
34 # TODO: Remove from project arguments and only use where necessary.
35 # Any change in config forces everything to rebuild due to lack of granularity here.
36 '-imacros', meson.build_root() / 'config.h',
37 language : [ 'c' ],
38)
39
40add_project_link_arguments(
41 '-Wl,--gc-sections',
42 '-Wl,--warn-common',
43 '-Wl,--fatal-warnings',
44 '-Wl,-z,text',
45 language : [ 'c', 'cpp' ],
46)
47
48# TODO: enable more warnings
49# FIXME: -fno-builtin-strftime works around seemingly spurious format warning.
50# We should investigate what's going on there.
51
52extra_common_flags = [
53 '-O' + OPTIMIZATION,
54 '-fexec-charset=UTF-8',
55 '-finput-charset=UTF-8',
56
57 '-D_HELENOS_SOURCE',
58
59 '-Wa,--fatal-warnings',
60 '-Wl,-z,text',
61
62 '-Wall',
63 '-Wextra',
64 '-Wwrite-strings',
65 '-Wunknown-pragmas',
66
67 '-Wno-unused-parameter',
68
69 '-pipe',
70
71 '-ffunction-sections',
72 '-fdata-sections',
73 '-fno-common',
74 '-fdebug-prefix-map=' + meson.source_root() + '/=',
75 '-fdebug-prefix-map=../../=',
76]
77
78if cc.get_id() != 'clang'
79 # Clang's own headers emit macro redefinition warnings.
80 extra_common_flags += '-Wsystem-headers'
81endif
82
83if UARCH != 'ia64'
84 extra_common_flags += [ '-fvar-tracking-assignments' ]
85endif
86
87if CONFIG_DEBUG
88 extra_common_flags += [ '-Werror' ]
89endif
90
91if CONFIG_LINE_DEBUG
92 extra_common_flags += [ '-gdwarf-5', '-g3' ]
93endif
94
95extra_cflags = extra_common_flags + [
96 '-Wmissing-prototypes',
97 '-Werror-implicit-function-declaration',
98
99 '-Wno-missing-braces',
100 '-Wno-missing-field-initializers',
101 '-Wno-unused-command-line-argument',
102 '-Wno-unused-parameter',
103 '-Wno-typedef-redefinition',
104 '-Wno-clobbered',
105 '-Wno-nonnull-compare',
106
107 '-fno-builtin-strftime',
108]
109
110if CONFIG_UBSAN
111 extra_cflags += '-fsanitize=undefined'
112endif
113
114extra_cppflags = extra_common_flags + [
115 '-fno-exceptions',
116 '-Wno-misleading-indentation',
117 '-frtti',
118]
119
120w_flags = {
121 'c': extra_cflags,
122 'cpp': extra_cppflags,
123}
124
125# TODO: To remove noise in Meson output, we may want to cut down on
126# the explicitly checked flags and just enable those supported by
127# both gcc and clang unconditionally.
128
129# Process flags. Only sets those that compiler supports.
130foreach lang : [ 'c', 'cpp' ]
131 extra_cflags = meson.get_compiler(lang).get_supported_arguments(w_flags.get(lang))
132 add_project_arguments(extra_cflags, language : [ lang ])
133 add_project_link_arguments(extra_cflags, language : [ lang ])
134endforeach
135
136# This flag is needed at several places, hence we define it here.
137#
138# For backwards compatibility we try to detect --no-warn-rwx-segments.
139# However, the autodetection done by Meson also results in
140# "cannot find entry symbol _start; defaulting to 00000000004000b0"
141# thus the option is never supported alone. So when detecting we also
142# specify --entry=main so that the stub source provided by Meson is build
143# correctly.
144ldflags_ignore_rwx_segments = []
145if cc.has_link_argument('-Wl,--no-warn-rwx-segments,--entry=main')
146 ldflags_ignore_rwx_segments += ['-Wl,--no-warn-rwx-segments']
147endif
Note: See TracBrowser for help on using the repository browser.