glibc-2.19.patch 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737
  1. diff --git a/Makeconfig b/Makeconfig
  2. index 1908f27..cf34ba1 100644
  3. --- a/Makeconfig
  4. +++ b/Makeconfig
  5. @@ -775,7 +775,8 @@ endif # $(+cflags) == ""
  6. # current directory.
  7. +includes = -I$(..)include $(if $(subdir),$(objpfx:%/=-I%)) \
  8. $(+sysdep-includes) $(includes) \
  9. - $(patsubst %/,-I%,$(..)) $(libio-include) -I. $(sysincludes)
  10. + $(patsubst %/,-I%,$(..)) $(libio-include) -I. $(sysincludes) \
  11. + -I$(common-objpfx)../shim/include
  12. # Since libio has several internal header files, we use a -I instead
  13. # of many little headers in the include directory.
  14. @@ -1033,7 +1034,7 @@ all-subdirs = csu assert ctype locale intl catgets math setjmp signal \
  15. grp pwd posix io termios resource misc socket sysvipc gmon \
  16. gnulib iconv iconvdata wctype manual shadow gshadow po argp \
  17. crypt localedata timezone rt conform debug \
  18. - $(add-on-subdirs) dlfcn elf
  19. + $(add-on-subdirs) dlfcn elf libos
  20. ifndef avoid-generated
  21. # sysd-sorted itself will contain rules making the sysd-sorted target
  22. diff --git a/Makefile b/Makefile
  23. index 51d4690..d72c4b0 100644
  24. --- a/Makefile
  25. +++ b/Makefile
  26. @@ -177,6 +177,8 @@ $(inst_includedir)/gnu/stubs.h: $(+force)
  27. install-others-nosubdir: $(installed-stubs)
  28. endif
  29. +# For Graphene
  30. +CFLAGS-syscalldb.c = -fPIC
  31. # Since stubs.h is never needed when building the library, we simplify the
  32. # hairy installation process by producing it in place only as the last part
  33. diff --git a/Versions.def b/Versions.def
  34. index 759c754..e1a270e 100644
  35. --- a/Versions.def
  36. +++ b/Versions.def
  37. @@ -41,6 +41,7 @@ libc {
  38. GCC_3.0
  39. %endif
  40. GLIBC_PRIVATE
  41. + SHIM
  42. }
  43. libcrypt {
  44. GLIBC_2.0
  45. @@ -50,6 +51,7 @@ libdl {
  46. GLIBC_2.1
  47. GLIBC_2.3.3
  48. GLIBC_2.3.4
  49. + SHIM
  50. }
  51. libm {
  52. GLIBC_2.0
  53. @@ -108,6 +110,7 @@ libpthread {
  54. GLIBC_2.18
  55. GLIBC_2.19
  56. GLIBC_PRIVATE
  57. + SHIM
  58. }
  59. libresolv {
  60. GLIBC_2.0
  61. @@ -135,6 +138,7 @@ ld {
  62. GLIBC_2.3
  63. GLIBC_2.4
  64. GLIBC_PRIVATE
  65. + SHIM
  66. }
  67. libthread_db {
  68. GLIBC_2.1.3
  69. @@ -148,3 +152,6 @@ libanl {
  70. libcidn {
  71. GLIBC_PRIVATE
  72. }
  73. +liblibos {
  74. + GLIBC_2.12
  75. +}
  76. diff --git a/configure b/configure
  77. index fc023d0..b71c1f9 100755
  78. --- a/configure
  79. +++ b/configure
  80. @@ -630,7 +630,8 @@ SED
  81. MAKEINFO
  82. MSGFMT
  83. MAKE
  84. -LD
  85. +LD_GOLD
  86. +LD_BFD
  87. AS
  88. OBJCOPY
  89. OBJDUMP
  90. @@ -4593,17 +4594,22 @@ if test $ac_verc_fail = yes; then
  91. AS=: critic_missing="$critic_missing as"
  92. fi
  93. -for ac_prog in $LD
  94. +LD_BFD=
  95. +LD_GOLD=
  96. +ld_is_gold="`$LD --version | sed -n 's/^GNU \(gold\).*$/\1/p'`"
  97. +if test -z "$ld_is_gold"; then
  98. + LD_BFD=$LD
  99. + for ac_prog in $LD_BFD
  100. do
  101. # Extract the first word of "$ac_prog", so it can be a program name with args.
  102. set dummy $ac_prog; ac_word=$2
  103. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  104. $as_echo_n "checking for $ac_word... " >&6; }
  105. -if ${ac_cv_prog_LD+:} false; then :
  106. +if ${ac_cv_prog_LD_BFD+:} false; then :
  107. $as_echo_n "(cached) " >&6
  108. else
  109. - if test -n "$LD"; then
  110. - ac_cv_prog_LD="$LD" # Let the user override the test.
  111. + if test -n "$LD_BFD"; then
  112. + ac_cv_prog_LD_BFD="$LD_BFD" # Let the user override the test.
  113. else
  114. as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  115. for as_dir in $PATH
  116. @@ -4612,7 +4618,7 @@ do
  117. test -z "$as_dir" && as_dir=.
  118. for ac_exec_ext in '' $ac_executable_extensions; do
  119. if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
  120. - ac_cv_prog_LD="$ac_prog"
  121. + ac_cv_prog_LD_BFD="$ac_prog"
  122. $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
  123. break 2
  124. fi
  125. @@ -4622,26 +4628,26 @@ IFS=$as_save_IFS
  126. fi
  127. fi
  128. -LD=$ac_cv_prog_LD
  129. -if test -n "$LD"; then
  130. - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LD" >&5
  131. -$as_echo "$LD" >&6; }
  132. +LD_BFD=$ac_cv_prog_LD_BFD
  133. +if test -n "$LD_BFD"; then
  134. + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LD_BFD" >&5
  135. +$as_echo "$LD_BFD" >&6; }
  136. else
  137. { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
  138. $as_echo "no" >&6; }
  139. fi
  140. - test -n "$LD" && break
  141. + test -n "$LD_BFD" && break
  142. done
  143. -if test -z "$LD"; then
  144. +if test -z "$LD_BFD"; then
  145. ac_verc_fail=yes
  146. else
  147. # Found it, now check the version.
  148. - { $as_echo "$as_me:${as_lineno-$LINENO}: checking version of $LD" >&5
  149. -$as_echo_n "checking version of $LD... " >&6; }
  150. - ac_prog_version=`$LD --version 2>&1 | sed -n 's/^.*GNU ld.* \([0-9][0-9]*\.[0-9.]*\).*$/\1/p'`
  151. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking version of $LD_BFD" >&5
  152. +$as_echo_n "checking version of $LD_BFD... " >&6; }
  153. + ac_prog_version=`$LD_BFD --version 2>&1 | sed -n 's/^.*GNU ld.* \([0-9][0-9]*\.[0-9.]*\).*$/\1/p'`
  154. case $ac_prog_version in
  155. '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
  156. 2.1[0-9][0-9]*|2.[2-9][0-9]*|[3-9].*|[1-9][0-9]*)
  157. @@ -4653,9 +4659,80 @@ $as_echo_n "checking version of $LD... " >&6; }
  158. $as_echo "$ac_prog_version" >&6; }
  159. fi
  160. if test $ac_verc_fail = yes; then
  161. - LD=: critic_missing="$critic_missing ld"
  162. + LD_BFD=:
  163. fi
  164. +else
  165. +# Accept gold 1.11 or higher.
  166. + LD_GOLD=$LD
  167. + for ac_prog in $LD_GOLD
  168. +do
  169. + # Extract the first word of "$ac_prog", so it can be a program name with args.
  170. +set dummy $ac_prog; ac_word=$2
  171. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  172. +$as_echo_n "checking for $ac_word... " >&6; }
  173. +if ${ac_cv_prog_LD_GOLD+:} false; then :
  174. + $as_echo_n "(cached) " >&6
  175. +else
  176. + if test -n "$LD_GOLD"; then
  177. + ac_cv_prog_LD_GOLD="$LD_GOLD" # Let the user override the test.
  178. +else
  179. +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  180. +for as_dir in $PATH
  181. +do
  182. + IFS=$as_save_IFS
  183. + test -z "$as_dir" && as_dir=.
  184. + for ac_exec_ext in '' $ac_executable_extensions; do
  185. + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
  186. + ac_cv_prog_LD_GOLD="$ac_prog"
  187. + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
  188. + break 2
  189. + fi
  190. +done
  191. + done
  192. +IFS=$as_save_IFS
  193. +
  194. +fi
  195. +fi
  196. +LD_GOLD=$ac_cv_prog_LD_GOLD
  197. +if test -n "$LD_GOLD"; then
  198. + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LD_GOLD" >&5
  199. +$as_echo "$LD_GOLD" >&6; }
  200. +else
  201. + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
  202. +$as_echo "no" >&6; }
  203. +fi
  204. +
  205. +
  206. + test -n "$LD_GOLD" && break
  207. +done
  208. +
  209. +if test -z "$LD_GOLD"; then
  210. + ac_verc_fail=yes
  211. +else
  212. + # Found it, now check the version.
  213. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking version of $LD_GOLD" >&5
  214. +$as_echo_n "checking version of $LD_GOLD... " >&6; }
  215. + ac_prog_version=`$LD_GOLD --version 2>&1 | sed -n 's/^.*GNU gold.* \([0-9][0-9]*\.[0-9.]*\).*$/\1/p'`
  216. + case $ac_prog_version in
  217. + '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
  218. + 1.1[1-9]*|1.[2-9][0-9]*|1.1[0-9][0-9]*|[2-9].*|[1-9][0-9]*)
  219. + ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
  220. + *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
  221. +
  222. + esac
  223. + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_prog_version" >&5
  224. +$as_echo "$ac_prog_version" >&6; }
  225. +fi
  226. +if test $ac_verc_fail = yes; then
  227. + LD_GOLD=:
  228. +fi
  229. +
  230. +fi
  231. +# Neither ld nor gold are new enough.
  232. +if test -z "$LD_BFD" && test -z "$LD_GOLD"; then
  233. + critic_missing="$critic_missing ld"
  234. +fi
  235. # These programs are version sensitive.
  236. @@ -6391,6 +6468,16 @@ $as_echo "$libc_cv_use_default_link" >&6; }
  237. use_default_link=$libc_cv_use_default_link
  238. fi
  239. +# The gold linker has no builtin default linker script,
  240. +# and the fallback of editing the builtin linker
  241. +# script is not available. Therefore if use_default_link
  242. +# is `no' then we can't use gold. This check is independent
  243. +# of gold's version and is used to sanity check that the
  244. +# linker continues to produce a useful shared link.
  245. +if test "$ld_is_gold" && test "$use_default_link" = "no"; then
  246. + as_fn_error $? "$LD did not generate a useful shared link. Try using GNU ld.bfd?" "$LINENO" 5
  247. +fi
  248. +
  249. { $as_echo "$as_me:${as_lineno-$LINENO}: checking linker output format" >&5
  250. $as_echo_n "checking linker output format... " >&6; }
  251. if ${libc_cv_output_format+:} false; then :
  252. @@ -6409,6 +6496,17 @@ fi
  253. $as_echo "$libc_cv_output_format" >&6; }
  254. +# The gold linker has no builtin default linker script,
  255. +# and the fallback of parsing the builtin linker
  256. +# script to determine the target is not available.
  257. +# Therefore if libc_cv_output_format is `unknown' then
  258. +# we can't use gold. This check is independent of gold's
  259. +# version and is used to sanity check that the linker
  260. +# continues to support --print-output-format.
  261. +if test "$ld_is_gold" && test "$libc_cv_output_format" = "unknown"; then
  262. + as_fn_error $? "$LD did not support --print-output-format. Try using GNU ld.bfd?" "$LINENO" 5
  263. +fi
  264. +
  265. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -fno-toplevel-reorder -fno-section-anchors" >&5
  266. $as_echo_n "checking for -fno-toplevel-reorder -fno-section-anchors... " >&6; }
  267. if ${libc_cv_fno_toplevel_reorder+:} false; then :
  268. diff --git a/dlfcn/Versions b/dlfcn/Versions
  269. index 97902f0..c1874c1 100644
  270. --- a/dlfcn/Versions
  271. +++ b/dlfcn/Versions
  272. @@ -14,4 +14,7 @@ libdl {
  273. GLIBC_PRIVATE {
  274. _dlfcn_hook;
  275. }
  276. + SHIM {
  277. + syscalldb;
  278. + }
  279. }
  280. diff --git a/elf/Makefile b/elf/Makefile
  281. index 4c58fc9..0ae2fa8 100644
  282. --- a/elf/Makefile
  283. +++ b/elf/Makefile
  284. @@ -21,7 +21,7 @@ subdir := elf
  285. include ../Makeconfig
  286. -headers = elf.h bits/elfclass.h link.h bits/link.h
  287. +headers = elf.h bits/elfclass.h link.h bits/link.h syscalldb.h
  288. routines = $(dl-routines) dl-support dl-iteratephdr \
  289. dl-addr enbl-secure dl-profstub \
  290. dl-origin dl-libc dl-sym dl-tsd dl-sysdep
  291. @@ -31,7 +31,8 @@ routines = $(dl-routines) dl-support dl-iteratephdr \
  292. dl-routines = $(addprefix dl-,load lookup object reloc deps hwcaps \
  293. runtime error init fini debug misc \
  294. version profile conflict tls origin scope \
  295. - execstack caller open close trampoline)
  296. + execstack caller open close trampoline) \
  297. + syscalldb syscallas
  298. ifeq (yes,$(use-ldconfig))
  299. dl-routines += dl-cache
  300. endif
  301. diff --git a/elf/Versions b/elf/Versions
  302. index 2383992..98687f6 100644
  303. --- a/elf/Versions
  304. +++ b/elf/Versions
  305. @@ -24,6 +24,9 @@ libc {
  306. _dl_sym; _dl_vsym;
  307. __libc_dlclose; __libc_dlopen_mode; __libc_dlsym;
  308. }
  309. + SHIM {
  310. + syscalldb; glibc_option;
  311. + }
  312. }
  313. ld {
  314. @@ -62,4 +65,7 @@ ld {
  315. # Pointer protection.
  316. __pointer_chk_guard;
  317. }
  318. + SHIM {
  319. + syscalldb; glibc_version; glibc_option; register_library;
  320. + }
  321. }
  322. diff --git a/elf/dl-debug.c b/elf/dl-debug.c
  323. index 4e7c593..3e0bff4 100644
  324. --- a/elf/dl-debug.c
  325. +++ b/elf/dl-debug.c
  326. @@ -34,7 +34,7 @@ extern const int verify_link_map_members
  327. normally finds it via the DT_DEBUG entry in the dynamic section, but in
  328. a statically-linked program there is no dynamic section for the debugger
  329. to examine and it looks for this particular symbol name. */
  330. -struct r_debug _r_debug;
  331. +struct r_debug __libc_r_debug;
  332. /* Initialize _r_debug if it has not already been done. The argument is
  333. @@ -48,7 +48,7 @@ _dl_debug_initialize (ElfW(Addr) ldbase,
  334. struct r_debug *r;
  335. if (ns == LM_ID_BASE)
  336. - r = &_r_debug;
  337. + r = &__libc_r_debug;
  338. else
  339. r = &GL(dl_ns)[ns]._ns_debug;
  340. @@ -56,9 +56,9 @@ _dl_debug_initialize (ElfW(Addr) ldbase,
  341. {
  342. /* Tell the debugger where to find the map of loaded objects. */
  343. r->r_version = 1 /* R_DEBUG_VERSION XXX */;
  344. - r->r_ldbase = ldbase ?: _r_debug.r_ldbase;
  345. + r->r_ldbase = ldbase ?: __libc_r_debug.r_ldbase;
  346. r->r_map = (void *) GL(dl_ns)[ns]._ns_loaded;
  347. r->r_brk = (ElfW(Addr)) &_dl_debug_state;
  348. }
  349. return r;
  350. diff --git a/elf/dl-load.c b/elf/dl-load.c
  351. index 1be7a3c..c560ec1 100644
  352. --- a/elf/dl-load.c
  353. +++ b/elf/dl-load.c
  354. @@ -39,6 +39,8 @@
  355. #include <dl-dst.h>
  356. +#include <glibc-version.h>
  357. +
  358. /* On some systems, no flag bits are given to specify file mapping. */
  359. #ifndef MAP_FILE
  360. # define MAP_FILE 0
  361. @@ -1595,6 +1597,9 @@ cannot enable executable stack as shared object requires");
  362. DL_AFTER_LOAD (l);
  363. #endif
  364. + /* register the library to SHIM */
  365. + register_library(l->l_name, l->l_addr);
  366. +
  367. /* Now that the object is fully initialized add it to the object list. */
  368. _dl_add_to_namespace_list (l, nsid);
  369. diff --git a/elf/link.h b/elf/link.h
  370. index d5905d1..f4e108a 100644
  371. --- a/elf/link.h
  372. +++ b/elf/link.h
  373. @@ -65,6 +65,7 @@ struct r_debug
  374. /* This is the instance of that structure used by the dynamic linker. */
  375. extern struct r_debug _r_debug;
  376. +asm (".symver _r_debug, __libc_r_debug@GLIBC_PRIVATE");
  377. /* This symbol refers to the "dynamic structure" in the `.dynamic' section
  378. of whatever module refers to `_DYNAMIC'. So, to find its own
  379. diff --git a/elf/rtld.c b/elf/rtld.c
  380. index 6dcbabc..c87c773 100644
  381. --- a/elf/rtld.c
  382. +++ b/elf/rtld.c
  383. @@ -356,6 +356,23 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
  384. return start_addr;
  385. }
  386. +/* For graphene, check if glibc version match to the compatible SHIM
  387. + library. If not, tell the user to update glibc. */
  388. +#include "glibc-version.h"
  389. +
  390. +volatile const int glibc_version __attribute__((weak)) = GLIBC_VERSION;
  391. +
  392. +static void __attribute__((noinline,optimize("-O0")))
  393. +check_glibc_version (void)
  394. +{
  395. + if (glibc_version != GLIBC_VERSION)
  396. + {
  397. + _dl_fatal_printf ("Warning from Graphene: "
  398. + "Glibc version is incorrect. Please rebuild Glibc.\n");
  399. + _exit (1);
  400. + }
  401. +}
  402. +
  403. static ElfW(Addr) __attribute_used__ internal_function
  404. _dl_start (void *arg)
  405. {
  406. @@ -546,6 +563,9 @@ _dl_start (void *arg)
  407. therefore need not test whether we have to allocate the array
  408. for the relocation results (as done in dl-reloc.c). */
  409. + /* For Graphene, check if the glibc version is correct. */
  410. + check_glibc_version();
  411. +
  412. /* Now life is sane; we can call functions and access global data.
  413. Set up to use the operating system facilities, and find out from
  414. the operating system's program loader where to find the program
  415. @@ -1233,9 +1253,20 @@ of this helper program; chances are you did not intend to run this program.\n\
  416. main_map->l_map_end = allocend;
  417. if ((ph->p_flags & PF_X) && allocend > main_map->l_text_end)
  418. main_map->l_text_end = allocend;
  419. +
  420. +#if 0
  421. + ElfW(Addr) mapend = (allocend + GLRO(dl_pagesize) - 1)
  422. + & ~(GLRO(dl_pagesize) - 1);
  423. + int prot = ((ph->p_flags & PF_R) ? PROT_READ : 0)|
  424. + ((ph->p_flags & PF_W) ? PROT_WRITE : 0)|
  425. + ((ph->p_flags & PF_X) ? PROT_EXEC : 0);
  426. + __mmap ((void *) mapstart, mapend - mapstart,
  427. + prot,
  428. + MAP_ANON|MAP_PRIVATE|MAP_FIXED|0x20000000,
  429. + -1, 0);
  430. +#endif
  431. }
  432. break;
  433. -
  434. case PT_TLS:
  435. if (ph->p_memsz > 0)
  436. {
  437. @@ -1381,13 +1412,31 @@ of this helper program; chances are you did not intend to run this program.\n\
  438. /* PT_GNU_RELRO is usually the last phdr. */
  439. size_t cnt = rtld_ehdr->e_phnum;
  440. while (cnt-- > 0)
  441. + {
  442. if (rtld_phdr[cnt].p_type == PT_GNU_RELRO)
  443. {
  444. GL(dl_rtld_map).l_relro_addr = rtld_phdr[cnt].p_vaddr;
  445. GL(dl_rtld_map).l_relro_size = rtld_phdr[cnt].p_memsz;
  446. - break;
  447. }
  448. +#if 0
  449. + if (rtld_phdr[cnt].p_type == PT_LOAD)
  450. + {
  451. + ElfW(Addr) mapstart = rtld_phdr[cnt].p_vaddr & ~(GLRO(dl_pagesize) - 1);
  452. + ElfW(Addr) mapend = (rtld_phdr[cnt].p_vaddr + rtld_phdr[cnt].p_memsz
  453. + + GLRO(dl_pagesize) - 1)
  454. + & ~(GLRO(dl_pagesize) - 1);
  455. + int prot = ((rtld_phdr[cnt].p_flags & PF_R) ? PROT_READ : 0)|
  456. + ((rtld_phdr[cnt].p_flags & PF_W) ? PROT_WRITE : 0)|
  457. + ((rtld_phdr[cnt].p_flags & PF_X) ? PROT_EXEC : 0);
  458. + __mmap ((void *) mapstart, mapend - mapstart,
  459. + prot,
  460. + MAP_ANON|MAP_PRIVATE|MAP_FIXED|0x20000000,
  461. + -1, 0);
  462. + }
  463. +#endif
  464. + }
  465. +
  466. /* Add the dynamic linker to the TLS list if it also uses TLS. */
  467. if (GL(dl_rtld_map).l_tls_blocksize != 0)
  468. /* Assign a module ID. Do this before loading any audit modules. */
  469. @@ -1636,89 +1654,6 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
  470. }
  471. }
  472. - /* There usually is no ld.so.preload file, it should only be used
  473. - for emergencies and testing. So the open call etc should usually
  474. - fail. Using access() on a non-existing file is faster than using
  475. - open(). So we do this first. If it succeeds we do almost twice
  476. - the work but this does not matter, since it is not for production
  477. - use. */
  478. - static const char preload_file[] = "/etc/ld.so.preload";
  479. - if (__builtin_expect (__access (preload_file, R_OK) == 0, 0))
  480. - {
  481. - /* Read the contents of the file. */
  482. - file = _dl_sysdep_read_whole_file (preload_file, &file_size,
  483. - PROT_READ | PROT_WRITE);
  484. - if (__builtin_expect (file != MAP_FAILED, 0))
  485. - {
  486. - /* Parse the file. It contains names of libraries to be loaded,
  487. - separated by white spaces or `:'. It may also contain
  488. - comments introduced by `#'. */
  489. - char *problem;
  490. - char *runp;
  491. - size_t rest;
  492. -
  493. - /* Eliminate comments. */
  494. - runp = file;
  495. - rest = file_size;
  496. - while (rest > 0)
  497. - {
  498. - char *comment = memchr (runp, '#', rest);
  499. - if (comment == NULL)
  500. - break;
  501. -
  502. - rest -= comment - runp;
  503. - do
  504. - *comment = ' ';
  505. - while (--rest > 0 && *++comment != '\n');
  506. - }
  507. -
  508. - /* We have one problematic case: if we have a name at the end of
  509. - the file without a trailing terminating characters, we cannot
  510. - place the \0. Handle the case separately. */
  511. - if (file[file_size - 1] != ' ' && file[file_size - 1] != '\t'
  512. - && file[file_size - 1] != '\n' && file[file_size - 1] != ':')
  513. - {
  514. - problem = &file[file_size];
  515. - while (problem > file && problem[-1] != ' '
  516. - && problem[-1] != '\t'
  517. - && problem[-1] != '\n' && problem[-1] != ':')
  518. - --problem;
  519. -
  520. - if (problem > file)
  521. - problem[-1] = '\0';
  522. - }
  523. - else
  524. - {
  525. - problem = NULL;
  526. - file[file_size - 1] = '\0';
  527. - }
  528. -
  529. - HP_TIMING_NOW (start);
  530. -
  531. - if (file != problem)
  532. - {
  533. - char *p;
  534. - runp = file;
  535. - while ((p = strsep (&runp, ": \t\n")) != NULL)
  536. - if (p[0] != '\0')
  537. - npreloads += do_preload (p, main_map, preload_file);
  538. - }
  539. -
  540. - if (problem != NULL)
  541. - {
  542. - char *p = strndupa (problem, file_size - (problem - file));
  543. -
  544. - npreloads += do_preload (p, main_map, preload_file);
  545. - }
  546. -
  547. - HP_TIMING_NOW (stop);
  548. - HP_TIMING_DIFF (diff, start, stop);
  549. - HP_TIMING_ACCUM_NT (load_time, diff);
  550. -
  551. - /* We don't need the file anymore. */
  552. - __munmap (file, file_size);
  553. - }
  554. - }
  555. if (__builtin_expect (*first_preload != NULL, 0))
  556. {
  557. diff --git a/malloc/arena.c b/malloc/arena.c
  558. index 5088a25..33a3879 100644
  559. --- a/malloc/arena.c
  560. +++ b/malloc/arena.c
  561. @@ -21,6 +21,27 @@
  562. /* Compile-time constants. */
  563. +#ifndef HEAP_MAX_SIZE
  564. +# ifdef DEFAULT_MMAP_THRESHOLD_MAX
  565. +# define DEFAULT_HEAP_MAX_SIZE (2 * DEFAULT_MMAP_THRESHOLD_MAX)
  566. +# else
  567. +# define DEFAULT_HEAP_MAX_SIZE (1024 * 1024) /* must be a power of two */
  568. +# endif
  569. +# include <sysdep.h>
  570. +static long int heap_max_size = 0;
  571. +# define HEAP_MAX_SIZE \
  572. + ({ \
  573. + if (!heap_max_size) { \
  574. + long int size = glibc_option("heap_size"); \
  575. + if (size > 0) \
  576. + heap_max_size = size; \
  577. + else \
  578. + heap_max_size = DEFAULT_HEAP_MAX_SIZE; \
  579. + } \
  580. + heap_max_size; \
  581. + })
  582. +#endif
  583. +
  584. #define HEAP_MIN_SIZE (32 * 1024)
  585. #ifndef HEAP_MAX_SIZE
  586. # ifdef DEFAULT_MMAP_THRESHOLD_MAX
  587. @@ -545,17 +566,6 @@ new_heap (size_t size, size_t top_pad)
  588. mapping (on Linux, this is the case for all non-writable mappings
  589. anyway). */
  590. p2 = MAP_FAILED;
  591. - if (aligned_heap_area)
  592. - {
  593. - p2 = (char *) MMAP (aligned_heap_area, HEAP_MAX_SIZE, PROT_NONE,
  594. - MAP_NORESERVE);
  595. - aligned_heap_area = NULL;
  596. - if (p2 != MAP_FAILED && ((unsigned long) p2 & (HEAP_MAX_SIZE - 1)))
  597. - {
  598. - __munmap (p2, HEAP_MAX_SIZE);
  599. - p2 = MAP_FAILED;
  600. - }
  601. - }
  602. if (p2 == MAP_FAILED)
  603. {
  604. p1 = (char *) MMAP (0, HEAP_MAX_SIZE << 1, PROT_NONE, MAP_NORESERVE);
  605. @@ -566,8 +576,6 @@ new_heap (size_t size, size_t top_pad)
  606. ul = p2 - p1;
  607. if (ul)
  608. __munmap (p1, ul);
  609. - else
  610. - aligned_heap_area = p2 + HEAP_MAX_SIZE;
  611. __munmap (p2 + HEAP_MAX_SIZE, HEAP_MAX_SIZE - ul);
  612. }
  613. else
  614. diff --git a/nptl/Makefile b/nptl/Makefile
  615. index 57cc8c6..81f1bf4 100644
  616. --- a/nptl/Makefile
  617. +++ b/nptl/Makefile
  618. @@ -20,7 +20,7 @@
  619. #
  620. subdir := nptl
  621. -headers := pthread.h semaphore.h bits/semaphore.h
  622. +headers := pthread.h semaphore.h bits/semaphore.h syscalldb.h
  623. extra-libs := libpthread
  624. extra-libs-others := $(extra-libs)
  625. diff --git a/nptl/Versions b/nptl/Versions
  626. index bb11277..354149a 100644
  627. --- a/nptl/Versions
  628. +++ b/nptl/Versions
  629. @@ -31,6 +31,9 @@ libc {
  630. # Internal libc interface to libpthread
  631. __libc_dl_error_tsd;
  632. }
  633. + SHIM {
  634. + syscalldb; glibc_option;
  635. + }
  636. }
  637. libpthread {
  638. @@ -262,4 +265,8 @@ libpthread {
  639. __pthread_clock_gettime; __pthread_clock_settime;
  640. __pthread_unwind; __pthread_get_minstack;
  641. }
  642. +
  643. + SHIM {
  644. + syscalldb; glibc_option;
  645. + }
  646. }
  647. diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
  648. index 9d7f52f..72d50ae 100644
  649. --- a/nptl/pthread_create.c
  650. +++ b/nptl/pthread_create.c
  651. @@ -405,8 +405,11 @@ start_thread (void *arg)
  652. # error "to do"
  653. #endif
  654. assert (freesize < pd->stackblock_size);
  655. + /* XXX: may not be necessary */
  656. +#if 0
  657. if (freesize > PTHREAD_STACK_MIN)
  658. __madvise (pd->stackblock, freesize - PTHREAD_STACK_MIN, MADV_DONTNEED);
  659. +#endif
  660. /* If the thread is detached free the TCB. */
  661. if (IS_DETACHED (pd))
  662. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S b/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S
  663. index 89fda5e..f6963f6 100644
  664. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S
  665. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S
  666. @@ -111,7 +111,8 @@ ENTRY(__pthread_disable_asynccancel)
  667. xorq %r10, %r10
  668. addq $CANCELHANDLING, %rdi
  669. LOAD_PRIVATE_FUTEX_WAIT (%esi)
  670. - syscall
  671. + SYSCALLDB
  672. +
  673. movl %fs:CANCELHANDLING, %eax
  674. jmp 3b
  675. END(__pthread_disable_asynccancel)
  676. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
  677. index f2dca07..0ce7c67 100644
  678. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
  679. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
  680. @@ -90,7 +90,7 @@ __lll_lock_wait_private:
  681. 1: LIBC_PROBE (lll_lock_wait_private, 1, %rdi)
  682. movl $SYS_futex, %eax
  683. - syscall
  684. + SYSCALLDB
  685. 2: movl %edx, %eax
  686. xchgl %eax, (%rdi) /* NB: lock is implied */
  687. @@ -130,7 +130,7 @@ __lll_lock_wait:
  688. 1: LIBC_PROBE (lll_lock_wait, 2, %rdi, %rsi)
  689. movl $SYS_futex, %eax
  690. - syscall
  691. + SYSCALLDB
  692. 2: movl %edx, %eax
  693. xchgl %eax, (%rdi) /* NB: lock is implied */
  694. @@ -185,7 +185,7 @@ __lll_timedlock_wait:
  695. 1: movl $SYS_futex, %eax
  696. movl $2, %edx
  697. - syscall
  698. + SYSCALLDB
  699. 2: xchgl %edx, (%rdi) /* NB: lock is implied */
  700. @@ -279,7 +279,7 @@ __lll_timedlock_wait:
  701. LOAD_FUTEX_WAIT (%esi)
  702. movq %r12, %rdi
  703. movl $SYS_futex, %eax
  704. - syscall
  705. + SYSCALLDB
  706. /* NB: %edx == 2 */
  707. xchgl %edx, (%r12)
  708. @@ -336,7 +336,7 @@ __lll_unlock_wake_private:
  709. LOAD_PRIVATE_FUTEX_WAKE (%esi)
  710. movl $1, %edx /* Wake one thread. */
  711. movl $SYS_futex, %eax
  712. - syscall
  713. + SYSCALLDB
  714. popq %rdx
  715. cfi_adjust_cfa_offset(-8)
  716. @@ -366,7 +366,7 @@ __lll_unlock_wake:
  717. LOAD_FUTEX_WAKE (%esi)
  718. movl $1, %edx /* Wake one thread. */
  719. movl $SYS_futex, %eax
  720. - syscall
  721. + SYSCALLDB
  722. popq %rdx
  723. cfi_adjust_cfa_offset(-8)
  724. @@ -435,7 +435,7 @@ __lll_timedwait_tid:
  725. #endif
  726. movq %r12, %rdi
  727. movl $SYS_futex, %eax
  728. - syscall
  729. + SYSCALLDB
  730. cmpl $0, (%rdi)
  731. jne 1f
  732. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
  733. index 0a26739..8aae14a 100644
  734. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
  735. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
  736. @@ -214,7 +214,7 @@ LLL_STUB_UNWIND_INFO_END
  737. register const struct timespec *__to __asm ("r10") = timeout; \
  738. int __status; \
  739. register __typeof (val) _val __asm ("edx") = (val); \
  740. - __asm __volatile ("syscall" \
  741. + __asm __volatile (SYSCALLDB \
  742. : "=a" (__status) \
  743. : "0" (SYS_futex), "D" (futex), \
  744. "S" (__lll_private_flag (FUTEX_WAIT, private)), \
  745. @@ -229,7 +229,7 @@ LLL_STUB_UNWIND_INFO_END
  746. int __status; \
  747. register __typeof (nr) _nr __asm ("edx") = (nr); \
  748. LIBC_PROBE (lll_futex_wake, 3, futex, nr, private); \
  749. - __asm __volatile ("syscall" \
  750. + __asm __volatile (SYSCALLDB \
  751. : "=a" (__status) \
  752. : "0" (SYS_futex), "D" (futex), \
  753. "S" (__lll_private_flag (FUTEX_WAKE, private)), \
  754. @@ -540,7 +540,7 @@ extern int __lll_timedlock_elision (int *futex, short *adapt_count,
  755. { \
  756. int ignore; \
  757. __asm __volatile (LOCK_INSTR "orl %3, (%2)\n\t" \
  758. - "syscall" \
  759. + SYSCALLDB \
  760. : "=m" (futex), "=a" (ignore) \
  761. : "D" (&(futex)), "i" (FUTEX_OWNER_DIED), \
  762. "S" (__lll_private_flag (FUTEX_WAKE, private)), \
  763. @@ -555,7 +555,7 @@ extern int __lll_timedlock_elision (int *futex, short *adapt_count,
  764. register int __nr_move __asm ("r10") = nr_move; \
  765. register void *__mutex __asm ("r8") = mutex; \
  766. register int __val __asm ("r9") = val; \
  767. - __asm __volatile ("syscall" \
  768. + __asm __volatile (SYSCALLDB \
  769. : "=a" (__res) \
  770. : "0" (__NR_futex), "D" ((void *) ftx), \
  771. "S" (__lll_private_flag (FUTEX_CMP_REQUEUE, \
  772. @@ -581,7 +581,7 @@ extern int __lll_timedlock_elision (int *futex, short *adapt_count,
  773. if (_tid != 0) \
  774. __asm __volatile ("xorq %%r10, %%r10\n\t" \
  775. "1:\tmovq %2, %%rax\n\t" \
  776. - "syscall\n\t" \
  777. + SYSCALLDB \
  778. "cmpl $0, (%%rdi)\n\t" \
  779. "jne 1b" \
  780. : "=&a" (__ignore) \
  781. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
  782. index 990b6f9..b01214d 100644
  783. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
  784. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
  785. @@ -80,7 +80,7 @@ __lll_robust_lock_wait:
  786. jnz 2f
  787. 1: movl $SYS_futex, %eax
  788. - syscall
  789. + SYSCALLDB
  790. movl (%rdi), %eax
  791. @@ -145,7 +145,7 @@ __lll_robust_timedlock_wait:
  792. jnz 6f
  793. 5: movl $SYS_futex, %eax
  794. - syscall
  795. + SYSCALLDB
  796. movl %eax, %ecx
  797. movl (%rdi), %eax
  798. @@ -257,7 +257,7 @@ __lll_robust_timedlock_wait:
  799. LOAD_FUTEX_WAIT (%esi)
  800. movq %r12, %rdi
  801. movl $SYS_futex, %eax
  802. - syscall
  803. + SYSCALLDB
  804. movq %rax, %rcx
  805. movl (%r12), %eax
  806. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S
  807. index eec17f2..a350340 100644
  808. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S
  809. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S
  810. @@ -62,7 +62,7 @@ pthread_barrier_wait:
  811. #endif
  812. xorq %r10, %r10
  813. 8: movl $SYS_futex, %eax
  814. - syscall
  815. + SYSCALLDB
  816. /* Don't return on spurious wakeups. The syscall does not change
  817. any register except %eax so there is no need to reload any of
  818. @@ -109,7 +109,7 @@ pthread_barrier_wait:
  819. movl $FUTEX_WAKE, %esi
  820. orl PRIVATE(%rdi), %esi
  821. movl $SYS_futex, %eax
  822. - syscall
  823. + SYSCALLDB
  824. /* Increment LEFT. If this brings the count back to the
  825. initial count unlock the object. */
  826. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
  827. index 985e0f1..d559456 100644
  828. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
  829. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
  830. @@ -90,7 +90,7 @@ __pthread_cond_broadcast:
  831. movl $SYS_futex, %eax
  832. movl $1, %edx
  833. movl $0x7fffffff, %r10d
  834. - syscall
  835. + SYSCALLDB
  836. /* For any kind of error, which mainly is EAGAIN, we try again
  837. with WAKE. The general test also covers running on old
  838. @@ -106,7 +106,7 @@ __pthread_cond_broadcast:
  839. movl $SYS_futex, %eax
  840. movl $1, %edx
  841. movl $0x7fffffff, %r10d
  842. - syscall
  843. + SYSCALLDB
  844. /* For any kind of error, which mainly is EAGAIN, we try again
  845. with WAKE. The general test also covers running on old
  846. @@ -172,7 +172,7 @@ __pthread_cond_broadcast:
  847. orl $FUTEX_WAKE, %esi
  848. #endif
  849. movl $SYS_futex, %eax
  850. - syscall
  851. + SYSCALLDB
  852. jmp 10b
  853. .size __pthread_cond_broadcast, .-__pthread_cond_broadcast
  854. versioned_symbol (libpthread, __pthread_cond_broadcast, pthread_cond_broadcast,
  855. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
  856. index 53d65b6..16df581 100644
  857. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
  858. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
  859. @@ -82,7 +82,7 @@ __pthread_cond_signal:
  860. addq $cond_lock, %r8
  861. #endif
  862. movl $FUTEX_OP_CLEAR_WAKE_IF_GT_ONE, %r9d
  863. - syscall
  864. + SYSCALLDB
  865. #if cond_lock != 0
  866. subq $cond_lock, %r8
  867. #endif
  868. @@ -99,7 +99,7 @@ __pthread_cond_signal:
  869. movq %rcx, %r8
  870. xorq %r10, %r10
  871. movl (%rdi), %r9d // XXX Can this be right?
  872. - syscall
  873. + SYSCALLDB
  874. leaq -cond_futex(%rdi), %r8
  875. @@ -118,7 +118,7 @@ __pthread_cond_signal:
  876. movl $SYS_futex, %eax
  877. /* %rdx should be 1 already from $FUTEX_WAKE_OP syscall.
  878. movl $1, %edx */
  879. - syscall
  880. + SYSCALLDB
  881. /* Unlock. */
  882. 4: LOCK
  883. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
  884. index 0dc2340..8aff242 100644
  885. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
  886. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
  887. @@ -188,7 +188,7 @@ __pthread_cond_timedwait:
  888. movq %r12, %rdx
  889. addq $cond_futex, %rdi
  890. movl $SYS_futex, %eax
  891. - syscall
  892. + SYSCALLDB
  893. cmpl $0, %eax
  894. sete %r15b
  895. @@ -234,7 +234,7 @@ __pthread_cond_timedwait:
  896. movq %r12, %rdx
  897. addq $cond_futex, %rdi
  898. movl $SYS_futex, %eax
  899. - syscall
  900. + SYSCALLDB
  901. 62: movq %rax, %r14
  902. movl (%rsp), %edi
  903. @@ -321,7 +321,7 @@ __pthread_cond_timedwait:
  904. orl $FUTEX_WAKE, %esi
  905. #endif
  906. movl $SYS_futex, %eax
  907. - syscall
  908. + SYSCALLDB
  909. subq $cond_nwaiters, %rdi
  910. 55: LOCK
  911. @@ -485,15 +485,8 @@ __pthread_cond_timedwait:
  912. /* Only clocks 0 and 1 are allowed so far. Both are handled in the
  913. kernel. */
  914. leaq 32(%rsp), %rsi
  915. -# ifdef SHARED
  916. - mov __vdso_clock_gettime@GOTPCREL(%rip), %RAX_LP
  917. - mov (%rax), %RAX_LP
  918. - PTR_DEMANGLE (%RAX_LP)
  919. - call *%rax
  920. -# else
  921. movl $__NR_clock_gettime, %eax
  922. - syscall
  923. -# endif
  924. + SYSCALLDB
  925. /* Compute relative timeout. */
  926. movq (%r13), %rcx
  927. @@ -560,7 +553,7 @@ __pthread_cond_timedwait:
  928. # endif
  929. addq $cond_futex, %rdi
  930. movl $SYS_futex, %eax
  931. - syscall
  932. + SYSCALLDB
  933. movq %rax, %r14
  934. movl (%rsp), %edi
  935. @@ -732,7 +725,7 @@ __condvar_cleanup2:
  936. orl $FUTEX_WAKE, %esi
  937. #endif
  938. movl $SYS_futex, %eax
  939. - syscall
  940. + SYSCALLDB
  941. subq $cond_nwaiters, %rdi
  942. movl $1, %r12d
  943. @@ -769,7 +762,7 @@ __condvar_cleanup2:
  944. orl $FUTEX_WAKE, %esi
  945. #endif
  946. movl $SYS_futex, %eax
  947. - syscall
  948. + SYSCALLDB
  949. /* Lock the mutex only if we don't own it already. This only happens
  950. in case of PI mutexes, if we got cancelled after a successful
  951. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
  952. index 0e61d0a..b4bcc15 100644
  953. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
  954. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
  955. @@ -138,7 +138,7 @@ __pthread_cond_wait:
  956. movl $(FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %esi
  957. movl $SYS_futex, %eax
  958. - syscall
  959. + SYSCALLDB
  960. cmpl $0, %eax
  961. sete %r8b
  962. @@ -180,7 +180,7 @@ __pthread_cond_wait:
  963. #endif
  964. 60: xorb %r8b, %r8b
  965. movl $SYS_futex, %eax
  966. - syscall
  967. + SYSCALLDB
  968. 62: movl (%rsp), %edi
  969. callq __pthread_disable_asynccancel
  970. @@ -239,7 +239,7 @@ __pthread_cond_wait:
  971. orl $FUTEX_WAKE, %esi
  972. #endif
  973. movl $SYS_futex, %eax
  974. - syscall
  975. + SYSCALLDB
  976. subq $cond_nwaiters, %rdi
  977. 17: LOCK
  978. @@ -455,7 +455,7 @@ __condvar_cleanup1:
  979. orl $FUTEX_WAKE, %esi
  980. #endif
  981. movl $SYS_futex, %eax
  982. - syscall
  983. + SYSCALLDB
  984. subq $cond_nwaiters, %rdi
  985. movl $1, %ecx
  986. @@ -493,7 +493,7 @@ __condvar_cleanup1:
  987. orl $FUTEX_WAKE, %esi
  988. #endif
  989. movl $SYS_futex, %eax
  990. - syscall
  991. + SYSCALLDB
  992. /* Lock the mutex only if we don't own it already. This only happens
  993. in case of PI mutexes, if we got cancelled after a successful
  994. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
  995. index 2cbe2fa..489998a 100644
  996. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
  997. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
  998. @@ -90,7 +90,7 @@ __pthread_once:
  999. # endif
  1000. #endif
  1001. movl $SYS_futex, %eax
  1002. - syscall
  1003. + SYSCALLDB
  1004. jmp 6b
  1005. /* Preserve the pointer to the control variable. */
  1006. @@ -123,7 +123,7 @@ __pthread_once:
  1007. orl %fs:PRIVATE_FUTEX, %esi
  1008. #endif
  1009. movl $SYS_futex, %eax
  1010. - syscall
  1011. + SYSCALLDB
  1012. 4: addq $8, %rsp
  1013. cfi_adjust_cfa_offset(-8)
  1014. @@ -152,7 +152,7 @@ clear_once_control:
  1015. orl %fs:PRIVATE_FUTEX, %esi
  1016. #endif
  1017. movl $SYS_futex, %eax
  1018. - syscall
  1019. + SYSCALLDB
  1020. movq %r8, %rdi
  1021. .LcallUR:
  1022. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S
  1023. index 3bbb4c7..53d5ca6 100644
  1024. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S
  1025. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S
  1026. @@ -82,7 +82,7 @@ __pthread_rwlock_rdlock:
  1027. #endif
  1028. addq $READERS_WAKEUP, %rdi
  1029. movl $SYS_futex, %eax
  1030. - syscall
  1031. + SYSCALLDB
  1032. subq $READERS_WAKEUP, %rdi
  1033. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
  1034. index 40bcc04..348170e 100644
  1035. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
  1036. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
  1037. @@ -109,7 +109,7 @@ pthread_rwlock_timedrdlock:
  1038. #endif
  1039. 21: leaq READERS_WAKEUP(%r12), %rdi
  1040. movl $SYS_futex, %eax
  1041. - syscall
  1042. + SYSCALLDB
  1043. movq %rax, %rdx
  1044. #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
  1045. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
  1046. index f57ef52..e9ac77f 100644
  1047. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
  1048. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
  1049. @@ -106,7 +106,7 @@ pthread_rwlock_timedwrlock:
  1050. #endif
  1051. 21: leaq WRITERS_WAKEUP(%r12), %rdi
  1052. movl $SYS_futex, %eax
  1053. - syscall
  1054. + SYSCALLDB
  1055. movq %rax, %rdx
  1056. #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
  1057. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S
  1058. index d779f7b..849c74f 100644
  1059. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S
  1060. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S
  1061. @@ -79,7 +79,7 @@ __pthread_rwlock_unlock:
  1062. #endif
  1063. movl $SYS_futex, %eax
  1064. movq %r10, %rdi
  1065. - syscall
  1066. + SYSCALLDB
  1067. xorl %eax, %eax
  1068. retq
  1069. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S
  1070. index e444def..fd94930 100644
  1071. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S
  1072. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S
  1073. @@ -80,7 +80,7 @@ __pthread_rwlock_wrlock:
  1074. #endif
  1075. addq $WRITERS_WAKEUP, %rdi
  1076. movl $SYS_futex, %eax
  1077. - syscall
  1078. + SYSCALLDB
  1079. subq $WRITERS_WAKEUP, %rdi
  1080. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
  1081. index 1c11600..bd166cf 100644
  1082. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
  1083. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
  1084. @@ -52,7 +52,7 @@ sem_post:
  1085. movl $FUTEX_WAKE, %esi
  1086. orl PRIVATE(%rdi), %esi
  1087. movl $1, %edx
  1088. - syscall
  1089. + SYSCALLDB
  1090. testq %rax, %rax
  1091. js 1f
  1092. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
  1093. index 880610e..e520049 100644
  1094. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
  1095. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
  1096. @@ -97,7 +97,7 @@ sem_timedwait:
  1097. orl PRIVATE(%rdi), %esi
  1098. movl $SYS_futex, %eax
  1099. xorl %edx, %edx
  1100. - syscall
  1101. + SYSCALLDB
  1102. movq %rax, %r9
  1103. #if VALUE != 0
  1104. leaq -VALUE(%rdi), %rdi
  1105. @@ -233,7 +233,7 @@ sem_timedwait:
  1106. # endif
  1107. movl $SYS_futex, %eax
  1108. xorl %edx, %edx
  1109. - syscall
  1110. + SYSCALLDB
  1111. movq %rax, %r14
  1112. movl 16(%rsp), %edi
  1113. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
  1114. index 8f4d068..fe6dfbf 100644
  1115. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
  1116. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
  1117. @@ -81,7 +81,7 @@ sem_wait:
  1118. orl PRIVATE(%rdi), %esi
  1119. #endif
  1120. xorl %edx, %edx
  1121. - syscall
  1122. + SYSCALLDB
  1123. movq %rax, %rcx
  1124. xchgq %r8, %rdi
  1125. diff --git a/nptl/sysdeps/x86_64/pthreaddef.h b/nptl/sysdeps/x86_64/pthreaddef.h
  1126. index 18a15a1..f050241 100644
  1127. --- a/nptl/sysdeps/x86_64/pthreaddef.h
  1128. +++ b/nptl/sysdeps/x86_64/pthreaddef.h
  1129. @@ -48,4 +48,4 @@
  1130. /* While there is no such syscall. */
  1131. #define __exit_thread_inline(val) \
  1132. - asm volatile ("syscall" :: "a" (__NR_exit), "D" (val))
  1133. + asm volatile (SYSCALLDB :: "a" (__NR_exit), "D" (val))
  1134. diff --git a/nptl/sysdeps/x86_64/tls.h b/nptl/sysdeps/x86_64/tls.h
  1135. index cbb5e9e..9b87e25 100644
  1136. --- a/nptl/sysdeps/x86_64/tls.h
  1137. +++ b/nptl/sysdeps/x86_64/tls.h
  1138. @@ -28,6 +28,8 @@
  1139. # include <sysdep.h>
  1140. # include <libc-internal.h>
  1141. # include <kernel-features.h>
  1142. +# include <shim_tls.h>
  1143. +# include <syscalldb.h>
  1144. /* Replacement type for __m128 since this file is included by ld.so,
  1145. which is compiled with -mno-sse. It must not change the alignment
  1146. @@ -67,6 +69,10 @@ typedef struct
  1147. # else
  1148. int __glibc_reserved1;
  1149. # endif
  1150. +
  1151. + shim_tcb_t shim_tcb; /* For graphene, we allocate a shim_tcb
  1152. + in the real tcb. */
  1153. +
  1154. int rtld_must_xmm_save;
  1155. /* Reservation of some values for the TM ABI. */
  1156. void *__private_tm[4];
  1157. @@ -137,7 +143,6 @@ typedef struct
  1158. # define GET_DTV(descr) \
  1159. (((tcbhead_t *) (descr))->dtv)
  1160. -
  1161. /* Code to initially initialize the thread pointer. This might need
  1162. special attention since 'errno' is not yet available and if the
  1163. operation can cause a failure 'errno' must not be touched.
  1164. @@ -154,7 +159,7 @@ typedef struct
  1165. _head->self = _thrdescr; \
  1166. \
  1167. /* It is a simple syscall to set the %fs value for the thread. */ \
  1168. - asm volatile ("syscall" \
  1169. + asm volatile (SYSCALLDB \
  1170. : "=a" (_result) \
  1171. : "0" ((unsigned long int) __NR_arch_prctl), \
  1172. "D" ((unsigned long int) ARCH_SET_FS), \
  1173. diff --git a/scripts/mkinstalldirs b/scripts/mkinstalldirs
  1174. index 55d537f..57bf12b 100755
  1175. --- a/scripts/mkinstalldirs
  1176. +++ b/scripts/mkinstalldirs
  1177. @@ -126,9 +126,9 @@ do
  1178. esac
  1179. if test ! -d "$pathcomp"; then
  1180. - echo "mkdir $pathcomp"
  1181. + echo "mkdir -p $pathcomp"
  1182. - mkdir "$pathcomp" || lasterr=$?
  1183. + mkdir -p "$pathcomp" || lasterr=$?
  1184. if test ! -d "$pathcomp"; then
  1185. errstatus=$lasterr
  1186. diff --git a/shlib-versions b/shlib-versions
  1187. index 78b0ad7..5c3dcf2 100644
  1188. --- a/shlib-versions
  1189. +++ b/shlib-versions
  1190. @@ -108,3 +108,5 @@ sparc64.*-.*-.* libBrokenLocale=1 GLIBC_2.2
  1191. # This defines the libgcc soname version this glibc is to load for
  1192. # asynchronous cancellation to work correctly.
  1193. .*-.*-.* libgcc_s=1
  1194. +
  1195. +.*-.*-.* liblibos=1
  1196. diff --git a/sysdeps/unix/sysv/linux/_exit.c b/sysdeps/unix/sysv/linux/_exit.c
  1197. index 2468228..a9f1cd6 100644
  1198. --- a/sysdeps/unix/sysv/linux/_exit.c
  1199. +++ b/sysdeps/unix/sysv/linux/_exit.c
  1200. @@ -29,9 +29,9 @@ _exit (status)
  1201. while (1)
  1202. {
  1203. #ifdef __NR_exit_group
  1204. - INLINE_SYSCALL (exit_group, 1, status);
  1205. + INLINE_SYSCALL_ASM (exit_group, 1, status);
  1206. #endif
  1207. - INLINE_SYSCALL (exit, 1, status);
  1208. + INLINE_SYSCALL_ASM (exit, 1, status);
  1209. #ifdef ABORT_INSTRUCTION
  1210. ABORT_INSTRUCTION;
  1211. diff --git a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
  1212. index 49f0384..6b1a975 100644
  1213. --- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
  1214. +++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
  1215. @@ -84,7 +84,8 @@ ENTRY(____longjmp_chk)
  1216. xorl %edi, %edi
  1217. lea -sizeSS(%rsp), %RSI_LP
  1218. movl $__NR_sigaltstack, %eax
  1219. - syscall
  1220. + SYSCALLDB
  1221. +
  1222. /* Without working sigaltstack we cannot perform the test. */
  1223. testl %eax, %eax
  1224. jne .Lok2
  1225. diff --git a/sysdeps/unix/sysv/linux/x86_64/clock_gettime.c b/sysdeps/unix/sysv/linux/x86_64/clock_gettime.c
  1226. index f712110..f6bad14 100644
  1227. --- a/sysdeps/unix/sysv/linux/x86_64/clock_gettime.c
  1228. +++ b/sysdeps/unix/sysv/linux/x86_64/clock_gettime.c
  1229. @@ -1,5 +1,6 @@
  1230. #include "bits/libc-vdso.h"
  1231. +#if 0 /* in Graphene, disallow VDSO calls */
  1232. #ifdef SHARED
  1233. # define SYSCALL_GETTIME(id, tp) \
  1234. ({ long int (*f) (clockid_t, struct timespec *) = __vdso_clock_gettime; \
  1235. @@ -16,5 +17,6 @@
  1236. PTR_DEMANGLE (f); \
  1237. f (id, tp); })
  1238. #endif
  1239. +#endif
  1240. #include "../clock_gettime.c"
  1241. diff --git a/sysdeps/unix/sysv/linux/x86_64/clone.S b/sysdeps/unix/sysv/linux/x86_64/clone.S
  1242. index 0508730..e1b35ec 100644
  1243. --- a/sysdeps/unix/sysv/linux/x86_64/clone.S
  1244. +++ b/sysdeps/unix/sysv/linux/x86_64/clone.S
  1245. @@ -76,5 +80,5 @@ ENTRY (__clone)
  1246. /* End FDE now, because in the child the unwind info will be
  1247. wrong. */
  1248. cfi_endproc;
  1249. - syscall
  1250. + SYSCALLDB
  1251. @@ -99,10 +104,10 @@ L(thread_start):
  1252. movl $-1, %eax
  1253. jne 2f
  1254. movl $SYS_ify(getpid), %eax
  1255. - syscall
  1256. + SYSCALLDB
  1257. 2: movl %eax, %fs:PID
  1258. movl %eax, %fs:TID
  1259. 1:
  1260. #endif
  1261. /* Set up arguments for the function call. */
  1262. diff --git a/sysdeps/unix/sysv/linux/x86_64/getcontext.S b/sysdeps/unix/sysv/linux/x86_64/getcontext.S
  1263. index 140db03..6967f10 100644
  1264. --- a/sysdeps/unix/sysv/linux/x86_64/getcontext.S
  1265. +++ b/sysdeps/unix/sysv/linux/x86_64/getcontext.S
  1266. @@ -75,7 +75,7 @@ ENTRY(__getcontext)
  1267. #endif
  1268. movl $_NSIG8,%r10d
  1269. movl $__NR_rt_sigprocmask, %eax
  1270. - syscall
  1271. + SYSCALLDB
  1272. cmpq $-4095, %rax /* Check %rax for error. */
  1273. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  1274. diff --git a/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c b/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c
  1275. index 440ca7f..571125d 100644
  1276. --- a/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c
  1277. +++ b/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c
  1278. @@ -17,6 +17,7 @@
  1279. #include <sys/time.h>
  1280. +#if 0 /* In graphene, do not use vsyscall or VDSO call */
  1281. #ifdef SHARED
  1282. # include <dl-vdso.h>
  1283. @@ -42,7 +43,8 @@ asm (".type __gettimeofday, %gnu_indirect_function");
  1284. asm (".globl __GI___gettimeofday\n"
  1285. "__GI___gettimeofday = __gettimeofday");
  1286. -#else
  1287. +#endif
  1288. +#endif
  1289. # include <sysdep.h>
  1290. # include <errno.h>
  1291. @@ -54,6 +56,5 @@ __gettimeofday (struct timeval *tv, struct timezone *tz)
  1292. }
  1293. libc_hidden_def (__gettimeofday)
  1294. -#endif
  1295. weak_alias (__gettimeofday, gettimeofday)
  1296. libc_hidden_weak (gettimeofday)
  1297. diff --git a/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S b/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
  1298. index 0fd47f2..7a82975 100644
  1299. --- a/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
  1300. +++ b/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
  1301. @@ -30,6 +30,7 @@ ENTRY (sched_getcpu)
  1302. sub $0x8, %rsp
  1303. cfi_adjust_cfa_offset(8)
  1304. +#if 0 /* for Graphene, never do VDSO calls */
  1305. movq %rsp, %rdi
  1306. xorl %esi, %esi
  1307. movl $VGETCPU_CACHE_OFFSET, %edx
  1308. @@ -39,16 +40,19 @@ ENTRY (sched_getcpu)
  1309. movq __vdso_getcpu(%rip), %rax
  1310. PTR_DEMANGLE (%rax)
  1311. callq *%rax
  1312. -#else
  1313. -# ifdef __NR_getcpu
  1314. +#endif
  1315. +#endif
  1316. +
  1317. +#ifdef __NR_getcpu
  1318. movl $__NR_getcpu, %eax
  1319. - syscall
  1320. -# ifndef __ASSUME_GETCPU_SYSCALL
  1321. + SYSCALLDB
  1322. +#endif
  1323. +
  1324. +#if 0 /* for Graphene, never do vsyscall */
  1325. +# ifndef __ASSUME_GETCPU_SYSCALL
  1326. cmpq $-ENOSYS, %rax
  1327. jne 1f
  1328. -# endif
  1329. -# endif
  1330. -# ifndef __ASSUME_GETCPU_SYSCALL
  1331. +
  1332. movq $VSYSCALL_ADDR_vgetcpu, %rax
  1333. callq *%rax
  1334. 1:
  1335. diff --git a/sysdeps/unix/sysv/linux/x86_64/setcontext.S b/sysdeps/unix/sysv/linux/x86_64/setcontext.S
  1336. index b726fa0..bb3ae34 100644
  1337. --- a/sysdeps/unix/sysv/linux/x86_64/setcontext.S
  1338. +++ b/sysdeps/unix/sysv/linux/x86_64/setcontext.S
  1339. @@ -43,7 +43,7 @@ ENTRY(__setcontext)
  1340. movl $SIG_SETMASK, %edi
  1341. movl $_NSIG8,%r10d
  1342. movl $__NR_rt_sigprocmask, %eax
  1343. - syscall
  1344. + SYSCALLDB
  1345. popq %rdi /* Reload %rdi, adjust stack. */
  1346. cfi_adjust_cfa_offset(-8)
  1347. cmpq $-4095, %rax /* Check %rax for error. */
  1348. diff --git a/sysdeps/unix/sysv/linux/x86_64/sigaction.c b/sysdeps/unix/sysv/linux/x86_64/sigaction.c
  1349. index ab23985..38a6b69 100644
  1350. --- a/sysdeps/unix/sysv/linux/x86_64/sigaction.c
  1351. +++ b/sysdeps/unix/sysv/linux/x86_64/sigaction.c
  1352. @@ -129,7 +129,7 @@ asm \
  1353. " .type __" #name ",@function\n" \
  1354. "__" #name ":\n" \
  1355. " movq $" #syscall ", %rax\n" \
  1356. - " syscall\n" \
  1357. + SYSCALLDB_ASM \
  1358. ".LEND_" #name ":\n" \
  1359. ".section .eh_frame,\"a\",@progbits\n" \
  1360. ".LSTARTFRAME_" #name ":\n" \
  1361. diff --git a/sysdeps/unix/sysv/linux/x86_64/swapcontext.S b/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
  1362. index b3854fa..6369bfe 100644
  1363. --- a/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
  1364. +++ b/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
  1365. @@ -75,7 +75,7 @@ ENTRY(__swapcontext)
  1366. movl $SIG_SETMASK, %edi
  1367. movl $_NSIG8,%r10d
  1368. movl $__NR_rt_sigprocmask, %eax
  1369. - syscall
  1370. + SYSCALLDB
  1371. cmpq $-4095, %rax /* Check %rax for error. */
  1372. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  1373. diff --git a/sysdeps/unix/sysv/linux/x86_64/syscall.S b/sysdeps/unix/sysv/linux/x86_64/syscall.S
  1374. index 92c2f5b..e32ebb2 100644
  1375. --- a/sysdeps/unix/sysv/linux/x86_64/syscall.S
  1376. +++ b/sysdeps/unix/sysv/linux/x86_64/syscall.S
  1377. @@ -31,10 +31,12 @@
  1378. movq %rsi, %rdi /* shift arg1 - arg5. */
  1379. movq %rdx, %rsi
  1380. movq %rcx, %rdx
  1381. + /* DEP 8/17/17: Keep kernel calling
  1382. + * convention and fix in libOS */
  1383. movq %r8, %r10
  1384. movq %r9, %r8
  1385. movq 8(%rsp),%r9 /* arg6 is on the stack. */
  1386. - syscall /* Do the system call. */
  1387. + SYSCALLDB /* Do the system call. */
  1388. cmpq $-4095, %rax /* Check %rax for error. */
  1389. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  1390. ret /* Return to caller. */
  1391. diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
  1392. index 4a9a9d9..dc452ed 100644
  1393. --- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
  1394. +++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
  1395. @@ -21,6 +21,7 @@
  1396. /* There is some commonality. */
  1397. #include <sysdeps/unix/x86_64/sysdep.h>
  1398. #include <tls.h>
  1399. +#include "syscalldb.h"
  1400. #ifdef IS_IN_rtld
  1401. # include <dl-sysdep.h> /* Defines RTLD_PRIVATE_ERRNO. */
  1402. @@ -176,7 +177,7 @@
  1403. # define DO_CALL(syscall_name, args) \
  1404. DOARGS_##args \
  1405. movl $SYS_ify (syscall_name), %eax; \
  1406. - syscall;
  1407. + SYSCALLDB
  1408. # define DOARGS_0 /* nothing */
  1409. # define DOARGS_1 /* nothing */
  1410. @@ -190,9 +191,20 @@
  1411. /* Define a macro which expands inline into the wrapper code for a system
  1412. call. */
  1413. # undef INLINE_SYSCALL
  1414. -# define INLINE_SYSCALL(name, nr, args...) \
  1415. +# define INLINE_SYSCALL(name, nr_args...) \
  1416. ({ \
  1417. - unsigned long int resultvar = INTERNAL_SYSCALL (name, , nr, args); \
  1418. + unsigned long int resultvar = INTERNAL_SYSCALL (name, , ##nr_args); \
  1419. + if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0)) \
  1420. + { \
  1421. + __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
  1422. + resultvar = (unsigned long int) -1; \
  1423. + } \
  1424. + (long int) resultvar; })
  1425. +
  1426. +# undef INLINE_SYSCALL_ASM
  1427. +# define INLINE_SYSCALL_ASM(name, nr_args...) \
  1428. + ({ \
  1429. + unsigned long int resultvar = INTERNAL_SYSCALL_ASM (name, , ##nr_args); \
  1430. if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0)) \
  1431. { \
  1432. __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
  1433. @@ -204,9 +216,9 @@
  1434. into the wrapper code for a system call. It should be used when size
  1435. of any argument > size of long int. */
  1436. # undef INLINE_SYSCALL_TYPES
  1437. -# define INLINE_SYSCALL_TYPES(name, nr, args...) \
  1438. +# define INLINE_SYSCALL_TYPES(name, nr_args...) \
  1439. ({ \
  1440. - unsigned long int resultvar = INTERNAL_SYSCALL_TYPES (name, , nr, args); \
  1441. + unsigned long int resultvar = INTERNAL_SYSCALL_TYPES (name, , ##nr_args); \
  1442. if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0)) \
  1443. { \
  1444. __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
  1445. @@ -223,13 +235,19 @@
  1446. LOAD_ARGS_##nr (args) \
  1447. LOAD_REGS_##nr \
  1448. asm volatile ( \
  1449. - "syscall\n\t" \
  1450. + SYSCALLDB \
  1451. : "=a" (resultvar) \
  1452. : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx"); \
  1453. (long int) resultvar; })
  1454. +# define INTERNAL_SYSCALL_NCS_ASM INTERNAL_SYSCALL_NCS
  1455. +
  1456. # undef INTERNAL_SYSCALL
  1457. -# define INTERNAL_SYSCALL(name, err, nr, args...) \
  1458. - INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
  1459. +# define INTERNAL_SYSCALL(name, err, nr_args...) \
  1460. + INTERNAL_SYSCALL_NCS (__NR_##name, err, ##nr_args)
  1461. +
  1462. +# undef INTERNAL_SYSCALL_ASM
  1463. +# define INTERNAL_SYSCALL_ASM(name, err, nr_args...) \
  1464. + INTERNAL_SYSCALL_NCS_ASM (__NR_##name, err, ##nr_args)
  1465. # define INTERNAL_SYSCALL_NCS_TYPES(name, err, nr, args...) \
  1466. ({ \
  1467. @@ -237,7 +255,7 @@
  1468. LOAD_ARGS_TYPES_##nr (args) \
  1469. LOAD_REGS_TYPES_##nr (args) \
  1470. asm volatile ( \
  1471. - "syscall\n\t" \
  1472. + SYSCALLDB \
  1473. : "=a" (resultvar) \
  1474. : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx"); \
  1475. (long int) resultvar; })
  1476. @@ -252,6 +270,7 @@
  1477. # undef INTERNAL_SYSCALL_ERRNO
  1478. # define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
  1479. +# if 0 /* for Graphene, never do vsyscall */
  1480. # ifdef SHARED
  1481. # define INLINE_VSYSCALL(name, nr, args...) \
  1482. ({ \
  1483. @@ -300,12 +319,13 @@
  1484. v_ret; \
  1485. })
  1486. -# else
  1487. -# define INLINE_VSYSCALL(name, nr, args...) \
  1488. - INLINE_SYSCALL (name, nr, ##args)
  1489. -# define INTERNAL_VSYSCALL(name, err, nr, args...) \
  1490. - INTERNAL_SYSCALL (name, err, nr, ##args)
  1491. # endif
  1492. +# endif
  1493. +
  1494. +# define INLINE_VSYSCALL(name, nr_args...) \
  1495. + INLINE_SYSCALL (name, ##nr_args)
  1496. +# define INTERNAL_VSYSCALL(name, err, nr_args...) \
  1497. + INTERNAL_SYSCALL (name, err, ##nr_args)
  1498. # define LOAD_ARGS_0()
  1499. # define LOAD_REGS_0
  1500. diff --git a/sysdeps/unix/sysv/linux/x86_64/time.c b/sysdeps/unix/sysv/linux/x86_64/time.c
  1501. deleted file mode 100644
  1502. index 79f1fab..0000000
  1503. --- a/sysdeps/unix/sysv/linux/x86_64/time.c
  1504. +++ /dev/null
  1505. @@ -1,60 +0,0 @@
  1506. -/* Copyright (C) 2001-2014 Free Software Foundation, Inc.
  1507. - This file is part of the GNU C Library.
  1508. -
  1509. - The GNU C Library is free software; you can redistribute it and/or
  1510. - modify it under the terms of the GNU Lesser General Public
  1511. - License as published by the Free Software Foundation; either
  1512. - version 2.1 of the License, or (at your option) any later version.
  1513. -
  1514. - The GNU C Library is distributed in the hope that it will be useful,
  1515. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  1516. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1517. - Lesser General Public License for more details.
  1518. -
  1519. - You should have received a copy of the GNU Lesser General Public
  1520. - License along with the GNU C Library; if not, see
  1521. - <http://www.gnu.org/licenses/>. */
  1522. -
  1523. -#ifdef SHARED
  1524. -/* Redefine time so that the compiler won't complain about the type
  1525. - mismatch with the IFUNC selector in strong_alias, below. */
  1526. -#undef time
  1527. -#define time __redirect_time
  1528. -#include <time.h>
  1529. -
  1530. -#include <dl-vdso.h>
  1531. -
  1532. -#define VSYSCALL_ADDR_vtime 0xffffffffff600400
  1533. -
  1534. -/* Avoid DWARF definition DIE on ifunc symbol so that GDB can handle
  1535. - ifunc symbol properly. */
  1536. -extern __typeof (__redirect_time) __libc_time;
  1537. -void *time_ifunc (void) __asm__ ("__libc_time");
  1538. -
  1539. -void *
  1540. -time_ifunc (void)
  1541. -{
  1542. - PREPARE_VERSION (linux26, "LINUX_2.6", 61765110);
  1543. -
  1544. - /* If the vDSO is not available we fall back on the old vsyscall. */
  1545. - return _dl_vdso_vsym ("__vdso_time", &linux26) ?: (void *) VSYSCALL_ADDR_vtime;
  1546. -}
  1547. -__asm (".type __libc_time, %gnu_indirect_function");
  1548. -
  1549. -#undef time
  1550. -strong_alias (__libc_time, time)
  1551. -libc_hidden_ver (__libc_time, time)
  1552. -
  1553. -#else
  1554. -
  1555. -# include <time.h>
  1556. -# include <sysdep.h>
  1557. -
  1558. -time_t
  1559. -time (time_t *t)
  1560. -{
  1561. - INTERNAL_SYSCALL_DECL (err);
  1562. - return INTERNAL_SYSCALL (time, err, 1, t);
  1563. -}
  1564. -
  1565. -#endif
  1566. diff --git a/sysdeps/unix/sysv/linux/x86_64/vfork.S b/sysdeps/unix/sysv/linux/x86_64/vfork.S
  1567. index d3b450a..75a63e1 100644
  1568. --- a/sysdeps/unix/sysv/linux/x86_64/vfork.S
  1569. +++ b/sysdeps/unix/sysv/linux/x86_64/vfork.S
  1570. @@ -38,7 +38,7 @@ ENTRY (__vfork)
  1571. /* Stuff the syscall number in RAX and enter into the kernel. */
  1572. movl $SYS_ify (vfork), %eax
  1573. - syscall
  1574. + SYSCALLDB
  1575. /* Push back the return PC. */
  1576. pushq %rdi
  1577. diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h
  1578. index 504c95f..dcfc259 100644
  1579. --- a/sysdeps/x86_64/dl-machine.h
  1580. +++ b/sysdeps/x86_64/dl-machine.h
  1581. @@ -529,7 +529,8 @@ elf_machine_lazy_rel (struct link_map *map,
  1582. value = ((ElfW(Addr) (*) (void)) value) ();
  1583. *reloc_addr = value;
  1584. }
  1585. - else
  1586. + /* for graphene, get around R_X86_64_NONE */
  1587. + else if (__builtin_expect (r_type != R_X86_64_NONE, 1))
  1588. _dl_reloc_bad_type (map, r_type, 1);
  1589. }
  1590. diff --git a/sysdeps/x86_64/hp-timing.h b/sysdeps/x86_64/hp-timing.h
  1591. index d88206c..886c500 100644
  1592. --- a/sysdeps/x86_64/hp-timing.h
  1593. +++ b/sysdeps/x86_64/hp-timing.h
  1594. @@ -18,23 +18,6 @@
  1595. #ifndef _HP_TIMING_H
  1596. -/* We can use some of the i686 implementation without changes. */
  1597. -# include <sysdeps/i386/i686/hp-timing.h>
  1598. -
  1599. -/* The "=A" constraint used in 32-bit mode does not work in 64-bit mode. */
  1600. -# undef HP_TIMING_NOW
  1601. -# define HP_TIMING_NOW(Var) \
  1602. - ({ unsigned int _hi, _lo; \
  1603. - asm volatile ("rdtsc" : "=a" (_lo), "=d" (_hi)); \
  1604. - (Var) = ((unsigned long long int) _hi << 32) | _lo; })
  1605. -
  1606. -/* The funny business for 32-bit mode is not required here. */
  1607. -# undef HP_TIMING_ACCUM
  1608. -# define HP_TIMING_ACCUM(Sum, Diff) \
  1609. - do { \
  1610. - hp_timing_t __diff = (Diff) - GLRO(dl_hp_timing_overhead); \
  1611. - __asm__ __volatile__ ("lock; addq %1, %0" \
  1612. - : "=m" (Sum) : "r" (__diff), "m" (Sum)); \
  1613. - } while (0)
  1614. +# include <sysdeps/generic/hp-timing.h>
  1615. #endif /* hp-timing.h */