glibc-2.19.patch 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845
  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..03fbd38 100644
  303. --- a/elf/Versions
  304. +++ b/elf/Versions
  305. @@ -24,14 +24,15 @@ libc {
  306. _dl_sym; _dl_vsym;
  307. __libc_dlclose; __libc_dlopen_mode; __libc_dlsym;
  308. }
  309. + SHIM {
  310. + syscalldb;
  311. + }
  312. }
  313. ld {
  314. GLIBC_2.0 {
  315. # Function from libc.so which must be shared with libc.
  316. __libc_memalign; calloc; free; malloc; realloc;
  317. -
  318. - _r_debug;
  319. }
  320. GLIBC_2.1 {
  321. # functions used in other libraries
  322. @@ -57,9 +58,12 @@ ld {
  323. _rtld_global; _rtld_global_ro;
  324. # Only here for gdb while a better method is developed.
  325. - _dl_debug_state;
  326. + __libc_r_debug; __libc_dl_debug_state;
  327. # Pointer protection.
  328. __pointer_chk_guard;
  329. }
  330. + SHIM {
  331. + syscalldb; glibc_vers_2_17; register_library;
  332. + }
  333. }
  334. diff --git a/elf/circleload1.c b/elf/circleload1.c
  335. index 990ff84..ccf92d3 100644
  336. --- a/elf/circleload1.c
  337. +++ b/elf/circleload1.c
  338. @@ -5,7 +5,7 @@
  339. #include <stdlib.h>
  340. #include <string.h>
  341. -#define MAPS ((struct link_map *) _r_debug.r_map)
  342. +#define MAPS ((struct link_map *) __libc_r_debug.r_map)
  343. static int
  344. check_loaded_objects (const char **loaded)
  345. diff --git a/elf/dl-close.c b/elf/dl-close.c
  346. index 5bf1de7..a887133 100644
  347. --- a/elf/dl-close.c
  348. +++ b/elf/dl-close.c
  349. @@ -473,7 +473,7 @@ _dl_close_worker (struct link_map *map)
  350. /* Notify the debugger we are about to remove some loaded objects. */
  351. struct r_debug *r = _dl_debug_initialize (0, nsid);
  352. r->r_state = RT_DELETE;
  353. - _dl_debug_state ();
  354. + __libc_dl_debug_state ();
  355. LIBC_PROBE (unmap_start, 2, nsid, r);
  356. if (unload_global)
  357. @@ -739,7 +739,7 @@ _dl_close_worker (struct link_map *map)
  358. /* Notify the debugger those objects are finalized and gone. */
  359. r->r_state = RT_CONSISTENT;
  360. - _dl_debug_state ();
  361. + __libc_dl_debug_state ();
  362. LIBC_PROBE (unmap_complete, 2, nsid, r);
  363. /* Recheck if we need to retry, release the lock. */
  364. diff --git a/elf/dl-debug.c b/elf/dl-debug.c
  365. index 4e7c593..3e0bff4 100644
  366. --- a/elf/dl-debug.c
  367. +++ b/elf/dl-debug.c
  368. @@ -34,7 +34,7 @@ extern const int verify_link_map_members[(VERIFY_MEMBER (l_addr)
  369. normally finds it via the DT_DEBUG entry in the dynamic section, but in
  370. a statically-linked program there is no dynamic section for the debugger
  371. to examine and it looks for this particular symbol name. */
  372. -struct r_debug _r_debug;
  373. +struct r_debug __libc_r_debug __attribute__((weak));
  374. /* Initialize _r_debug if it has not already been done. The argument is
  375. @@ -48,7 +48,7 @@ _dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns)
  376. struct r_debug *r;
  377. if (ns == LM_ID_BASE)
  378. - r = &_r_debug;
  379. + r = &__libc_r_debug;
  380. else
  381. r = &GL(dl_ns)[ns]._ns_debug;
  382. @@ -56,9 +56,9 @@ _dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns)
  383. {
  384. /* Tell the debugger where to find the map of loaded objects. */
  385. r->r_version = 1 /* R_DEBUG_VERSION XXX */;
  386. - r->r_ldbase = ldbase ?: _r_debug.r_ldbase;
  387. + r->r_ldbase = ldbase ?: __libc_r_debug.r_ldbase;
  388. r->r_map = (void *) GL(dl_ns)[ns]._ns_loaded;
  389. - r->r_brk = (ElfW(Addr)) &_dl_debug_state;
  390. + r->r_brk = (ElfW(Addr)) &__libc_dl_debug_state;
  391. }
  392. return r;
  393. @@ -70,7 +70,7 @@ _dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns)
  394. examining the r_brk member of struct r_debug, but GDB 4.15 in fact looks
  395. for this particular symbol name in the PT_INTERP file. */
  396. void
  397. -_dl_debug_state (void)
  398. +__libc_dl_debug_state (void)
  399. {
  400. }
  401. -rtld_hidden_def (_dl_debug_state)
  402. +__attribute__((weak));
  403. diff --git a/elf/dl-load.c b/elf/dl-load.c
  404. index 1be7a3c..c560ec1 100644
  405. --- a/elf/dl-load.c
  406. +++ b/elf/dl-load.c
  407. @@ -39,6 +39,8 @@
  408. #include <dl-dst.h>
  409. +#include <glibc-version.h>
  410. +
  411. /* On some systems, no flag bits are given to specify file mapping. */
  412. #ifndef MAP_FILE
  413. # define MAP_FILE 0
  414. @@ -902,7 +904,7 @@ lose (int code, int fd, const char *name, char *realname, struct link_map *l,
  415. if (r != NULL)
  416. {
  417. r->r_state = RT_CONSISTENT;
  418. - _dl_debug_state ();
  419. + __libc_dl_debug_state ();
  420. LIBC_PROBE (map_failed, 2, nsid, r);
  421. }
  422. @@ -1048,7 +1050,7 @@ _dl_map_object_from_fd (const char *name, int fd, struct filebuf *fbp,
  423. call _dl_debug_initialize in a static program in case dynamic
  424. linking has not been used before. */
  425. r->r_state = RT_ADD;
  426. - _dl_debug_state ();
  427. + __libc_dl_debug_state ();
  428. LIBC_PROBE (map_start, 2, nsid, r);
  429. make_consistent = true;
  430. }
  431. @@ -1595,6 +1597,9 @@ cannot enable executable stack as shared object requires");
  432. DL_AFTER_LOAD (l);
  433. #endif
  434. + /* register the library to SHIM */
  435. + register_library(l->l_name, l->l_addr);
  436. +
  437. /* Now that the object is fully initialized add it to the object list. */
  438. _dl_add_to_namespace_list (l, nsid);
  439. diff --git a/elf/dl-open.c b/elf/dl-open.c
  440. index a9ca6b3..829d212 100644
  441. --- a/elf/dl-open.c
  442. +++ b/elf/dl-open.c
  443. @@ -290,7 +290,7 @@ dl_open_worker (void *a)
  444. /* Notify the debugger all new objects are now ready to go. */
  445. struct r_debug *r = _dl_debug_initialize (0, args->nsid);
  446. r->r_state = RT_CONSISTENT;
  447. - _dl_debug_state ();
  448. + __libc_dl_debug_state ();
  449. LIBC_PROBE (map_complete, 3, args->nsid, r, new);
  450. /* Print scope information. */
  451. diff --git a/elf/link.h b/elf/link.h
  452. index d5905d1..f4e108a 100644
  453. --- a/elf/link.h
  454. +++ b/elf/link.h
  455. @@ -64,7 +64,7 @@ struct r_debug
  456. };
  457. /* This is the instance of that structure used by the dynamic linker. */
  458. -extern struct r_debug _r_debug;
  459. +extern struct r_debug __libc_r_debug;
  460. /* This symbol refers to the "dynamic structure" in the `.dynamic' section
  461. of whatever module refers to `_DYNAMIC'. So, to find its own
  462. diff --git a/elf/loadtest.c b/elf/loadtest.c
  463. index 727469b..568ddef 100644
  464. --- a/elf/loadtest.c
  465. +++ b/elf/loadtest.c
  466. @@ -70,7 +70,7 @@ static const struct
  467. #include <include/link.h>
  468. -#define MAPS ((struct link_map *) _r_debug.r_map)
  469. +#define MAPS ((struct link_map *) __libc_r_debug.r_map)
  470. #define OUT \
  471. for (map = MAPS; map != NULL; map = map->l_next) \
  472. diff --git a/elf/neededtest.c b/elf/neededtest.c
  473. index 3cea499..e098d48 100644
  474. --- a/elf/neededtest.c
  475. +++ b/elf/neededtest.c
  476. @@ -5,7 +5,7 @@
  477. #include <stdlib.h>
  478. #include <string.h>
  479. -#define MAPS ((struct link_map *) _r_debug.r_map)
  480. +#define MAPS ((struct link_map *) __libc_r_debug.r_map)
  481. static int
  482. check_loaded_objects (const char **loaded)
  483. diff --git a/elf/neededtest2.c b/elf/neededtest2.c
  484. index 17c75f2..5a73a95 100644
  485. --- a/elf/neededtest2.c
  486. +++ b/elf/neededtest2.c
  487. @@ -5,7 +5,7 @@
  488. #include <stdlib.h>
  489. #include <string.h>
  490. -#define MAPS ((struct link_map *) _r_debug.r_map)
  491. +#define MAPS ((struct link_map *) __libc_r_debug.r_map)
  492. static int
  493. check_loaded_objects (const char **loaded)
  494. diff --git a/elf/neededtest3.c b/elf/neededtest3.c
  495. index 41970cf..5126615 100644
  496. --- a/elf/neededtest3.c
  497. +++ b/elf/neededtest3.c
  498. @@ -5,7 +5,7 @@
  499. #include <stdlib.h>
  500. #include <string.h>
  501. -#define MAPS ((struct link_map *) _r_debug.r_map)
  502. +#define MAPS ((struct link_map *) __libc_r_debug.r_map)
  503. static int
  504. check_loaded_objects (const char **loaded)
  505. diff --git a/elf/neededtest4.c b/elf/neededtest4.c
  506. index 0ae0b7f..f883910 100644
  507. --- a/elf/neededtest4.c
  508. +++ b/elf/neededtest4.c
  509. @@ -5,7 +5,7 @@
  510. #include <stdlib.h>
  511. #include <string.h>
  512. -#define MAPS ((struct link_map *) _r_debug.r_map)
  513. +#define MAPS ((struct link_map *) __libc_r_debug.r_map)
  514. static int
  515. check_loaded_objects (const char **loaded)
  516. diff --git a/elf/rtld.c b/elf/rtld.c
  517. index 6dcbabc..431120a 100644
  518. --- a/elf/rtld.c
  519. +++ b/elf/rtld.c
  520. @@ -356,6 +356,23 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
  521. return start_addr;
  522. }
  523. +/* For graphene, check if glibc version match to the compatible SHIM
  524. + library. If not, tell the user to update glibc. */
  525. +#include "glibc-version.h"
  526. +
  527. +volatile const int glibc_vers_2_17 __attribute__((weak)) = GLIBC_VERSION_2_17;
  528. +
  529. +static void __attribute__((noinline,optimize("-O0")))
  530. +check_glibc_version (void)
  531. +{
  532. + if (glibc_vers_2_17 != GLIBC_VERSION_2_17)
  533. + {
  534. + _dl_fatal_printf ("Warning from Graphene: "
  535. + "Glibc version is incorrect. Please rebuild Glibc.\n");
  536. + _exit (1);
  537. + }
  538. +}
  539. +
  540. static ElfW(Addr) __attribute_used__ internal_function
  541. _dl_start (void *arg)
  542. {
  543. @@ -546,6 +563,9 @@ _dl_start (void *arg)
  544. therefore need not test whether we have to allocate the array
  545. for the relocation results (as done in dl-reloc.c). */
  546. + /* For Graphene, check if the glibc version is correct. */
  547. + check_glibc_version();
  548. +
  549. /* Now life is sane; we can call functions and access global data.
  550. Set up to use the operating system facilities, and find out from
  551. the operating system's program loader where to find the program
  552. @@ -1233,9 +1253,20 @@ of this helper program; chances are you did not intend to run this program.\n\
  553. main_map->l_map_end = allocend;
  554. if ((ph->p_flags & PF_X) && allocend > main_map->l_text_end)
  555. main_map->l_text_end = allocend;
  556. +
  557. +#if 0
  558. + ElfW(Addr) mapend = (allocend + GLRO(dl_pagesize) - 1)
  559. + & ~(GLRO(dl_pagesize) - 1);
  560. + int prot = ((ph->p_flags & PF_R) ? PROT_READ : 0)|
  561. + ((ph->p_flags & PF_W) ? PROT_WRITE : 0)|
  562. + ((ph->p_flags & PF_X) ? PROT_EXEC : 0);
  563. + __mmap ((void *) mapstart, mapend - mapstart,
  564. + prot,
  565. + MAP_ANON|MAP_PRIVATE|MAP_FIXED|0x20000000,
  566. + -1, 0);
  567. +#endif
  568. }
  569. break;
  570. -
  571. case PT_TLS:
  572. if (ph->p_memsz > 0)
  573. {
  574. @@ -1381,13 +1412,31 @@ of this helper program; chances are you did not intend to run this program.\n\
  575. /* PT_GNU_RELRO is usually the last phdr. */
  576. size_t cnt = rtld_ehdr->e_phnum;
  577. while (cnt-- > 0)
  578. + {
  579. if (rtld_phdr[cnt].p_type == PT_GNU_RELRO)
  580. {
  581. GL(dl_rtld_map).l_relro_addr = rtld_phdr[cnt].p_vaddr;
  582. GL(dl_rtld_map).l_relro_size = rtld_phdr[cnt].p_memsz;
  583. - break;
  584. }
  585. +#if 0
  586. + if (rtld_phdr[cnt].p_type == PT_LOAD)
  587. + {
  588. + ElfW(Addr) mapstart = rtld_phdr[cnt].p_vaddr & ~(GLRO(dl_pagesize) - 1);
  589. + ElfW(Addr) mapend = (rtld_phdr[cnt].p_vaddr + rtld_phdr[cnt].p_memsz
  590. + + GLRO(dl_pagesize) - 1)
  591. + & ~(GLRO(dl_pagesize) - 1);
  592. + int prot = ((rtld_phdr[cnt].p_flags & PF_R) ? PROT_READ : 0)|
  593. + ((rtld_phdr[cnt].p_flags & PF_W) ? PROT_WRITE : 0)|
  594. + ((rtld_phdr[cnt].p_flags & PF_X) ? PROT_EXEC : 0);
  595. + __mmap ((void *) mapstart, mapend - mapstart,
  596. + prot,
  597. + MAP_ANON|MAP_PRIVATE|MAP_FIXED|0x20000000,
  598. + -1, 0);
  599. + }
  600. +#endif
  601. + }
  602. +
  603. /* Add the dynamic linker to the TLS list if it also uses TLS. */
  604. if (GL(dl_rtld_map).l_tls_blocksize != 0)
  605. /* Assign a module ID. Do this before loading any audit modules. */
  606. @@ -1588,7 +1637,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
  607. /* We start adding objects. */
  608. r->r_state = RT_ADD;
  609. - _dl_debug_state ();
  610. + __libc_dl_debug_state ();
  611. LIBC_PROBE (init_start, 2, LM_ID_BASE, r);
  612. /* Auditing checkpoint: we are ready to signal that the initial map
  613. @@ -2301,7 +2350,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
  614. the address since by now the variable might be in another object. */
  615. r = _dl_debug_initialize (0, LM_ID_BASE);
  616. r->r_state = RT_CONSISTENT;
  617. - _dl_debug_state ();
  618. + __libc_dl_debug_state ();
  619. LIBC_PROBE (init_complete, 2, LM_ID_BASE, r);
  620. #if defined USE_LDCONFIG && !defined MAP_COPY
  621. diff --git a/elf/unload.c b/elf/unload.c
  622. index 4566f22..73046de 100644
  623. --- a/elf/unload.c
  624. +++ b/elf/unload.c
  625. @@ -9,7 +9,7 @@
  626. #include <stdio.h>
  627. #include <stdlib.h>
  628. -#define MAPS ((struct link_map *) _r_debug.r_map)
  629. +#define MAPS ((struct link_map *) __libc_r_debug.r_map)
  630. #define OUT \
  631. for (map = MAPS; map != NULL; map = map->l_next) \
  632. diff --git a/elf/unload2.c b/elf/unload2.c
  633. index eef2bfd..a21d2ac 100644
  634. --- a/elf/unload2.c
  635. +++ b/elf/unload2.c
  636. @@ -6,7 +6,7 @@
  637. #include <stdio.h>
  638. #include <stdlib.h>
  639. -#define MAPS ((struct link_map *) _r_debug.r_map)
  640. +#define MAPS ((struct link_map *) __libc_r_debug.r_map)
  641. #define OUT \
  642. for (map = MAPS; map != NULL; map = map->l_next) \
  643. diff --git a/nptl/Makefile b/nptl/Makefile
  644. index 57cc8c6..81f1bf4 100644
  645. --- a/nptl/Makefile
  646. +++ b/nptl/Makefile
  647. @@ -20,7 +20,7 @@
  648. #
  649. subdir := nptl
  650. -headers := pthread.h semaphore.h bits/semaphore.h
  651. +headers := pthread.h semaphore.h bits/semaphore.h syscalldb.h
  652. extra-libs := libpthread
  653. extra-libs-others := $(extra-libs)
  654. diff --git a/nptl/Versions b/nptl/Versions
  655. index bb11277..4480543 100644
  656. --- a/nptl/Versions
  657. +++ b/nptl/Versions
  658. @@ -31,6 +31,9 @@ libc {
  659. # Internal libc interface to libpthread
  660. __libc_dl_error_tsd;
  661. }
  662. + SHIM {
  663. + syscalldb;
  664. + }
  665. }
  666. libpthread {
  667. @@ -262,4 +265,8 @@ libpthread {
  668. __pthread_clock_gettime; __pthread_clock_settime;
  669. __pthread_unwind; __pthread_get_minstack;
  670. }
  671. +
  672. + SHIM {
  673. + syscalldb;
  674. + }
  675. }
  676. diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
  677. index 9d7f52f..72d50ae 100644
  678. --- a/nptl/pthread_create.c
  679. +++ b/nptl/pthread_create.c
  680. @@ -405,8 +405,11 @@ start_thread (void *arg)
  681. # error "to do"
  682. #endif
  683. assert (freesize < pd->stackblock_size);
  684. + /* XXX: may not be necessary */
  685. +#if 0
  686. if (freesize > PTHREAD_STACK_MIN)
  687. __madvise (pd->stackblock, freesize - PTHREAD_STACK_MIN, MADV_DONTNEED);
  688. +#endif
  689. /* If the thread is detached free the TCB. */
  690. if (IS_DETACHED (pd))
  691. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S b/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S
  692. index 89fda5e..594dd72 100644
  693. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S
  694. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S
  695. @@ -111,7 +111,8 @@ ENTRY(__pthread_disable_asynccancel)
  696. xorq %r10, %r10
  697. addq $CANCELHANDLING, %rdi
  698. LOAD_PRIVATE_FUTEX_WAIT (%esi)
  699. - syscall
  700. + SYSCALL
  701. +
  702. movl %fs:CANCELHANDLING, %eax
  703. jmp 3b
  704. END(__pthread_disable_asynccancel)
  705. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c b/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c
  706. index a036b92..40a1eaf 100644
  707. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c
  708. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c
  709. @@ -21,10 +21,20 @@
  710. #include <sysdep.h>
  711. #include <tls.h>
  712. -
  713. -#define ARCH_FORK() \
  714. +/* In Graphene, we prefer to call fork system call directly than clone */
  715. +#if USE_clone_FOR_fork
  716. +# define ARCH_FORK() \
  717. INLINE_SYSCALL (clone, 4, \
  718. CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, 0, \
  719. NULL, &THREAD_SELF->tid)
  720. +#else
  721. +# define ARCH_FORK() \
  722. + ({ unsigned long ret = INLINE_SYSCALL (fork, 0); \
  723. + if (!ret) { \
  724. + pid_t pid = INLINE_SYSCALL (getpid, 0); \
  725. + THREAD_SETMEM (THREAD_SELF, pid, pid); \
  726. + THREAD_SETMEM (THREAD_SELF, tid, pid); \
  727. + } ret; })
  728. +#endif
  729. #include "../fork.c"
  730. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
  731. index f2dca07..e5b3f2f 100644
  732. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
  733. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
  734. @@ -90,7 +90,7 @@ __lll_lock_wait_private:
  735. 1: LIBC_PROBE (lll_lock_wait_private, 1, %rdi)
  736. movl $SYS_futex, %eax
  737. - syscall
  738. + SYSCALL
  739. 2: movl %edx, %eax
  740. xchgl %eax, (%rdi) /* NB: lock is implied */
  741. @@ -130,7 +130,7 @@ __lll_lock_wait:
  742. 1: LIBC_PROBE (lll_lock_wait, 2, %rdi, %rsi)
  743. movl $SYS_futex, %eax
  744. - syscall
  745. + SYSCALL
  746. 2: movl %edx, %eax
  747. xchgl %eax, (%rdi) /* NB: lock is implied */
  748. @@ -185,7 +185,7 @@ __lll_timedlock_wait:
  749. 1: movl $SYS_futex, %eax
  750. movl $2, %edx
  751. - syscall
  752. + SYSCALL
  753. 2: xchgl %edx, (%rdi) /* NB: lock is implied */
  754. @@ -279,7 +279,7 @@ __lll_timedlock_wait:
  755. LOAD_FUTEX_WAIT (%esi)
  756. movq %r12, %rdi
  757. movl $SYS_futex, %eax
  758. - syscall
  759. + SYSCALL
  760. /* NB: %edx == 2 */
  761. xchgl %edx, (%r12)
  762. @@ -336,7 +336,7 @@ __lll_unlock_wake_private:
  763. LOAD_PRIVATE_FUTEX_WAKE (%esi)
  764. movl $1, %edx /* Wake one thread. */
  765. movl $SYS_futex, %eax
  766. - syscall
  767. + SYSCALL
  768. popq %rdx
  769. cfi_adjust_cfa_offset(-8)
  770. @@ -366,7 +366,7 @@ __lll_unlock_wake:
  771. LOAD_FUTEX_WAKE (%esi)
  772. movl $1, %edx /* Wake one thread. */
  773. movl $SYS_futex, %eax
  774. - syscall
  775. + SYSCALL
  776. popq %rdx
  777. cfi_adjust_cfa_offset(-8)
  778. @@ -435,7 +435,7 @@ __lll_timedwait_tid:
  779. #endif
  780. movq %r12, %rdi
  781. movl $SYS_futex, %eax
  782. - syscall
  783. + SYSCALL
  784. cmpl $0, (%rdi)
  785. jne 1f
  786. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
  787. index 0a26739..8aae14a 100644
  788. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
  789. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
  790. @@ -214,7 +214,7 @@ LLL_STUB_UNWIND_INFO_END
  791. register const struct timespec *__to __asm ("r10") = timeout; \
  792. int __status; \
  793. register __typeof (val) _val __asm ("edx") = (val); \
  794. - __asm __volatile ("syscall" \
  795. + __asm __volatile (SYSCALLDB \
  796. : "=a" (__status) \
  797. : "0" (SYS_futex), "D" (futex), \
  798. "S" (__lll_private_flag (FUTEX_WAIT, private)), \
  799. @@ -229,7 +229,7 @@ LLL_STUB_UNWIND_INFO_END
  800. int __status; \
  801. register __typeof (nr) _nr __asm ("edx") = (nr); \
  802. LIBC_PROBE (lll_futex_wake, 3, futex, nr, private); \
  803. - __asm __volatile ("syscall" \
  804. + __asm __volatile (SYSCALLDB \
  805. : "=a" (__status) \
  806. : "0" (SYS_futex), "D" (futex), \
  807. "S" (__lll_private_flag (FUTEX_WAKE, private)), \
  808. @@ -540,7 +540,7 @@ extern int __lll_timedlock_elision (int *futex, short *adapt_count,
  809. { \
  810. int ignore; \
  811. __asm __volatile (LOCK_INSTR "orl %3, (%2)\n\t" \
  812. - "syscall" \
  813. + SYSCALLDB \
  814. : "=m" (futex), "=a" (ignore) \
  815. : "D" (&(futex)), "i" (FUTEX_OWNER_DIED), \
  816. "S" (__lll_private_flag (FUTEX_WAKE, private)), \
  817. @@ -555,7 +555,7 @@ extern int __lll_timedlock_elision (int *futex, short *adapt_count,
  818. register int __nr_move __asm ("r10") = nr_move; \
  819. register void *__mutex __asm ("r8") = mutex; \
  820. register int __val __asm ("r9") = val; \
  821. - __asm __volatile ("syscall" \
  822. + __asm __volatile (SYSCALLDB \
  823. : "=a" (__res) \
  824. : "0" (__NR_futex), "D" ((void *) ftx), \
  825. "S" (__lll_private_flag (FUTEX_CMP_REQUEUE, \
  826. @@ -581,7 +581,7 @@ extern int __lll_timedlock_elision (int *futex, short *adapt_count,
  827. if (_tid != 0) \
  828. __asm __volatile ("xorq %%r10, %%r10\n\t" \
  829. "1:\tmovq %2, %%rax\n\t" \
  830. - "syscall\n\t" \
  831. + SYSCALLDB \
  832. "cmpl $0, (%%rdi)\n\t" \
  833. "jne 1b" \
  834. : "=&a" (__ignore) \
  835. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
  836. index 990b6f9..89dbe32 100644
  837. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
  838. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
  839. @@ -80,7 +80,7 @@ __lll_robust_lock_wait:
  840. jnz 2f
  841. 1: movl $SYS_futex, %eax
  842. - syscall
  843. + SYSCALL
  844. movl (%rdi), %eax
  845. @@ -145,7 +145,7 @@ __lll_robust_timedlock_wait:
  846. jnz 6f
  847. 5: movl $SYS_futex, %eax
  848. - syscall
  849. + SYSCALL
  850. movl %eax, %ecx
  851. movl (%rdi), %eax
  852. @@ -257,7 +257,7 @@ __lll_robust_timedlock_wait:
  853. LOAD_FUTEX_WAIT (%esi)
  854. movq %r12, %rdi
  855. movl $SYS_futex, %eax
  856. - syscall
  857. + SYSCALL
  858. movq %rax, %rcx
  859. movl (%r12), %eax
  860. 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
  861. index eec17f2..4472960 100644
  862. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S
  863. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S
  864. @@ -62,7 +62,7 @@ pthread_barrier_wait:
  865. #endif
  866. xorq %r10, %r10
  867. 8: movl $SYS_futex, %eax
  868. - syscall
  869. + SYSCALL
  870. /* Don't return on spurious wakeups. The syscall does not change
  871. any register except %eax so there is no need to reload any of
  872. @@ -109,7 +109,7 @@ pthread_barrier_wait:
  873. movl $FUTEX_WAKE, %esi
  874. orl PRIVATE(%rdi), %esi
  875. movl $SYS_futex, %eax
  876. - syscall
  877. + SYSCALL
  878. /* Increment LEFT. If this brings the count back to the
  879. initial count unlock the object. */
  880. 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
  881. index 985e0f1..f180ab1 100644
  882. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
  883. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
  884. @@ -90,7 +90,7 @@ __pthread_cond_broadcast:
  885. movl $SYS_futex, %eax
  886. movl $1, %edx
  887. movl $0x7fffffff, %r10d
  888. - syscall
  889. + SYSCALL
  890. /* For any kind of error, which mainly is EAGAIN, we try again
  891. with WAKE. The general test also covers running on old
  892. @@ -106,7 +106,7 @@ __pthread_cond_broadcast:
  893. movl $SYS_futex, %eax
  894. movl $1, %edx
  895. movl $0x7fffffff, %r10d
  896. - syscall
  897. + SYSCALL
  898. /* For any kind of error, which mainly is EAGAIN, we try again
  899. with WAKE. The general test also covers running on old
  900. @@ -172,7 +172,7 @@ __pthread_cond_broadcast:
  901. orl $FUTEX_WAKE, %esi
  902. #endif
  903. movl $SYS_futex, %eax
  904. - syscall
  905. + SYSCALL
  906. jmp 10b
  907. .size __pthread_cond_broadcast, .-__pthread_cond_broadcast
  908. versioned_symbol (libpthread, __pthread_cond_broadcast, pthread_cond_broadcast,
  909. 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
  910. index 53d65b6..8724325 100644
  911. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
  912. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
  913. @@ -82,7 +82,7 @@ __pthread_cond_signal:
  914. addq $cond_lock, %r8
  915. #endif
  916. movl $FUTEX_OP_CLEAR_WAKE_IF_GT_ONE, %r9d
  917. - syscall
  918. + SYSCALL
  919. #if cond_lock != 0
  920. subq $cond_lock, %r8
  921. #endif
  922. @@ -99,7 +99,7 @@ __pthread_cond_signal:
  923. movq %rcx, %r8
  924. xorq %r10, %r10
  925. movl (%rdi), %r9d // XXX Can this be right?
  926. - syscall
  927. + SYSCALL
  928. leaq -cond_futex(%rdi), %r8
  929. @@ -118,7 +118,7 @@ __pthread_cond_signal:
  930. movl $SYS_futex, %eax
  931. /* %rdx should be 1 already from $FUTEX_WAKE_OP syscall.
  932. movl $1, %edx */
  933. - syscall
  934. + SYSCALL
  935. /* Unlock. */
  936. 4: LOCK
  937. 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
  938. index 0dc2340..cac13bf 100644
  939. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
  940. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
  941. @@ -188,7 +188,7 @@ __pthread_cond_timedwait:
  942. movq %r12, %rdx
  943. addq $cond_futex, %rdi
  944. movl $SYS_futex, %eax
  945. - syscall
  946. + SYSCALL
  947. cmpl $0, %eax
  948. sete %r15b
  949. @@ -234,7 +234,7 @@ __pthread_cond_timedwait:
  950. movq %r12, %rdx
  951. addq $cond_futex, %rdi
  952. movl $SYS_futex, %eax
  953. - syscall
  954. + SYSCALL
  955. 62: movq %rax, %r14
  956. movl (%rsp), %edi
  957. @@ -321,7 +321,7 @@ __pthread_cond_timedwait:
  958. orl $FUTEX_WAKE, %esi
  959. #endif
  960. movl $SYS_futex, %eax
  961. - syscall
  962. + SYSCALL
  963. subq $cond_nwaiters, %rdi
  964. 55: LOCK
  965. @@ -485,15 +485,8 @@ __pthread_cond_timedwait:
  966. /* Only clocks 0 and 1 are allowed so far. Both are handled in the
  967. kernel. */
  968. leaq 32(%rsp), %rsi
  969. -# ifdef SHARED
  970. - mov __vdso_clock_gettime@GOTPCREL(%rip), %RAX_LP
  971. - mov (%rax), %RAX_LP
  972. - PTR_DEMANGLE (%RAX_LP)
  973. - call *%rax
  974. -# else
  975. movl $__NR_clock_gettime, %eax
  976. - syscall
  977. -# endif
  978. + SYSCALL
  979. /* Compute relative timeout. */
  980. movq (%r13), %rcx
  981. @@ -560,7 +553,7 @@ __pthread_cond_timedwait:
  982. # endif
  983. addq $cond_futex, %rdi
  984. movl $SYS_futex, %eax
  985. - syscall
  986. + SYSCALL
  987. movq %rax, %r14
  988. movl (%rsp), %edi
  989. @@ -732,7 +725,7 @@ __condvar_cleanup2:
  990. orl $FUTEX_WAKE, %esi
  991. #endif
  992. movl $SYS_futex, %eax
  993. - syscall
  994. + SYSCALL
  995. subq $cond_nwaiters, %rdi
  996. movl $1, %r12d
  997. @@ -769,7 +762,7 @@ __condvar_cleanup2:
  998. orl $FUTEX_WAKE, %esi
  999. #endif
  1000. movl $SYS_futex, %eax
  1001. - syscall
  1002. + SYSCALL
  1003. /* Lock the mutex only if we don't own it already. This only happens
  1004. in case of PI mutexes, if we got cancelled after a successful
  1005. 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
  1006. index 0e61d0a..60e104b 100644
  1007. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
  1008. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
  1009. @@ -138,7 +138,7 @@ __pthread_cond_wait:
  1010. movl $(FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %esi
  1011. movl $SYS_futex, %eax
  1012. - syscall
  1013. + SYSCALL
  1014. cmpl $0, %eax
  1015. sete %r8b
  1016. @@ -180,7 +180,7 @@ __pthread_cond_wait:
  1017. #endif
  1018. 60: xorb %r8b, %r8b
  1019. movl $SYS_futex, %eax
  1020. - syscall
  1021. + SYSCALL
  1022. 62: movl (%rsp), %edi
  1023. callq __pthread_disable_asynccancel
  1024. @@ -239,7 +239,7 @@ __pthread_cond_wait:
  1025. orl $FUTEX_WAKE, %esi
  1026. #endif
  1027. movl $SYS_futex, %eax
  1028. - syscall
  1029. + SYSCALL
  1030. subq $cond_nwaiters, %rdi
  1031. 17: LOCK
  1032. @@ -455,7 +455,7 @@ __condvar_cleanup1:
  1033. orl $FUTEX_WAKE, %esi
  1034. #endif
  1035. movl $SYS_futex, %eax
  1036. - syscall
  1037. + SYSCALL
  1038. subq $cond_nwaiters, %rdi
  1039. movl $1, %ecx
  1040. @@ -493,7 +493,7 @@ __condvar_cleanup1:
  1041. orl $FUTEX_WAKE, %esi
  1042. #endif
  1043. movl $SYS_futex, %eax
  1044. - syscall
  1045. + SYSCALL
  1046. /* Lock the mutex only if we don't own it already. This only happens
  1047. in case of PI mutexes, if we got cancelled after a successful
  1048. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
  1049. index 2cbe2fa..d4e229a 100644
  1050. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
  1051. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
  1052. @@ -90,7 +90,7 @@ __pthread_once:
  1053. # endif
  1054. #endif
  1055. movl $SYS_futex, %eax
  1056. - syscall
  1057. + SYSCALL
  1058. jmp 6b
  1059. /* Preserve the pointer to the control variable. */
  1060. @@ -123,7 +123,7 @@ __pthread_once:
  1061. orl %fs:PRIVATE_FUTEX, %esi
  1062. #endif
  1063. movl $SYS_futex, %eax
  1064. - syscall
  1065. + SYSCALL
  1066. 4: addq $8, %rsp
  1067. cfi_adjust_cfa_offset(-8)
  1068. @@ -152,7 +152,7 @@ clear_once_control:
  1069. orl %fs:PRIVATE_FUTEX, %esi
  1070. #endif
  1071. movl $SYS_futex, %eax
  1072. - syscall
  1073. + SYSCALL
  1074. movq %r8, %rdi
  1075. .LcallUR:
  1076. 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
  1077. index 3bbb4c7..8ebf317 100644
  1078. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S
  1079. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S
  1080. @@ -82,7 +82,7 @@ __pthread_rwlock_rdlock:
  1081. #endif
  1082. addq $READERS_WAKEUP, %rdi
  1083. movl $SYS_futex, %eax
  1084. - syscall
  1085. + SYSCALL
  1086. subq $READERS_WAKEUP, %rdi
  1087. 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
  1088. index 40bcc04..d6c9c82 100644
  1089. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
  1090. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
  1091. @@ -109,7 +109,7 @@ pthread_rwlock_timedrdlock:
  1092. #endif
  1093. 21: leaq READERS_WAKEUP(%r12), %rdi
  1094. movl $SYS_futex, %eax
  1095. - syscall
  1096. + SYSCALL
  1097. movq %rax, %rdx
  1098. #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
  1099. 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
  1100. index f57ef52..78a2655 100644
  1101. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
  1102. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
  1103. @@ -106,7 +106,7 @@ pthread_rwlock_timedwrlock:
  1104. #endif
  1105. 21: leaq WRITERS_WAKEUP(%r12), %rdi
  1106. movl $SYS_futex, %eax
  1107. - syscall
  1108. + SYSCALL
  1109. movq %rax, %rdx
  1110. #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
  1111. 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
  1112. index d779f7b..4dec0c0 100644
  1113. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S
  1114. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S
  1115. @@ -79,7 +79,7 @@ __pthread_rwlock_unlock:
  1116. #endif
  1117. movl $SYS_futex, %eax
  1118. movq %r10, %rdi
  1119. - syscall
  1120. + SYSCALL
  1121. xorl %eax, %eax
  1122. retq
  1123. 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
  1124. index e444def..ba31821 100644
  1125. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S
  1126. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S
  1127. @@ -80,7 +80,7 @@ __pthread_rwlock_wrlock:
  1128. #endif
  1129. addq $WRITERS_WAKEUP, %rdi
  1130. movl $SYS_futex, %eax
  1131. - syscall
  1132. + SYSCALL
  1133. subq $WRITERS_WAKEUP, %rdi
  1134. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
  1135. index 1c11600..d276efa 100644
  1136. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
  1137. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
  1138. @@ -52,7 +52,7 @@ sem_post:
  1139. movl $FUTEX_WAKE, %esi
  1140. orl PRIVATE(%rdi), %esi
  1141. movl $1, %edx
  1142. - syscall
  1143. + SYSCALL
  1144. testq %rax, %rax
  1145. js 1f
  1146. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
  1147. index 880610e..06fd57c 100644
  1148. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
  1149. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
  1150. @@ -97,7 +97,7 @@ sem_timedwait:
  1151. orl PRIVATE(%rdi), %esi
  1152. movl $SYS_futex, %eax
  1153. xorl %edx, %edx
  1154. - syscall
  1155. + SYSCALL
  1156. movq %rax, %r9
  1157. #if VALUE != 0
  1158. leaq -VALUE(%rdi), %rdi
  1159. @@ -233,7 +233,7 @@ sem_timedwait:
  1160. # endif
  1161. movl $SYS_futex, %eax
  1162. xorl %edx, %edx
  1163. - syscall
  1164. + SYSCALL
  1165. movq %rax, %r14
  1166. movl 16(%rsp), %edi
  1167. diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
  1168. index 8f4d068..d9b49e4 100644
  1169. --- a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
  1170. +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
  1171. @@ -81,7 +81,7 @@ sem_wait:
  1172. orl PRIVATE(%rdi), %esi
  1173. #endif
  1174. xorl %edx, %edx
  1175. - syscall
  1176. + SYSCALL
  1177. movq %rax, %rcx
  1178. xchgq %r8, %rdi
  1179. diff --git a/nptl/sysdeps/x86_64/pthreaddef.h b/nptl/sysdeps/x86_64/pthreaddef.h
  1180. index 18a15a1..ac3d6d3 100644
  1181. --- a/nptl/sysdeps/x86_64/pthreaddef.h
  1182. +++ b/nptl/sysdeps/x86_64/pthreaddef.h
  1183. @@ -48,4 +48,5 @@
  1184. /* While there is no such syscall. */
  1185. #define __exit_thread_inline(val) \
  1186. - asm volatile ("syscall" :: "a" (__NR_exit), "D" (val))
  1187. + asm volatile ("pushq %%rbx\n\tmovq syscalldb@GOTPCREL(%%rip), %%rbx\n\t" \
  1188. + "call %%rbx\n\t" :: "a" (__NR_exit), "D" (val) : "bx" )
  1189. diff --git a/nptl/sysdeps/x86_64/tls.h b/nptl/sysdeps/x86_64/tls.h
  1190. index cbb5e9e..19b18ef 100644
  1191. --- a/nptl/sysdeps/x86_64/tls.h
  1192. +++ b/nptl/sysdeps/x86_64/tls.h
  1193. @@ -28,6 +28,7 @@
  1194. # include <sysdep.h>
  1195. # include <libc-internal.h>
  1196. # include <kernel-features.h>
  1197. +# include <shim_tls.h>
  1198. /* Replacement type for __m128 since this file is included by ld.so,
  1199. which is compiled with -mno-sse. It must not change the alignment
  1200. @@ -67,6 +68,10 @@ typedef struct
  1201. # else
  1202. int __glibc_reserved1;
  1203. # endif
  1204. +
  1205. + shim_tcb_t shim_tcb; /* For graphene, we allocate a shim_tcb
  1206. + in the real tcb. */
  1207. +
  1208. int rtld_must_xmm_save;
  1209. /* Reservation of some values for the TM ABI. */
  1210. void *__private_tm[4];
  1211. @@ -137,6 +142,12 @@ typedef struct
  1212. # define GET_DTV(descr) \
  1213. (((tcbhead_t *) (descr))->dtv)
  1214. +/* For Graphene */
  1215. +#define SYSCALLDB \
  1216. + "pushq %%rbx\n\t" \
  1217. + "movq syscalldb@GOTPCREL(%%rip), %%rbx\n\t" \
  1218. + "callq *%%rbx\n\t" \
  1219. + "popq %%rbx\n\t"
  1220. /* Code to initially initialize the thread pointer. This might need
  1221. special attention since 'errno' is not yet available and if the
  1222. @@ -154,7 +165,7 @@ typedef struct
  1223. _head->self = _thrdescr; \
  1224. \
  1225. /* It is a simple syscall to set the %fs value for the thread. */ \
  1226. - asm volatile ("syscall" \
  1227. + asm volatile (SYSCALLDB \
  1228. : "=a" (_result) \
  1229. : "0" ((unsigned long int) __NR_arch_prctl), \
  1230. "D" ((unsigned long int) ARCH_SET_FS), \
  1231. diff --git a/scripts/mkinstalldirs b/scripts/mkinstalldirs
  1232. index 55d537f..57bf12b 100755
  1233. --- a/scripts/mkinstalldirs
  1234. +++ b/scripts/mkinstalldirs
  1235. @@ -126,9 +126,9 @@ do
  1236. esac
  1237. if test ! -d "$pathcomp"; then
  1238. - echo "mkdir $pathcomp"
  1239. + echo "mkdir -p $pathcomp"
  1240. - mkdir "$pathcomp" || lasterr=$?
  1241. + mkdir -p "$pathcomp" || lasterr=$?
  1242. if test ! -d "$pathcomp"; then
  1243. errstatus=$lasterr
  1244. diff --git a/shlib-versions b/shlib-versions
  1245. index 78b0ad7..5c3dcf2 100644
  1246. --- a/shlib-versions
  1247. +++ b/shlib-versions
  1248. @@ -108,3 +108,5 @@ sparc64.*-.*-.* libBrokenLocale=1 GLIBC_2.2
  1249. # This defines the libgcc soname version this glibc is to load for
  1250. # asynchronous cancellation to work correctly.
  1251. .*-.*-.* libgcc_s=1
  1252. +
  1253. +.*-.*-.* liblibos=1
  1254. diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
  1255. index ffeb093..7a9fbcb 100644
  1256. --- a/sysdeps/generic/ldsodefs.h
  1257. +++ b/sysdeps/generic/ldsodefs.h
  1258. @@ -881,8 +881,7 @@ extern void _dl_sort_fini (struct link_map **maps, size_t nmaps, char *used,
  1259. any shared object mappings. The `r_state' member of `struct r_debug'
  1260. says what change is taking place. This function's address is
  1261. the value of the `r_brk' member. */
  1262. -extern void _dl_debug_state (void);
  1263. -rtld_hidden_proto (_dl_debug_state)
  1264. +extern void __libc_dl_debug_state (void) __attribute__((weak));
  1265. /* Initialize `struct r_debug' if it has not already been done. The
  1266. argument is the run-time load address of the dynamic linker, to be put
  1267. diff --git a/sysdeps/unix/sysv/linux/_exit.c b/sysdeps/unix/sysv/linux/_exit.c
  1268. index 2468228..a9f1cd6 100644
  1269. --- a/sysdeps/unix/sysv/linux/_exit.c
  1270. +++ b/sysdeps/unix/sysv/linux/_exit.c
  1271. @@ -29,9 +29,9 @@ _exit (status)
  1272. while (1)
  1273. {
  1274. #ifdef __NR_exit_group
  1275. - INLINE_SYSCALL (exit_group, 1, status);
  1276. + INLINE_SYSCALL_ASM (exit_group, 1, status);
  1277. #endif
  1278. - INLINE_SYSCALL (exit, 1, status);
  1279. + INLINE_SYSCALL_ASM (exit, 1, status);
  1280. #ifdef ABORT_INSTRUCTION
  1281. ABORT_INSTRUCTION;
  1282. diff --git a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
  1283. index 49f0384..ee59c00 100644
  1284. --- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
  1285. +++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
  1286. @@ -84,7 +84,8 @@ ENTRY(____longjmp_chk)
  1287. xorl %edi, %edi
  1288. lea -sizeSS(%rsp), %RSI_LP
  1289. movl $__NR_sigaltstack, %eax
  1290. - syscall
  1291. + SYSCALL
  1292. +
  1293. /* Without working sigaltstack we cannot perform the test. */
  1294. testl %eax, %eax
  1295. jne .Lok2
  1296. diff --git a/sysdeps/unix/sysv/linux/x86_64/clock_gettime.c b/sysdeps/unix/sysv/linux/x86_64/clock_gettime.c
  1297. index f712110..f6bad14 100644
  1298. --- a/sysdeps/unix/sysv/linux/x86_64/clock_gettime.c
  1299. +++ b/sysdeps/unix/sysv/linux/x86_64/clock_gettime.c
  1300. @@ -1,5 +1,6 @@
  1301. #include "bits/libc-vdso.h"
  1302. +#if 0 /* in Graphene, disallow VDSO calls */
  1303. #ifdef SHARED
  1304. # define SYSCALL_GETTIME(id, tp) \
  1305. ({ long int (*f) (clockid_t, struct timespec *) = __vdso_clock_gettime; \
  1306. @@ -16,5 +17,6 @@
  1307. PTR_DEMANGLE (f); \
  1308. f (id, tp); })
  1309. #endif
  1310. +#endif
  1311. #include "../clock_gettime.c"
  1312. diff --git a/sysdeps/unix/sysv/linux/x86_64/clone.S b/sysdeps/unix/sysv/linux/x86_64/clone.S
  1313. index 0508730..c011e7a 100644
  1314. --- a/sysdeps/unix/sysv/linux/x86_64/clone.S
  1315. +++ b/sysdeps/unix/sysv/linux/x86_64/clone.S
  1316. @@ -59,11 +59,15 @@ ENTRY (__clone)
  1317. jz SYSCALL_ERROR_LABEL
  1318. /* Insert the argument onto the new stack. */
  1319. - subq $16,%rsi
  1320. - movq %rcx,8(%rsi)
  1321. + subq $24,%rsi
  1322. + movq %rcx,16(%rsi)
  1323. /* Save the function pointer. It will be popped off in the
  1324. child in the ebx frobbing below. */
  1325. + movq %rdi,8(%rsi)
  1326. +
  1327. + /* Push an additional pointer as return address into the stack */
  1328. + leaq L(clone_return)(%rip),%rdi
  1329. movq %rdi,0(%rsi)
  1330. /* Do the system call. */
  1331. @@ -76,8 +80,9 @@ ENTRY (__clone)
  1332. /* End FDE now, because in the child the unwind info will be
  1333. wrong. */
  1334. cfi_endproc;
  1335. - syscall
  1336. + SYSCALL
  1337. +L(clone_return):
  1338. testq %rax,%rax
  1339. jl SYSCALL_ERROR_LABEL
  1340. jz L(thread_start)
  1341. @@ -99,13 +104,14 @@ L(thread_start):
  1342. movl $-1, %eax
  1343. jne 2f
  1344. movl $SYS_ify(getpid), %eax
  1345. - syscall
  1346. + SYSCALL
  1347. 2: movl %eax, %fs:PID
  1348. movl %eax, %fs:TID
  1349. 1:
  1350. #endif
  1351. /* Set up arguments for the function call. */
  1352. + addq $8,%rsp /* Skip the return address */
  1353. popq %rax /* Function to call. */
  1354. popq %rdi /* Argument. */
  1355. call *%rax
  1356. diff --git a/sysdeps/unix/sysv/linux/x86_64/getcontext.S b/sysdeps/unix/sysv/linux/x86_64/getcontext.S
  1357. index 140db03..870fb02 100644
  1358. --- a/sysdeps/unix/sysv/linux/x86_64/getcontext.S
  1359. +++ b/sysdeps/unix/sysv/linux/x86_64/getcontext.S
  1360. @@ -75,7 +75,7 @@ ENTRY(__getcontext)
  1361. #endif
  1362. movl $_NSIG8,%r10d
  1363. movl $__NR_rt_sigprocmask, %eax
  1364. - syscall
  1365. + SYSCALL
  1366. cmpq $-4095, %rax /* Check %rax for error. */
  1367. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  1368. diff --git a/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c b/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c
  1369. index 440ca7f..571125d 100644
  1370. --- a/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c
  1371. +++ b/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c
  1372. @@ -17,6 +17,7 @@
  1373. #include <sys/time.h>
  1374. +#if 0 /* In graphene, do not use vsyscall or VDSO call */
  1375. #ifdef SHARED
  1376. # include <dl-vdso.h>
  1377. @@ -42,7 +43,8 @@ asm (".type __gettimeofday, %gnu_indirect_function");
  1378. asm (".globl __GI___gettimeofday\n"
  1379. "__GI___gettimeofday = __gettimeofday");
  1380. -#else
  1381. +#endif
  1382. +#endif
  1383. # include <sysdep.h>
  1384. # include <errno.h>
  1385. @@ -54,6 +56,5 @@ __gettimeofday (struct timeval *tv, struct timezone *tz)
  1386. }
  1387. libc_hidden_def (__gettimeofday)
  1388. -#endif
  1389. weak_alias (__gettimeofday, gettimeofday)
  1390. libc_hidden_weak (gettimeofday)
  1391. diff --git a/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S b/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
  1392. index 0fd47f2..0247e2f 100644
  1393. --- a/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
  1394. +++ b/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
  1395. @@ -30,6 +30,7 @@ ENTRY (sched_getcpu)
  1396. sub $0x8, %rsp
  1397. cfi_adjust_cfa_offset(8)
  1398. +#if 0 /* for Graphene, never do VDSO calls */
  1399. movq %rsp, %rdi
  1400. xorl %esi, %esi
  1401. movl $VGETCPU_CACHE_OFFSET, %edx
  1402. @@ -39,16 +40,19 @@ ENTRY (sched_getcpu)
  1403. movq __vdso_getcpu(%rip), %rax
  1404. PTR_DEMANGLE (%rax)
  1405. callq *%rax
  1406. -#else
  1407. -# ifdef __NR_getcpu
  1408. +#endif
  1409. +#endif
  1410. +
  1411. +#ifdef __NR_getcpu
  1412. movl $__NR_getcpu, %eax
  1413. - syscall
  1414. -# ifndef __ASSUME_GETCPU_SYSCALL
  1415. + SYSCALL
  1416. +#endif
  1417. +
  1418. +#if 0 /* for Graphene, never do vsyscall */
  1419. +# ifndef __ASSUME_GETCPU_SYSCALL
  1420. cmpq $-ENOSYS, %rax
  1421. jne 1f
  1422. -# endif
  1423. -# endif
  1424. -# ifndef __ASSUME_GETCPU_SYSCALL
  1425. +
  1426. movq $VSYSCALL_ADDR_vgetcpu, %rax
  1427. callq *%rax
  1428. 1:
  1429. diff --git a/sysdeps/unix/sysv/linux/x86_64/setcontext.S b/sysdeps/unix/sysv/linux/x86_64/setcontext.S
  1430. index b726fa0..96bf0ec 100644
  1431. --- a/sysdeps/unix/sysv/linux/x86_64/setcontext.S
  1432. +++ b/sysdeps/unix/sysv/linux/x86_64/setcontext.S
  1433. @@ -43,7 +43,7 @@ ENTRY(__setcontext)
  1434. movl $SIG_SETMASK, %edi
  1435. movl $_NSIG8,%r10d
  1436. movl $__NR_rt_sigprocmask, %eax
  1437. - syscall
  1438. + SYSCALL
  1439. popq %rdi /* Reload %rdi, adjust stack. */
  1440. cfi_adjust_cfa_offset(-8)
  1441. cmpq $-4095, %rax /* Check %rax for error. */
  1442. diff --git a/sysdeps/unix/sysv/linux/x86_64/sigaction.c b/sysdeps/unix/sysv/linux/x86_64/sigaction.c
  1443. index ab23985..39d0bdc 100644
  1444. --- a/sysdeps/unix/sysv/linux/x86_64/sigaction.c
  1445. +++ b/sysdeps/unix/sysv/linux/x86_64/sigaction.c
  1446. @@ -129,7 +129,8 @@ asm \
  1447. " .type __" #name ",@function\n" \
  1448. "__" #name ":\n" \
  1449. " movq $" #syscall ", %rax\n" \
  1450. - " syscall\n" \
  1451. + " movq syscalldb@GOTPCREL(%rip), %rbx\n" \
  1452. + " call *%rbx\n" \
  1453. ".LEND_" #name ":\n" \
  1454. ".section .eh_frame,\"a\",@progbits\n" \
  1455. ".LSTARTFRAME_" #name ":\n" \
  1456. diff --git a/sysdeps/unix/sysv/linux/x86_64/swapcontext.S b/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
  1457. index b3854fa..fd42f66 100644
  1458. --- a/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
  1459. +++ b/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
  1460. @@ -75,7 +75,7 @@ ENTRY(__swapcontext)
  1461. movl $SIG_SETMASK, %edi
  1462. movl $_NSIG8,%r10d
  1463. movl $__NR_rt_sigprocmask, %eax
  1464. - syscall
  1465. + SYSCALL
  1466. cmpq $-4095, %rax /* Check %rax for error. */
  1467. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  1468. diff --git a/sysdeps/unix/sysv/linux/x86_64/syscall.S b/sysdeps/unix/sysv/linux/x86_64/syscall.S
  1469. index 92c2f5b..7b7ee12 100644
  1470. --- a/sysdeps/unix/sysv/linux/x86_64/syscall.S
  1471. +++ b/sysdeps/unix/sysv/linux/x86_64/syscall.S
  1472. @@ -34,7 +34,7 @@ ENTRY (syscall)
  1473. movq %r8, %r10
  1474. movq %r9, %r8
  1475. movq 8(%rsp),%r9 /* arg6 is on the stack. */
  1476. - syscall /* Do the system call. */
  1477. + SYSCALL /* Do the system call. */
  1478. cmpq $-4095, %rax /* Check %rax for error. */
  1479. jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */
  1480. ret /* Return to caller. */
  1481. diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
  1482. index 4a9a9d9..3b7434d 100644
  1483. --- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
  1484. +++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
  1485. @@ -21,6 +21,7 @@
  1486. /* There is some commonality. */
  1487. #include <sysdeps/unix/x86_64/sysdep.h>
  1488. #include <tls.h>
  1489. +#include "syscalldb.h"
  1490. #ifdef IS_IN_rtld
  1491. # include <dl-sysdep.h> /* Defines RTLD_PRIVATE_ERRNO. */
  1492. @@ -172,11 +173,18 @@
  1493. Syscalls of more than 6 arguments are not supported. */
  1494. +# undef SYSCALL
  1495. +# define SYSCALL \
  1496. + pushq %rbx; \
  1497. + movq syscalldb@GOTPCREL(%rip), %rbx; \
  1498. + call *%rbx; \
  1499. + popq %rbx;
  1500. +
  1501. # undef DO_CALL
  1502. # define DO_CALL(syscall_name, args) \
  1503. DOARGS_##args \
  1504. movl $SYS_ify (syscall_name), %eax; \
  1505. - syscall;
  1506. + SYSCALL
  1507. # define DOARGS_0 /* nothing */
  1508. # define DOARGS_1 /* nothing */
  1509. @@ -190,9 +198,20 @@
  1510. /* Define a macro which expands inline into the wrapper code for a system
  1511. call. */
  1512. # undef INLINE_SYSCALL
  1513. -# define INLINE_SYSCALL(name, nr, args...) \
  1514. +# define INLINE_SYSCALL(name, nr_args...) \
  1515. + ({ \
  1516. + unsigned long int resultvar = INTERNAL_SYSCALL (name, , ##nr_args); \
  1517. + if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0)) \
  1518. + { \
  1519. + __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
  1520. + resultvar = (unsigned long int) -1; \
  1521. + } \
  1522. + (long int) resultvar; })
  1523. +
  1524. +# undef INLINE_SYSCALL_ASM
  1525. +# define INLINE_SYSCALL_ASM(name, nr_args...) \
  1526. ({ \
  1527. - unsigned long int resultvar = INTERNAL_SYSCALL (name, , nr, args); \
  1528. + unsigned long int resultvar = INTERNAL_SYSCALL_ASM (name, , ##nr_args); \
  1529. if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0)) \
  1530. { \
  1531. __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
  1532. @@ -204,9 +223,9 @@
  1533. into the wrapper code for a system call. It should be used when size
  1534. of any argument > size of long int. */
  1535. # undef INLINE_SYSCALL_TYPES
  1536. -# define INLINE_SYSCALL_TYPES(name, nr, args...) \
  1537. +# define INLINE_SYSCALL_TYPES(name, nr_args...) \
  1538. ({ \
  1539. - unsigned long int resultvar = INTERNAL_SYSCALL_TYPES (name, , nr, args); \
  1540. + unsigned long int resultvar = INTERNAL_SYSCALL_TYPES (name, , ##nr_args); \
  1541. if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0)) \
  1542. { \
  1543. __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
  1544. @@ -223,13 +242,20 @@
  1545. LOAD_ARGS_##nr (args) \
  1546. LOAD_REGS_##nr \
  1547. asm volatile ( \
  1548. - "syscall\n\t" \
  1549. + "movq syscalldb@GOTPCREL(%%rip), %%rbx\n\t" \
  1550. + "call *%%rbx\n\t" \
  1551. : "=a" (resultvar) \
  1552. - : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx"); \
  1553. + : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx", "bx"); \
  1554. (long int) resultvar; })
  1555. +# define INTERNAL_SYSCALL_NCS_ASM INTERNAL_SYSCALL_NCS
  1556. +
  1557. # undef INTERNAL_SYSCALL
  1558. -# define INTERNAL_SYSCALL(name, err, nr, args...) \
  1559. - INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
  1560. +# define INTERNAL_SYSCALL(name, err, nr_args...) \
  1561. + INTERNAL_SYSCALL_NCS (__NR_##name, err, ##nr_args)
  1562. +
  1563. +# undef INTERNAL_SYSCALL_ASM
  1564. +# define INTERNAL_SYSCALL_ASM(name, err, nr_args...) \
  1565. + INTERNAL_SYSCALL_NCS_ASM (__NR_##name, err, ##nr_args)
  1566. # define INTERNAL_SYSCALL_NCS_TYPES(name, err, nr, args...) \
  1567. ({ \
  1568. @@ -237,9 +263,10 @@
  1569. LOAD_ARGS_TYPES_##nr (args) \
  1570. LOAD_REGS_TYPES_##nr (args) \
  1571. asm volatile ( \
  1572. - "syscall\n\t" \
  1573. + "movq syscalldb@GOTPCREL(%%rip), %%rbx\n\t" \
  1574. + "call *%%rbx\n\t" \
  1575. : "=a" (resultvar) \
  1576. - : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx"); \
  1577. + : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx", "bx"); \
  1578. (long int) resultvar; })
  1579. # undef INTERNAL_SYSCALL_TYPES
  1580. # define INTERNAL_SYSCALL_TYPES(name, err, nr, args...) \
  1581. @@ -252,6 +279,7 @@
  1582. # undef INTERNAL_SYSCALL_ERRNO
  1583. # define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
  1584. +# if 0 /* for Graphene, never do vsyscall */
  1585. # ifdef SHARED
  1586. # define INLINE_VSYSCALL(name, nr, args...) \
  1587. ({ \
  1588. @@ -300,12 +328,13 @@
  1589. v_ret; \
  1590. })
  1591. -# else
  1592. -# define INLINE_VSYSCALL(name, nr, args...) \
  1593. - INLINE_SYSCALL (name, nr, ##args)
  1594. -# define INTERNAL_VSYSCALL(name, err, nr, args...) \
  1595. - INTERNAL_SYSCALL (name, err, nr, ##args)
  1596. # endif
  1597. +# endif
  1598. +
  1599. +# define INLINE_VSYSCALL(name, nr_args...) \
  1600. + INLINE_SYSCALL (name, ##nr_args)
  1601. +# define INTERNAL_VSYSCALL(name, err, nr_args...) \
  1602. + INTERNAL_SYSCALL (name, err, ##nr_args)
  1603. # define LOAD_ARGS_0()
  1604. # define LOAD_REGS_0
  1605. diff --git a/sysdeps/unix/sysv/linux/x86_64/time.c b/sysdeps/unix/sysv/linux/x86_64/time.c
  1606. deleted file mode 100644
  1607. index 79f1fab..0000000
  1608. --- a/sysdeps/unix/sysv/linux/x86_64/time.c
  1609. +++ /dev/null
  1610. @@ -1,60 +0,0 @@
  1611. -/* Copyright (C) 2001-2014 Free Software Foundation, Inc.
  1612. - This file is part of the GNU C Library.
  1613. -
  1614. - The GNU C Library is free software; you can redistribute it and/or
  1615. - modify it under the terms of the GNU Lesser General Public
  1616. - License as published by the Free Software Foundation; either
  1617. - version 2.1 of the License, or (at your option) any later version.
  1618. -
  1619. - The GNU C Library is distributed in the hope that it will be useful,
  1620. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  1621. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1622. - Lesser General Public License for more details.
  1623. -
  1624. - You should have received a copy of the GNU Lesser General Public
  1625. - License along with the GNU C Library; if not, see
  1626. - <http://www.gnu.org/licenses/>. */
  1627. -
  1628. -#ifdef SHARED
  1629. -/* Redefine time so that the compiler won't complain about the type
  1630. - mismatch with the IFUNC selector in strong_alias, below. */
  1631. -#undef time
  1632. -#define time __redirect_time
  1633. -#include <time.h>
  1634. -
  1635. -#include <dl-vdso.h>
  1636. -
  1637. -#define VSYSCALL_ADDR_vtime 0xffffffffff600400
  1638. -
  1639. -/* Avoid DWARF definition DIE on ifunc symbol so that GDB can handle
  1640. - ifunc symbol properly. */
  1641. -extern __typeof (__redirect_time) __libc_time;
  1642. -void *time_ifunc (void) __asm__ ("__libc_time");
  1643. -
  1644. -void *
  1645. -time_ifunc (void)
  1646. -{
  1647. - PREPARE_VERSION (linux26, "LINUX_2.6", 61765110);
  1648. -
  1649. - /* If the vDSO is not available we fall back on the old vsyscall. */
  1650. - return _dl_vdso_vsym ("__vdso_time", &linux26) ?: (void *) VSYSCALL_ADDR_vtime;
  1651. -}
  1652. -__asm (".type __libc_time, %gnu_indirect_function");
  1653. -
  1654. -#undef time
  1655. -strong_alias (__libc_time, time)
  1656. -libc_hidden_ver (__libc_time, time)
  1657. -
  1658. -#else
  1659. -
  1660. -# include <time.h>
  1661. -# include <sysdep.h>
  1662. -
  1663. -time_t
  1664. -time (time_t *t)
  1665. -{
  1666. - INTERNAL_SYSCALL_DECL (err);
  1667. - return INTERNAL_SYSCALL (time, err, 1, t);
  1668. -}
  1669. -
  1670. -#endif
  1671. diff --git a/sysdeps/unix/sysv/linux/x86_64/vfork.S b/sysdeps/unix/sysv/linux/x86_64/vfork.S
  1672. index d3b450a..76bda33 100644
  1673. --- a/sysdeps/unix/sysv/linux/x86_64/vfork.S
  1674. +++ b/sysdeps/unix/sysv/linux/x86_64/vfork.S
  1675. @@ -38,7 +38,7 @@ ENTRY (__vfork)
  1676. /* Stuff the syscall number in RAX and enter into the kernel. */
  1677. movl $SYS_ify (vfork), %eax
  1678. - syscall
  1679. + SYSCALL
  1680. /* Push back the return PC. */
  1681. pushq %rdi
  1682. diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h
  1683. index 504c95f..dcfc259 100644
  1684. --- a/sysdeps/x86_64/dl-machine.h
  1685. +++ b/sysdeps/x86_64/dl-machine.h
  1686. @@ -529,7 +529,8 @@ elf_machine_lazy_rel (struct link_map *map,
  1687. value = ((ElfW(Addr) (*) (void)) value) ();
  1688. *reloc_addr = value;
  1689. }
  1690. - else
  1691. + /* for graphene, get around R_X86_64_NONE */
  1692. + else if (__builtin_expect (r_type != R_X86_64_NONE, 1))
  1693. _dl_reloc_bad_type (map, r_type, 1);
  1694. }