glibc-2.19.patch 55 KB

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