glibc-2.19.patch 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764
  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/fork.c b/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c
  677. index a036b92..40a1eaf 100644
  678. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c
  679. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c
  680. @@ -21,10 +21,20 @@
  681. #include <sysdep.h>
  682. #include <tls.h>
  683. -
  684. -#define ARCH_FORK() \
  685. +/* In Graphene, we prefer to call fork system call directly than clone */
  686. +#if USE_clone_FOR_fork
  687. +# define ARCH_FORK() \
  688. INLINE_SYSCALL (clone, 4, \
  689. CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, 0, \
  690. NULL, &THREAD_SELF->tid)
  691. +#else
  692. +# define ARCH_FORK() \
  693. + ({ unsigned long ret = INLINE_SYSCALL (fork, 0); \
  694. + if (!ret) { \
  695. + pid_t pid = INLINE_SYSCALL (getpid, 0); \
  696. + THREAD_SETMEM (THREAD_SELF, pid, pid); \
  697. + THREAD_SETMEM (THREAD_SELF, tid, pid); \
  698. + } ret; })
  699. +#endif
  700. #include "../fork.c"
  701. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
  702. index f2dca07..0ce7c67 100644
  703. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
  704. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
  705. @@ -90,7 +90,7 @@ __lll_lock_wait_private:
  706. 1: LIBC_PROBE (lll_lock_wait_private, 1, %rdi)
  707. movl $SYS_futex, %eax
  708. - syscall
  709. + SYSCALLDB
  710. 2: movl %edx, %eax
  711. xchgl %eax, (%rdi) /* NB: lock is implied */
  712. @@ -130,7 +130,7 @@ __lll_lock_wait:
  713. 1: LIBC_PROBE (lll_lock_wait, 2, %rdi, %rsi)
  714. movl $SYS_futex, %eax
  715. - syscall
  716. + SYSCALLDB
  717. 2: movl %edx, %eax
  718. xchgl %eax, (%rdi) /* NB: lock is implied */
  719. @@ -185,7 +185,7 @@ __lll_timedlock_wait:
  720. 1: movl $SYS_futex, %eax
  721. movl $2, %edx
  722. - syscall
  723. + SYSCALLDB
  724. 2: xchgl %edx, (%rdi) /* NB: lock is implied */
  725. @@ -279,7 +279,7 @@ __lll_timedlock_wait:
  726. LOAD_FUTEX_WAIT (%esi)
  727. movq %r12, %rdi
  728. movl $SYS_futex, %eax
  729. - syscall
  730. + SYSCALLDB
  731. /* NB: %edx == 2 */
  732. xchgl %edx, (%r12)
  733. @@ -336,7 +336,7 @@ __lll_unlock_wake_private:
  734. LOAD_PRIVATE_FUTEX_WAKE (%esi)
  735. movl $1, %edx /* Wake one thread. */
  736. movl $SYS_futex, %eax
  737. - syscall
  738. + SYSCALLDB
  739. popq %rdx
  740. cfi_adjust_cfa_offset(-8)
  741. @@ -366,7 +366,7 @@ __lll_unlock_wake:
  742. LOAD_FUTEX_WAKE (%esi)
  743. movl $1, %edx /* Wake one thread. */
  744. movl $SYS_futex, %eax
  745. - syscall
  746. + SYSCALLDB
  747. popq %rdx
  748. cfi_adjust_cfa_offset(-8)
  749. @@ -435,7 +435,7 @@ __lll_timedwait_tid:
  750. #endif
  751. movq %r12, %rdi
  752. movl $SYS_futex, %eax
  753. - syscall
  754. + SYSCALLDB
  755. cmpl $0, (%rdi)
  756. jne 1f
  757. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
  758. index 0a26739..8aae14a 100644
  759. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
  760. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
  761. @@ -214,7 +214,7 @@ LLL_STUB_UNWIND_INFO_END
  762. register const struct timespec *__to __asm ("r10") = timeout; \
  763. int __status; \
  764. register __typeof (val) _val __asm ("edx") = (val); \
  765. - __asm __volatile ("syscall" \
  766. + __asm __volatile (SYSCALLDB \
  767. : "=a" (__status) \
  768. : "0" (SYS_futex), "D" (futex), \
  769. "S" (__lll_private_flag (FUTEX_WAIT, private)), \
  770. @@ -229,7 +229,7 @@ LLL_STUB_UNWIND_INFO_END
  771. int __status; \
  772. register __typeof (nr) _nr __asm ("edx") = (nr); \
  773. LIBC_PROBE (lll_futex_wake, 3, futex, nr, private); \
  774. - __asm __volatile ("syscall" \
  775. + __asm __volatile (SYSCALLDB \
  776. : "=a" (__status) \
  777. : "0" (SYS_futex), "D" (futex), \
  778. "S" (__lll_private_flag (FUTEX_WAKE, private)), \
  779. @@ -540,7 +540,7 @@ extern int __lll_timedlock_elision (int *futex, short *adapt_count,
  780. { \
  781. int ignore; \
  782. __asm __volatile (LOCK_INSTR "orl %3, (%2)\n\t" \
  783. - "syscall" \
  784. + SYSCALLDB \
  785. : "=m" (futex), "=a" (ignore) \
  786. : "D" (&(futex)), "i" (FUTEX_OWNER_DIED), \
  787. "S" (__lll_private_flag (FUTEX_WAKE, private)), \
  788. @@ -555,7 +555,7 @@ extern int __lll_timedlock_elision (int *futex, short *adapt_count,
  789. register int __nr_move __asm ("r10") = nr_move; \
  790. register void *__mutex __asm ("r8") = mutex; \
  791. register int __val __asm ("r9") = val; \
  792. - __asm __volatile ("syscall" \
  793. + __asm __volatile (SYSCALLDB \
  794. : "=a" (__res) \
  795. : "0" (__NR_futex), "D" ((void *) ftx), \
  796. "S" (__lll_private_flag (FUTEX_CMP_REQUEUE, \
  797. @@ -581,7 +581,7 @@ extern int __lll_timedlock_elision (int *futex, short *adapt_count,
  798. if (_tid != 0) \
  799. __asm __volatile ("xorq %%r10, %%r10\n\t" \
  800. "1:\tmovq %2, %%rax\n\t" \
  801. - "syscall\n\t" \
  802. + SYSCALLDB \
  803. "cmpl $0, (%%rdi)\n\t" \
  804. "jne 1b" \
  805. : "=&a" (__ignore) \
  806. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
  807. index 990b6f9..b01214d 100644
  808. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
  809. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
  810. @@ -80,7 +80,7 @@ __lll_robust_lock_wait:
  811. jnz 2f
  812. 1: movl $SYS_futex, %eax
  813. - syscall
  814. + SYSCALLDB
  815. movl (%rdi), %eax
  816. @@ -145,7 +145,7 @@ __lll_robust_timedlock_wait:
  817. jnz 6f
  818. 5: movl $SYS_futex, %eax
  819. - syscall
  820. + SYSCALLDB
  821. movl %eax, %ecx
  822. movl (%rdi), %eax
  823. @@ -257,7 +257,7 @@ __lll_robust_timedlock_wait:
  824. LOAD_FUTEX_WAIT (%esi)
  825. movq %r12, %rdi
  826. movl $SYS_futex, %eax
  827. - syscall
  828. + SYSCALLDB
  829. movq %rax, %rcx
  830. movl (%r12), %eax
  831. 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
  832. index eec17f2..a350340 100644
  833. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S
  834. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S
  835. @@ -62,7 +62,7 @@ pthread_barrier_wait:
  836. #endif
  837. xorq %r10, %r10
  838. 8: movl $SYS_futex, %eax
  839. - syscall
  840. + SYSCALLDB
  841. /* Don't return on spurious wakeups. The syscall does not change
  842. any register except %eax so there is no need to reload any of
  843. @@ -109,7 +109,7 @@ pthread_barrier_wait:
  844. movl $FUTEX_WAKE, %esi
  845. orl PRIVATE(%rdi), %esi
  846. movl $SYS_futex, %eax
  847. - syscall
  848. + SYSCALLDB
  849. /* Increment LEFT. If this brings the count back to the
  850. initial count unlock the object. */
  851. 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
  852. index 985e0f1..d559456 100644
  853. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
  854. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
  855. @@ -90,7 +90,7 @@ __pthread_cond_broadcast:
  856. movl $SYS_futex, %eax
  857. movl $1, %edx
  858. movl $0x7fffffff, %r10d
  859. - syscall
  860. + SYSCALLDB
  861. /* For any kind of error, which mainly is EAGAIN, we try again
  862. with WAKE. The general test also covers running on old
  863. @@ -106,7 +106,7 @@ __pthread_cond_broadcast:
  864. movl $SYS_futex, %eax
  865. movl $1, %edx
  866. movl $0x7fffffff, %r10d
  867. - syscall
  868. + SYSCALLDB
  869. /* For any kind of error, which mainly is EAGAIN, we try again
  870. with WAKE. The general test also covers running on old
  871. @@ -172,7 +172,7 @@ __pthread_cond_broadcast:
  872. orl $FUTEX_WAKE, %esi
  873. #endif
  874. movl $SYS_futex, %eax
  875. - syscall
  876. + SYSCALLDB
  877. jmp 10b
  878. .size __pthread_cond_broadcast, .-__pthread_cond_broadcast
  879. versioned_symbol (libpthread, __pthread_cond_broadcast, pthread_cond_broadcast,
  880. 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
  881. index 53d65b6..16df581 100644
  882. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
  883. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
  884. @@ -82,7 +82,7 @@ __pthread_cond_signal:
  885. addq $cond_lock, %r8
  886. #endif
  887. movl $FUTEX_OP_CLEAR_WAKE_IF_GT_ONE, %r9d
  888. - syscall
  889. + SYSCALLDB
  890. #if cond_lock != 0
  891. subq $cond_lock, %r8
  892. #endif
  893. @@ -99,7 +99,7 @@ __pthread_cond_signal:
  894. movq %rcx, %r8
  895. xorq %r10, %r10
  896. movl (%rdi), %r9d // XXX Can this be right?
  897. - syscall
  898. + SYSCALLDB
  899. leaq -cond_futex(%rdi), %r8
  900. @@ -118,7 +118,7 @@ __pthread_cond_signal:
  901. movl $SYS_futex, %eax
  902. /* %rdx should be 1 already from $FUTEX_WAKE_OP syscall.
  903. movl $1, %edx */
  904. - syscall
  905. + SYSCALLDB
  906. /* Unlock. */
  907. 4: LOCK
  908. 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
  909. index 0dc2340..8aff242 100644
  910. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
  911. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
  912. @@ -188,7 +188,7 @@ __pthread_cond_timedwait:
  913. movq %r12, %rdx
  914. addq $cond_futex, %rdi
  915. movl $SYS_futex, %eax
  916. - syscall
  917. + SYSCALLDB
  918. cmpl $0, %eax
  919. sete %r15b
  920. @@ -234,7 +234,7 @@ __pthread_cond_timedwait:
  921. movq %r12, %rdx
  922. addq $cond_futex, %rdi
  923. movl $SYS_futex, %eax
  924. - syscall
  925. + SYSCALLDB
  926. 62: movq %rax, %r14
  927. movl (%rsp), %edi
  928. @@ -321,7 +321,7 @@ __pthread_cond_timedwait:
  929. orl $FUTEX_WAKE, %esi
  930. #endif
  931. movl $SYS_futex, %eax
  932. - syscall
  933. + SYSCALLDB
  934. subq $cond_nwaiters, %rdi
  935. 55: LOCK
  936. @@ -485,15 +485,8 @@ __pthread_cond_timedwait:
  937. /* Only clocks 0 and 1 are allowed so far. Both are handled in the
  938. kernel. */
  939. leaq 32(%rsp), %rsi
  940. -# ifdef SHARED
  941. - mov __vdso_clock_gettime@GOTPCREL(%rip), %RAX_LP
  942. - mov (%rax), %RAX_LP
  943. - PTR_DEMANGLE (%RAX_LP)
  944. - call *%rax
  945. -# else
  946. movl $__NR_clock_gettime, %eax
  947. - syscall
  948. -# endif
  949. + SYSCALLDB
  950. /* Compute relative timeout. */
  951. movq (%r13), %rcx
  952. @@ -560,7 +553,7 @@ __pthread_cond_timedwait:
  953. # endif
  954. addq $cond_futex, %rdi
  955. movl $SYS_futex, %eax
  956. - syscall
  957. + SYSCALLDB
  958. movq %rax, %r14
  959. movl (%rsp), %edi
  960. @@ -732,7 +725,7 @@ __condvar_cleanup2:
  961. orl $FUTEX_WAKE, %esi
  962. #endif
  963. movl $SYS_futex, %eax
  964. - syscall
  965. + SYSCALLDB
  966. subq $cond_nwaiters, %rdi
  967. movl $1, %r12d
  968. @@ -769,7 +762,7 @@ __condvar_cleanup2:
  969. orl $FUTEX_WAKE, %esi
  970. #endif
  971. movl $SYS_futex, %eax
  972. - syscall
  973. + SYSCALLDB
  974. /* Lock the mutex only if we don't own it already. This only happens
  975. in case of PI mutexes, if we got cancelled after a successful
  976. 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
  977. index 0e61d0a..b4bcc15 100644
  978. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
  979. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
  980. @@ -138,7 +138,7 @@ __pthread_cond_wait:
  981. movl $(FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %esi
  982. movl $SYS_futex, %eax
  983. - syscall
  984. + SYSCALLDB
  985. cmpl $0, %eax
  986. sete %r8b
  987. @@ -180,7 +180,7 @@ __pthread_cond_wait:
  988. #endif
  989. 60: xorb %r8b, %r8b
  990. movl $SYS_futex, %eax
  991. - syscall
  992. + SYSCALLDB
  993. 62: movl (%rsp), %edi
  994. callq __pthread_disable_asynccancel
  995. @@ -239,7 +239,7 @@ __pthread_cond_wait:
  996. orl $FUTEX_WAKE, %esi
  997. #endif
  998. movl $SYS_futex, %eax
  999. - syscall
  1000. + SYSCALLDB
  1001. subq $cond_nwaiters, %rdi
  1002. 17: LOCK
  1003. @@ -455,7 +455,7 @@ __condvar_cleanup1:
  1004. orl $FUTEX_WAKE, %esi
  1005. #endif
  1006. movl $SYS_futex, %eax
  1007. - syscall
  1008. + SYSCALLDB
  1009. subq $cond_nwaiters, %rdi
  1010. movl $1, %ecx
  1011. @@ -493,7 +493,7 @@ __condvar_cleanup1:
  1012. orl $FUTEX_WAKE, %esi
  1013. #endif
  1014. movl $SYS_futex, %eax
  1015. - syscall
  1016. + SYSCALLDB
  1017. /* Lock the mutex only if we don't own it already. This only happens
  1018. in case of PI mutexes, if we got cancelled after a successful
  1019. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
  1020. index 2cbe2fa..489998a 100644
  1021. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
  1022. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
  1023. @@ -90,7 +90,7 @@ __pthread_once:
  1024. # endif
  1025. #endif
  1026. movl $SYS_futex, %eax
  1027. - syscall
  1028. + SYSCALLDB
  1029. jmp 6b
  1030. /* Preserve the pointer to the control variable. */
  1031. @@ -123,7 +123,7 @@ __pthread_once:
  1032. orl %fs:PRIVATE_FUTEX, %esi
  1033. #endif
  1034. movl $SYS_futex, %eax
  1035. - syscall
  1036. + SYSCALLDB
  1037. 4: addq $8, %rsp
  1038. cfi_adjust_cfa_offset(-8)
  1039. @@ -152,7 +152,7 @@ clear_once_control:
  1040. orl %fs:PRIVATE_FUTEX, %esi
  1041. #endif
  1042. movl $SYS_futex, %eax
  1043. - syscall
  1044. + SYSCALLDB
  1045. movq %r8, %rdi
  1046. .LcallUR:
  1047. 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
  1048. index 3bbb4c7..53d5ca6 100644
  1049. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S
  1050. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S
  1051. @@ -82,7 +82,7 @@ __pthread_rwlock_rdlock:
  1052. #endif
  1053. addq $READERS_WAKEUP, %rdi
  1054. movl $SYS_futex, %eax
  1055. - syscall
  1056. + SYSCALLDB
  1057. subq $READERS_WAKEUP, %rdi
  1058. 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
  1059. index 40bcc04..348170e 100644
  1060. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
  1061. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
  1062. @@ -109,7 +109,7 @@ pthread_rwlock_timedrdlock:
  1063. #endif
  1064. 21: leaq READERS_WAKEUP(%r12), %rdi
  1065. movl $SYS_futex, %eax
  1066. - syscall
  1067. + SYSCALLDB
  1068. movq %rax, %rdx
  1069. #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
  1070. 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
  1071. index f57ef52..e9ac77f 100644
  1072. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
  1073. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
  1074. @@ -106,7 +106,7 @@ pthread_rwlock_timedwrlock:
  1075. #endif
  1076. 21: leaq WRITERS_WAKEUP(%r12), %rdi
  1077. movl $SYS_futex, %eax
  1078. - syscall
  1079. + SYSCALLDB
  1080. movq %rax, %rdx
  1081. #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
  1082. 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
  1083. index d779f7b..849c74f 100644
  1084. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S
  1085. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S
  1086. @@ -79,7 +79,7 @@ __pthread_rwlock_unlock:
  1087. #endif
  1088. movl $SYS_futex, %eax
  1089. movq %r10, %rdi
  1090. - syscall
  1091. + SYSCALLDB
  1092. xorl %eax, %eax
  1093. retq
  1094. 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
  1095. index e444def..fd94930 100644
  1096. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S
  1097. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S
  1098. @@ -80,7 +80,7 @@ __pthread_rwlock_wrlock:
  1099. #endif
  1100. addq $WRITERS_WAKEUP, %rdi
  1101. movl $SYS_futex, %eax
  1102. - syscall
  1103. + SYSCALLDB
  1104. subq $WRITERS_WAKEUP, %rdi
  1105. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
  1106. index 1c11600..bd166cf 100644
  1107. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
  1108. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
  1109. @@ -52,7 +52,7 @@ sem_post:
  1110. movl $FUTEX_WAKE, %esi
  1111. orl PRIVATE(%rdi), %esi
  1112. movl $1, %edx
  1113. - syscall
  1114. + SYSCALLDB
  1115. testq %rax, %rax
  1116. js 1f
  1117. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
  1118. index 880610e..e520049 100644
  1119. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
  1120. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
  1121. @@ -97,7 +97,7 @@ sem_timedwait:
  1122. orl PRIVATE(%rdi), %esi
  1123. movl $SYS_futex, %eax
  1124. xorl %edx, %edx
  1125. - syscall
  1126. + SYSCALLDB
  1127. movq %rax, %r9
  1128. #if VALUE != 0
  1129. leaq -VALUE(%rdi), %rdi
  1130. @@ -233,7 +233,7 @@ sem_timedwait:
  1131. # endif
  1132. movl $SYS_futex, %eax
  1133. xorl %edx, %edx
  1134. - syscall
  1135. + SYSCALLDB
  1136. movq %rax, %r14
  1137. movl 16(%rsp), %edi
  1138. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
  1139. index 8f4d068..fe6dfbf 100644
  1140. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
  1141. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
  1142. @@ -81,7 +81,7 @@ sem_wait:
  1143. orl PRIVATE(%rdi), %esi
  1144. #endif
  1145. xorl %edx, %edx
  1146. - syscall
  1147. + SYSCALLDB
  1148. movq %rax, %rcx
  1149. xchgq %r8, %rdi
  1150. diff --git a/nptl/sysdeps/x86_64/pthreaddef.h b/nptl/sysdeps/x86_64/pthreaddef.h
  1151. index 18a15a1..f050241 100644
  1152. --- a/nptl/sysdeps/x86_64/pthreaddef.h
  1153. +++ b/nptl/sysdeps/x86_64/pthreaddef.h
  1154. @@ -48,4 +48,4 @@
  1155. /* While there is no such syscall. */
  1156. #define __exit_thread_inline(val) \
  1157. - asm volatile ("syscall" :: "a" (__NR_exit), "D" (val))
  1158. + asm volatile (SYSCALLDB :: "a" (__NR_exit), "D" (val))
  1159. diff --git a/nptl/sysdeps/x86_64/tls.h b/nptl/sysdeps/x86_64/tls.h
  1160. index cbb5e9e..9b87e25 100644
  1161. --- a/nptl/sysdeps/x86_64/tls.h
  1162. +++ b/nptl/sysdeps/x86_64/tls.h
  1163. @@ -28,6 +28,8 @@
  1164. # include <sysdep.h>
  1165. # include <libc-internal.h>
  1166. # include <kernel-features.h>
  1167. +# include <shim_tls.h>
  1168. +# include <syscalldb.h>
  1169. /* Replacement type for __m128 since this file is included by ld.so,
  1170. which is compiled with -mno-sse. It must not change the alignment
  1171. @@ -67,6 +69,10 @@ typedef struct
  1172. # else
  1173. int __glibc_reserved1;
  1174. # endif
  1175. +
  1176. + shim_tcb_t shim_tcb; /* For graphene, we allocate a shim_tcb
  1177. + in the real tcb. */
  1178. +
  1179. int rtld_must_xmm_save;
  1180. /* Reservation of some values for the TM ABI. */
  1181. void *__private_tm[4];
  1182. @@ -137,7 +143,6 @@ typedef struct
  1183. # define GET_DTV(descr) \
  1184. (((tcbhead_t *) (descr))->dtv)
  1185. -
  1186. /* Code to initially initialize the thread pointer. This might need
  1187. special attention since 'errno' is not yet available and if the
  1188. operation can cause a failure 'errno' must not be touched.
  1189. @@ -154,7 +159,7 @@ typedef struct
  1190. _head->self = _thrdescr; \
  1191. \
  1192. /* It is a simple syscall to set the %fs value for the thread. */ \
  1193. - asm volatile ("syscall" \
  1194. + asm volatile (SYSCALLDB \
  1195. : "=a" (_result) \
  1196. : "0" ((unsigned long int) __NR_arch_prctl), \
  1197. "D" ((unsigned long int) ARCH_SET_FS), \
  1198. diff --git a/scripts/mkinstalldirs b/scripts/mkinstalldirs
  1199. index 55d537f..57bf12b 100755
  1200. --- a/scripts/mkinstalldirs
  1201. +++ b/scripts/mkinstalldirs
  1202. @@ -126,9 +126,9 @@ do
  1203. esac
  1204. if test ! -d "$pathcomp"; then
  1205. - echo "mkdir $pathcomp"
  1206. + echo "mkdir -p $pathcomp"
  1207. - mkdir "$pathcomp" || lasterr=$?
  1208. + mkdir -p "$pathcomp" || lasterr=$?
  1209. if test ! -d "$pathcomp"; then
  1210. errstatus=$lasterr
  1211. diff --git a/shlib-versions b/shlib-versions
  1212. index 78b0ad7..5c3dcf2 100644
  1213. --- a/shlib-versions
  1214. +++ b/shlib-versions
  1215. @@ -108,3 +108,5 @@ sparc64.*-.*-.* libBrokenLocale=1 GLIBC_2.2
  1216. # This defines the libgcc soname version this glibc is to load for
  1217. # asynchronous cancellation to work correctly.
  1218. .*-.*-.* libgcc_s=1
  1219. +
  1220. +.*-.*-.* liblibos=1
  1221. diff --git a/sysdeps/unix/sysv/linux/_exit.c b/sysdeps/unix/sysv/linux/_exit.c
  1222. index 2468228..a9f1cd6 100644
  1223. --- a/sysdeps/unix/sysv/linux/_exit.c
  1224. +++ b/sysdeps/unix/sysv/linux/_exit.c
  1225. @@ -29,9 +29,9 @@ _exit (status)
  1226. while (1)
  1227. {
  1228. #ifdef __NR_exit_group
  1229. - INLINE_SYSCALL (exit_group, 1, status);
  1230. + INLINE_SYSCALL_ASM (exit_group, 1, status);
  1231. #endif
  1232. - INLINE_SYSCALL (exit, 1, status);
  1233. + INLINE_SYSCALL_ASM (exit, 1, status);
  1234. #ifdef ABORT_INSTRUCTION
  1235. ABORT_INSTRUCTION;
  1236. diff --git a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
  1237. index 49f0384..6b1a975 100644
  1238. --- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
  1239. +++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
  1240. @@ -84,7 +84,8 @@ ENTRY(____longjmp_chk)
  1241. xorl %edi, %edi
  1242. lea -sizeSS(%rsp), %RSI_LP
  1243. movl $__NR_sigaltstack, %eax
  1244. - syscall
  1245. + SYSCALLDB
  1246. +
  1247. /* Without working sigaltstack we cannot perform the test. */
  1248. testl %eax, %eax
  1249. jne .Lok2
  1250. diff --git a/sysdeps/unix/sysv/linux/x86_64/clock_gettime.c b/sysdeps/unix/sysv/linux/x86_64/clock_gettime.c
  1251. index f712110..f6bad14 100644
  1252. --- a/sysdeps/unix/sysv/linux/x86_64/clock_gettime.c
  1253. +++ b/sysdeps/unix/sysv/linux/x86_64/clock_gettime.c
  1254. @@ -1,5 +1,6 @@
  1255. #include "bits/libc-vdso.h"
  1256. +#if 0 /* in Graphene, disallow VDSO calls */
  1257. #ifdef SHARED
  1258. # define SYSCALL_GETTIME(id, tp) \
  1259. ({ long int (*f) (clockid_t, struct timespec *) = __vdso_clock_gettime; \
  1260. @@ -16,5 +17,6 @@
  1261. PTR_DEMANGLE (f); \
  1262. f (id, tp); })
  1263. #endif
  1264. +#endif
  1265. #include "../clock_gettime.c"
  1266. diff --git a/sysdeps/unix/sysv/linux/x86_64/clone.S b/sysdeps/unix/sysv/linux/x86_64/clone.S
  1267. index 0508730..e1b35ec 100644
  1268. --- a/sysdeps/unix/sysv/linux/x86_64/clone.S
  1269. +++ b/sysdeps/unix/sysv/linux/x86_64/clone.S
  1270. @@ -76,5 +80,5 @@ ENTRY (__clone)
  1271. /* End FDE now, because in the child the unwind info will be
  1272. wrong. */
  1273. cfi_endproc;
  1274. - syscall
  1275. + SYSCALLDB
  1276. @@ -99,10 +104,10 @@ L(thread_start):
  1277. movl $-1, %eax
  1278. jne 2f
  1279. movl $SYS_ify(getpid), %eax
  1280. - syscall
  1281. + SYSCALLDB
  1282. 2: movl %eax, %fs:PID
  1283. movl %eax, %fs:TID
  1284. 1:
  1285. #endif
  1286. /* Set up arguments for the function call. */
  1287. diff --git a/sysdeps/unix/sysv/linux/x86_64/getcontext.S b/sysdeps/unix/sysv/linux/x86_64/getcontext.S
  1288. index 140db03..6967f10 100644
  1289. --- a/sysdeps/unix/sysv/linux/x86_64/getcontext.S
  1290. +++ b/sysdeps/unix/sysv/linux/x86_64/getcontext.S
  1291. @@ -75,7 +75,7 @@ ENTRY(__getcontext)
  1292. #endif
  1293. movl $_NSIG8,%r10d
  1294. movl $__NR_rt_sigprocmask, %eax
  1295. - syscall
  1296. + SYSCALLDB
  1297. cmpq $-4095, %rax /* Check %rax for error. */
  1298. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  1299. diff --git a/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c b/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c
  1300. index 440ca7f..571125d 100644
  1301. --- a/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c
  1302. +++ b/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c
  1303. @@ -17,6 +17,7 @@
  1304. #include <sys/time.h>
  1305. +#if 0 /* In graphene, do not use vsyscall or VDSO call */
  1306. #ifdef SHARED
  1307. # include <dl-vdso.h>
  1308. @@ -42,7 +43,8 @@ asm (".type __gettimeofday, %gnu_indirect_function");
  1309. asm (".globl __GI___gettimeofday\n"
  1310. "__GI___gettimeofday = __gettimeofday");
  1311. -#else
  1312. +#endif
  1313. +#endif
  1314. # include <sysdep.h>
  1315. # include <errno.h>
  1316. @@ -54,6 +56,5 @@ __gettimeofday (struct timeval *tv, struct timezone *tz)
  1317. }
  1318. libc_hidden_def (__gettimeofday)
  1319. -#endif
  1320. weak_alias (__gettimeofday, gettimeofday)
  1321. libc_hidden_weak (gettimeofday)
  1322. diff --git a/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S b/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
  1323. index 0fd47f2..7a82975 100644
  1324. --- a/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
  1325. +++ b/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
  1326. @@ -30,6 +30,7 @@ ENTRY (sched_getcpu)
  1327. sub $0x8, %rsp
  1328. cfi_adjust_cfa_offset(8)
  1329. +#if 0 /* for Graphene, never do VDSO calls */
  1330. movq %rsp, %rdi
  1331. xorl %esi, %esi
  1332. movl $VGETCPU_CACHE_OFFSET, %edx
  1333. @@ -39,16 +40,19 @@ ENTRY (sched_getcpu)
  1334. movq __vdso_getcpu(%rip), %rax
  1335. PTR_DEMANGLE (%rax)
  1336. callq *%rax
  1337. -#else
  1338. -# ifdef __NR_getcpu
  1339. +#endif
  1340. +#endif
  1341. +
  1342. +#ifdef __NR_getcpu
  1343. movl $__NR_getcpu, %eax
  1344. - syscall
  1345. -# ifndef __ASSUME_GETCPU_SYSCALL
  1346. + SYSCALLDB
  1347. +#endif
  1348. +
  1349. +#if 0 /* for Graphene, never do vsyscall */
  1350. +# ifndef __ASSUME_GETCPU_SYSCALL
  1351. cmpq $-ENOSYS, %rax
  1352. jne 1f
  1353. -# endif
  1354. -# endif
  1355. -# ifndef __ASSUME_GETCPU_SYSCALL
  1356. +
  1357. movq $VSYSCALL_ADDR_vgetcpu, %rax
  1358. callq *%rax
  1359. 1:
  1360. diff --git a/sysdeps/unix/sysv/linux/x86_64/setcontext.S b/sysdeps/unix/sysv/linux/x86_64/setcontext.S
  1361. index b726fa0..bb3ae34 100644
  1362. --- a/sysdeps/unix/sysv/linux/x86_64/setcontext.S
  1363. +++ b/sysdeps/unix/sysv/linux/x86_64/setcontext.S
  1364. @@ -43,7 +43,7 @@ ENTRY(__setcontext)
  1365. movl $SIG_SETMASK, %edi
  1366. movl $_NSIG8,%r10d
  1367. movl $__NR_rt_sigprocmask, %eax
  1368. - syscall
  1369. + SYSCALLDB
  1370. popq %rdi /* Reload %rdi, adjust stack. */
  1371. cfi_adjust_cfa_offset(-8)
  1372. cmpq $-4095, %rax /* Check %rax for error. */
  1373. diff --git a/sysdeps/unix/sysv/linux/x86_64/sigaction.c b/sysdeps/unix/sysv/linux/x86_64/sigaction.c
  1374. index ab23985..38a6b69 100644
  1375. --- a/sysdeps/unix/sysv/linux/x86_64/sigaction.c
  1376. +++ b/sysdeps/unix/sysv/linux/x86_64/sigaction.c
  1377. @@ -129,7 +129,7 @@ asm \
  1378. " .type __" #name ",@function\n" \
  1379. "__" #name ":\n" \
  1380. " movq $" #syscall ", %rax\n" \
  1381. - " syscall\n" \
  1382. + SYSCALLDB_ASM \
  1383. ".LEND_" #name ":\n" \
  1384. ".section .eh_frame,\"a\",@progbits\n" \
  1385. ".LSTARTFRAME_" #name ":\n" \
  1386. diff --git a/sysdeps/unix/sysv/linux/x86_64/swapcontext.S b/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
  1387. index b3854fa..6369bfe 100644
  1388. --- a/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
  1389. +++ b/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
  1390. @@ -75,7 +75,7 @@ ENTRY(__swapcontext)
  1391. movl $SIG_SETMASK, %edi
  1392. movl $_NSIG8,%r10d
  1393. movl $__NR_rt_sigprocmask, %eax
  1394. - syscall
  1395. + SYSCALLDB
  1396. cmpq $-4095, %rax /* Check %rax for error. */
  1397. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  1398. diff --git a/sysdeps/unix/sysv/linux/x86_64/syscall.S b/sysdeps/unix/sysv/linux/x86_64/syscall.S
  1399. index 92c2f5b..e32ebb2 100644
  1400. --- a/sysdeps/unix/sysv/linux/x86_64/syscall.S
  1401. +++ b/sysdeps/unix/sysv/linux/x86_64/syscall.S
  1402. @@ -31,10 +31,12 @@
  1403. movq %rsi, %rdi /* shift arg1 - arg5. */
  1404. movq %rdx, %rsi
  1405. movq %rcx, %rdx
  1406. + /* DEP 8/17/17: Keep kernel calling
  1407. + * convention and fix in libOS */
  1408. movq %r8, %r10
  1409. movq %r9, %r8
  1410. movq 8(%rsp),%r9 /* arg6 is on the stack. */
  1411. - syscall /* Do the system call. */
  1412. + SYSCALLDB /* Do the system call. */
  1413. cmpq $-4095, %rax /* Check %rax for error. */
  1414. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  1415. ret /* Return to caller. */
  1416. diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
  1417. index 4a9a9d9..dc452ed 100644
  1418. --- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
  1419. +++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
  1420. @@ -21,6 +21,7 @@
  1421. /* There is some commonality. */
  1422. #include <sysdeps/unix/x86_64/sysdep.h>
  1423. #include <tls.h>
  1424. +#include "syscalldb.h"
  1425. #ifdef IS_IN_rtld
  1426. # include <dl-sysdep.h> /* Defines RTLD_PRIVATE_ERRNO. */
  1427. @@ -176,7 +177,7 @@
  1428. # define DO_CALL(syscall_name, args) \
  1429. DOARGS_##args \
  1430. movl $SYS_ify (syscall_name), %eax; \
  1431. - syscall;
  1432. + SYSCALLDB
  1433. # define DOARGS_0 /* nothing */
  1434. # define DOARGS_1 /* nothing */
  1435. @@ -190,9 +191,20 @@
  1436. /* Define a macro which expands inline into the wrapper code for a system
  1437. call. */
  1438. # undef INLINE_SYSCALL
  1439. -# define INLINE_SYSCALL(name, nr, args...) \
  1440. +# define INLINE_SYSCALL(name, nr_args...) \
  1441. ({ \
  1442. - unsigned long int resultvar = INTERNAL_SYSCALL (name, , nr, args); \
  1443. + unsigned long int resultvar = INTERNAL_SYSCALL (name, , ##nr_args); \
  1444. + if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0)) \
  1445. + { \
  1446. + __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
  1447. + resultvar = (unsigned long int) -1; \
  1448. + } \
  1449. + (long int) resultvar; })
  1450. +
  1451. +# undef INLINE_SYSCALL_ASM
  1452. +# define INLINE_SYSCALL_ASM(name, nr_args...) \
  1453. + ({ \
  1454. + unsigned long int resultvar = INTERNAL_SYSCALL_ASM (name, , ##nr_args); \
  1455. if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0)) \
  1456. { \
  1457. __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
  1458. @@ -204,9 +216,9 @@
  1459. into the wrapper code for a system call. It should be used when size
  1460. of any argument > size of long int. */
  1461. # undef INLINE_SYSCALL_TYPES
  1462. -# define INLINE_SYSCALL_TYPES(name, nr, args...) \
  1463. +# define INLINE_SYSCALL_TYPES(name, nr_args...) \
  1464. ({ \
  1465. - unsigned long int resultvar = INTERNAL_SYSCALL_TYPES (name, , nr, args); \
  1466. + unsigned long int resultvar = INTERNAL_SYSCALL_TYPES (name, , ##nr_args); \
  1467. if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0)) \
  1468. { \
  1469. __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
  1470. @@ -223,13 +235,19 @@
  1471. LOAD_ARGS_##nr (args) \
  1472. LOAD_REGS_##nr \
  1473. asm volatile ( \
  1474. - "syscall\n\t" \
  1475. + SYSCALLDB \
  1476. : "=a" (resultvar) \
  1477. : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx"); \
  1478. (long int) resultvar; })
  1479. +# define INTERNAL_SYSCALL_NCS_ASM INTERNAL_SYSCALL_NCS
  1480. +
  1481. # undef INTERNAL_SYSCALL
  1482. -# define INTERNAL_SYSCALL(name, err, nr, args...) \
  1483. - INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
  1484. +# define INTERNAL_SYSCALL(name, err, nr_args...) \
  1485. + INTERNAL_SYSCALL_NCS (__NR_##name, err, ##nr_args)
  1486. +
  1487. +# undef INTERNAL_SYSCALL_ASM
  1488. +# define INTERNAL_SYSCALL_ASM(name, err, nr_args...) \
  1489. + INTERNAL_SYSCALL_NCS_ASM (__NR_##name, err, ##nr_args)
  1490. # define INTERNAL_SYSCALL_NCS_TYPES(name, err, nr, args...) \
  1491. ({ \
  1492. @@ -237,7 +255,7 @@
  1493. LOAD_ARGS_TYPES_##nr (args) \
  1494. LOAD_REGS_TYPES_##nr (args) \
  1495. asm volatile ( \
  1496. - "syscall\n\t" \
  1497. + SYSCALLDB \
  1498. : "=a" (resultvar) \
  1499. : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx"); \
  1500. (long int) resultvar; })
  1501. @@ -252,6 +270,7 @@
  1502. # undef INTERNAL_SYSCALL_ERRNO
  1503. # define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
  1504. +# if 0 /* for Graphene, never do vsyscall */
  1505. # ifdef SHARED
  1506. # define INLINE_VSYSCALL(name, nr, args...) \
  1507. ({ \
  1508. @@ -300,12 +319,13 @@
  1509. v_ret; \
  1510. })
  1511. -# else
  1512. -# define INLINE_VSYSCALL(name, nr, args...) \
  1513. - INLINE_SYSCALL (name, nr, ##args)
  1514. -# define INTERNAL_VSYSCALL(name, err, nr, args...) \
  1515. - INTERNAL_SYSCALL (name, err, nr, ##args)
  1516. # endif
  1517. +# endif
  1518. +
  1519. +# define INLINE_VSYSCALL(name, nr_args...) \
  1520. + INLINE_SYSCALL (name, ##nr_args)
  1521. +# define INTERNAL_VSYSCALL(name, err, nr_args...) \
  1522. + INTERNAL_SYSCALL (name, err, ##nr_args)
  1523. # define LOAD_ARGS_0()
  1524. # define LOAD_REGS_0
  1525. diff --git a/sysdeps/unix/sysv/linux/x86_64/time.c b/sysdeps/unix/sysv/linux/x86_64/time.c
  1526. deleted file mode 100644
  1527. index 79f1fab..0000000
  1528. --- a/sysdeps/unix/sysv/linux/x86_64/time.c
  1529. +++ /dev/null
  1530. @@ -1,60 +0,0 @@
  1531. -/* Copyright (C) 2001-2014 Free Software Foundation, Inc.
  1532. - This file is part of the GNU C Library.
  1533. -
  1534. - The GNU C Library is free software; you can redistribute it and/or
  1535. - modify it under the terms of the GNU Lesser General Public
  1536. - License as published by the Free Software Foundation; either
  1537. - version 2.1 of the License, or (at your option) any later version.
  1538. -
  1539. - The GNU C Library is distributed in the hope that it will be useful,
  1540. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  1541. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1542. - Lesser General Public License for more details.
  1543. -
  1544. - You should have received a copy of the GNU Lesser General Public
  1545. - License along with the GNU C Library; if not, see
  1546. - <http://www.gnu.org/licenses/>. */
  1547. -
  1548. -#ifdef SHARED
  1549. -/* Redefine time so that the compiler won't complain about the type
  1550. - mismatch with the IFUNC selector in strong_alias, below. */
  1551. -#undef time
  1552. -#define time __redirect_time
  1553. -#include <time.h>
  1554. -
  1555. -#include <dl-vdso.h>
  1556. -
  1557. -#define VSYSCALL_ADDR_vtime 0xffffffffff600400
  1558. -
  1559. -/* Avoid DWARF definition DIE on ifunc symbol so that GDB can handle
  1560. - ifunc symbol properly. */
  1561. -extern __typeof (__redirect_time) __libc_time;
  1562. -void *time_ifunc (void) __asm__ ("__libc_time");
  1563. -
  1564. -void *
  1565. -time_ifunc (void)
  1566. -{
  1567. - PREPARE_VERSION (linux26, "LINUX_2.6", 61765110);
  1568. -
  1569. - /* If the vDSO is not available we fall back on the old vsyscall. */
  1570. - return _dl_vdso_vsym ("__vdso_time", &linux26) ?: (void *) VSYSCALL_ADDR_vtime;
  1571. -}
  1572. -__asm (".type __libc_time, %gnu_indirect_function");
  1573. -
  1574. -#undef time
  1575. -strong_alias (__libc_time, time)
  1576. -libc_hidden_ver (__libc_time, time)
  1577. -
  1578. -#else
  1579. -
  1580. -# include <time.h>
  1581. -# include <sysdep.h>
  1582. -
  1583. -time_t
  1584. -time (time_t *t)
  1585. -{
  1586. - INTERNAL_SYSCALL_DECL (err);
  1587. - return INTERNAL_SYSCALL (time, err, 1, t);
  1588. -}
  1589. -
  1590. -#endif
  1591. diff --git a/sysdeps/unix/sysv/linux/x86_64/vfork.S b/sysdeps/unix/sysv/linux/x86_64/vfork.S
  1592. index d3b450a..75a63e1 100644
  1593. --- a/sysdeps/unix/sysv/linux/x86_64/vfork.S
  1594. +++ b/sysdeps/unix/sysv/linux/x86_64/vfork.S
  1595. @@ -38,7 +38,7 @@ ENTRY (__vfork)
  1596. /* Stuff the syscall number in RAX and enter into the kernel. */
  1597. movl $SYS_ify (vfork), %eax
  1598. - syscall
  1599. + SYSCALLDB
  1600. /* Push back the return PC. */
  1601. pushq %rdi
  1602. diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h
  1603. index 504c95f..dcfc259 100644
  1604. --- a/sysdeps/x86_64/dl-machine.h
  1605. +++ b/sysdeps/x86_64/dl-machine.h
  1606. @@ -529,7 +529,8 @@ elf_machine_lazy_rel (struct link_map *map,
  1607. value = ((ElfW(Addr) (*) (void)) value) ();
  1608. *reloc_addr = value;
  1609. }
  1610. - else
  1611. + /* for graphene, get around R_X86_64_NONE */
  1612. + else if (__builtin_expect (r_type != R_X86_64_NONE, 1))
  1613. _dl_reloc_bad_type (map, r_type, 1);
  1614. }
  1615. diff --git a/sysdeps/x86_64/hp-timing.h b/sysdeps/x86_64/hp-timing.h
  1616. index d88206c..886c500 100644
  1617. --- a/sysdeps/x86_64/hp-timing.h
  1618. +++ b/sysdeps/x86_64/hp-timing.h
  1619. @@ -18,23 +18,6 @@
  1620. #ifndef _HP_TIMING_H
  1621. -/* We can use some of the i686 implementation without changes. */
  1622. -# include <sysdeps/i386/i686/hp-timing.h>
  1623. -
  1624. -/* The "=A" constraint used in 32-bit mode does not work in 64-bit mode. */
  1625. -# undef HP_TIMING_NOW
  1626. -# define HP_TIMING_NOW(Var) \
  1627. - ({ unsigned int _hi, _lo; \
  1628. - asm volatile ("rdtsc" : "=a" (_lo), "=d" (_hi)); \
  1629. - (Var) = ((unsigned long long int) _hi << 32) | _lo; })
  1630. -
  1631. -/* The funny business for 32-bit mode is not required here. */
  1632. -# undef HP_TIMING_ACCUM
  1633. -# define HP_TIMING_ACCUM(Sum, Diff) \
  1634. - do { \
  1635. - hp_timing_t __diff = (Diff) - GLRO(dl_hp_timing_overhead); \
  1636. - __asm__ __volatile__ ("lock; addq %1, %0" \
  1637. - : "=m" (Sum) : "r" (__diff), "m" (Sum)); \
  1638. - } while (0)
  1639. +# include <sysdeps/generic/hp-timing.h>
  1640. #endif /* hp-timing.h */