glibc-2.17.patch 65 KB

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