glibc-2.19.patch 59 KB

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