branch-updates.diff 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771
  1. diff --git a/arch/aarch64/bits/hwcap.h b/arch/aarch64/bits/hwcap.h
  2. index 7ab73f99..424cc4d4 100644
  3. --- a/arch/aarch64/bits/hwcap.h
  4. +++ b/arch/aarch64/bits/hwcap.h
  5. @@ -48,3 +48,5 @@
  6. #define HWCAP2_BF16 (1 << 14)
  7. #define HWCAP2_DGH (1 << 15)
  8. #define HWCAP2_RNG (1 << 16)
  9. +#define HWCAP2_BTI (1 << 17)
  10. +#define HWCAP2_MTE (1 << 18)
  11. diff --git a/arch/aarch64/bits/mman.h b/arch/aarch64/bits/mman.h
  12. new file mode 100644
  13. index 00000000..8fad5ceb
  14. --- /dev/null
  15. +++ b/arch/aarch64/bits/mman.h
  16. @@ -0,0 +1,2 @@
  17. +#define PROT_BTI 0x10
  18. +#define PROT_MTE 0x20
  19. diff --git a/arch/aarch64/bits/syscall.h.in b/arch/aarch64/bits/syscall.h.in
  20. index f9457c18..1ad467c0 100644
  21. --- a/arch/aarch64/bits/syscall.h.in
  22. +++ b/arch/aarch64/bits/syscall.h.in
  23. @@ -293,4 +293,5 @@
  24. #define __NR_openat2 437
  25. #define __NR_pidfd_getfd 438
  26. #define __NR_faccessat2 439
  27. +#define __NR_process_madvise 440
  28. diff --git a/arch/arm/bits/syscall.h.in b/arch/arm/bits/syscall.h.in
  29. index 7e2fc266..cf9e3411 100644
  30. --- a/arch/arm/bits/syscall.h.in
  31. +++ b/arch/arm/bits/syscall.h.in
  32. @@ -393,6 +393,7 @@
  33. #define __NR_openat2 437
  34. #define __NR_pidfd_getfd 438
  35. #define __NR_faccessat2 439
  36. +#define __NR_process_madvise 440
  37. #define __ARM_NR_breakpoint 0x0f0001
  38. #define __ARM_NR_cacheflush 0x0f0002
  39. diff --git a/arch/i386/bits/syscall.h.in b/arch/i386/bits/syscall.h.in
  40. index abdb210d..5d1c4d7a 100644
  41. --- a/arch/i386/bits/syscall.h.in
  42. +++ b/arch/i386/bits/syscall.h.in
  43. @@ -430,4 +430,5 @@
  44. #define __NR_openat2 437
  45. #define __NR_pidfd_getfd 438
  46. #define __NR_faccessat2 439
  47. +#define __NR_process_madvise 440
  48. diff --git a/arch/m68k/bits/syscall.h.in b/arch/m68k/bits/syscall.h.in
  49. index e10969a2..6794b1a0 100644
  50. --- a/arch/m68k/bits/syscall.h.in
  51. +++ b/arch/m68k/bits/syscall.h.in
  52. @@ -410,3 +410,4 @@
  53. #define __NR_openat2 437
  54. #define __NR_pidfd_getfd 438
  55. #define __NR_faccessat2 439
  56. +#define __NR_process_madvise 440
  57. diff --git a/arch/microblaze/bits/syscall.h.in b/arch/microblaze/bits/syscall.h.in
  58. index 9d469047..7f71df3b 100644
  59. --- a/arch/microblaze/bits/syscall.h.in
  60. +++ b/arch/microblaze/bits/syscall.h.in
  61. @@ -431,4 +431,5 @@
  62. #define __NR_openat2 437
  63. #define __NR_pidfd_getfd 438
  64. #define __NR_faccessat2 439
  65. +#define __NR_process_madvise 440
  66. diff --git a/arch/mips/bits/syscall.h.in b/arch/mips/bits/syscall.h.in
  67. index 2bb03f06..d54845b2 100644
  68. --- a/arch/mips/bits/syscall.h.in
  69. +++ b/arch/mips/bits/syscall.h.in
  70. @@ -412,4 +412,5 @@
  71. #define __NR_openat2 4437
  72. #define __NR_pidfd_getfd 4438
  73. #define __NR_faccessat2 4439
  74. +#define __NR_process_madvise 4440
  75. diff --git a/arch/mips/pthread_arch.h b/arch/mips/pthread_arch.h
  76. index c45347ab..376b7741 100644
  77. --- a/arch/mips/pthread_arch.h
  78. +++ b/arch/mips/pthread_arch.h
  79. @@ -1,10 +1,9 @@
  80. static inline uintptr_t __get_tp()
  81. {
  82. -#if __mips_isa_rev < 2
  83. register uintptr_t tp __asm__("$3");
  84. +#if __mips_isa_rev < 2
  85. __asm__ (".word 0x7c03e83b" : "=r" (tp) );
  86. #else
  87. - uintptr_t tp;
  88. __asm__ ("rdhwr %0, $29" : "=r" (tp) );
  89. #endif
  90. return tp;
  91. diff --git a/arch/mips64/bits/syscall.h.in b/arch/mips64/bits/syscall.h.in
  92. index 045e8238..920b4358 100644
  93. --- a/arch/mips64/bits/syscall.h.in
  94. +++ b/arch/mips64/bits/syscall.h.in
  95. @@ -342,4 +342,5 @@
  96. #define __NR_openat2 5437
  97. #define __NR_pidfd_getfd 5438
  98. #define __NR_faccessat2 5439
  99. +#define __NR_process_madvise 5440
  100. diff --git a/arch/mipsn32/bits/syscall.h.in b/arch/mipsn32/bits/syscall.h.in
  101. index 5b322558..e6dad688 100644
  102. --- a/arch/mipsn32/bits/syscall.h.in
  103. +++ b/arch/mipsn32/bits/syscall.h.in
  104. @@ -366,4 +366,5 @@
  105. #define __NR_openat2 6437
  106. #define __NR_pidfd_getfd 6438
  107. #define __NR_faccessat2 6439
  108. +#define __NR_process_madvise 6440
  109. diff --git a/arch/or1k/bits/syscall.h.in b/arch/or1k/bits/syscall.h.in
  110. index b3603891..463ee901 100644
  111. --- a/arch/or1k/bits/syscall.h.in
  112. +++ b/arch/or1k/bits/syscall.h.in
  113. @@ -315,4 +315,5 @@
  114. #define __NR_openat2 437
  115. #define __NR_pidfd_getfd 438
  116. #define __NR_faccessat2 439
  117. +#define __NR_process_madvise 440
  118. diff --git a/arch/powerpc/bits/fenv.h b/arch/powerpc/bits/fenv.h
  119. index c5a3e5c5..5b15c69a 100644
  120. --- a/arch/powerpc/bits/fenv.h
  121. +++ b/arch/powerpc/bits/fenv.h
  122. @@ -1,4 +1,4 @@
  123. -#ifdef _SOFT_FLOAT
  124. +#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
  125. #define FE_ALL_EXCEPT 0
  126. #define FE_TONEAREST 0
  127. #else
  128. diff --git a/arch/powerpc/bits/shm.h b/arch/powerpc/bits/shm.h
  129. index fb1d4020..7f1ca17e 100644
  130. --- a/arch/powerpc/bits/shm.h
  131. +++ b/arch/powerpc/bits/shm.h
  132. @@ -8,11 +8,11 @@ struct shmid_ds {
  133. unsigned long __shm_dtime_lo;
  134. unsigned long __shm_ctime_hi;
  135. unsigned long __shm_ctime_lo;
  136. + unsigned long __pad1;
  137. size_t shm_segsz;
  138. pid_t shm_cpid;
  139. pid_t shm_lpid;
  140. unsigned long shm_nattch;
  141. - unsigned long __pad1;
  142. unsigned long __pad2;
  143. time_t shm_atime;
  144. time_t shm_dtime;
  145. diff --git a/arch/powerpc/bits/syscall.h.in b/arch/powerpc/bits/syscall.h.in
  146. index 5c6fae3e..db4d0ca4 100644
  147. --- a/arch/powerpc/bits/syscall.h.in
  148. +++ b/arch/powerpc/bits/syscall.h.in
  149. @@ -419,4 +419,5 @@
  150. #define __NR_openat2 437
  151. #define __NR_pidfd_getfd 438
  152. #define __NR_faccessat2 439
  153. +#define __NR_process_madvise 440
  154. diff --git a/arch/powerpc/reloc.h b/arch/powerpc/reloc.h
  155. index 527b6b7c..fdfbf827 100644
  156. --- a/arch/powerpc/reloc.h
  157. +++ b/arch/powerpc/reloc.h
  158. @@ -1,4 +1,4 @@
  159. -#ifdef _SOFT_FLOAT
  160. +#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
  161. #define FP_SUFFIX "-sf"
  162. #else
  163. #define FP_SUFFIX ""
  164. diff --git a/arch/powerpc64/bits/syscall.h.in b/arch/powerpc64/bits/syscall.h.in
  165. index edf73d3d..a128890b 100644
  166. --- a/arch/powerpc64/bits/syscall.h.in
  167. +++ b/arch/powerpc64/bits/syscall.h.in
  168. @@ -391,4 +391,5 @@
  169. #define __NR_openat2 437
  170. #define __NR_pidfd_getfd 438
  171. #define __NR_faccessat2 439
  172. +#define __NR_process_madvise 440
  173. diff --git a/arch/riscv64/bits/syscall.h.in b/arch/riscv64/bits/syscall.h.in
  174. index 5def016b..39c0d650 100644
  175. --- a/arch/riscv64/bits/syscall.h.in
  176. +++ b/arch/riscv64/bits/syscall.h.in
  177. @@ -76,7 +76,7 @@
  178. #define __NR_splice 76
  179. #define __NR_tee 77
  180. #define __NR_readlinkat 78
  181. -#define __NR_fstatat 79
  182. +#define __NR_newfstatat 79
  183. #define __NR_fstat 80
  184. #define __NR_sync 81
  185. #define __NR_fsync 82
  186. @@ -293,6 +293,7 @@
  187. #define __NR_openat2 437
  188. #define __NR_pidfd_getfd 438
  189. #define __NR_faccessat2 439
  190. +#define __NR_process_madvise 440
  191. #define __NR_sysriscv __NR_arch_specific_syscall
  192. #define __NR_riscv_flush_icache (__NR_sysriscv + 15)
  193. diff --git a/arch/riscv64/bits/user.h b/arch/riscv64/bits/user.h
  194. index 2da743ea..0d37de0b 100644
  195. --- a/arch/riscv64/bits/user.h
  196. +++ b/arch/riscv64/bits/user.h
  197. @@ -1,5 +1,6 @@
  198. #include <signal.h>
  199. #define ELF_NGREG 32
  200. +#define ELF_NFPREG 33
  201. typedef unsigned long elf_greg_t, elf_gregset_t[ELF_NGREG];
  202. typedef union __riscv_mc_fp_state elf_fpregset_t;
  203. diff --git a/arch/s390x/bits/syscall.h.in b/arch/s390x/bits/syscall.h.in
  204. index fb2e60e3..9c8d984e 100644
  205. --- a/arch/s390x/bits/syscall.h.in
  206. +++ b/arch/s390x/bits/syscall.h.in
  207. @@ -356,4 +356,5 @@
  208. #define __NR_openat2 437
  209. #define __NR_pidfd_getfd 438
  210. #define __NR_faccessat2 439
  211. +#define __NR_process_madvise 440
  212. diff --git a/arch/sh/bits/syscall.h.in b/arch/sh/bits/syscall.h.in
  213. index 158afc09..17dd7e07 100644
  214. --- a/arch/sh/bits/syscall.h.in
  215. +++ b/arch/sh/bits/syscall.h.in
  216. @@ -403,4 +403,5 @@
  217. #define __NR_openat2 437
  218. #define __NR_pidfd_getfd 438
  219. #define __NR_faccessat2 439
  220. +#define __NR_process_madvise 440
  221. diff --git a/arch/x32/bits/syscall.h.in b/arch/x32/bits/syscall.h.in
  222. index cfd9856f..5361442e 100644
  223. --- a/arch/x32/bits/syscall.h.in
  224. +++ b/arch/x32/bits/syscall.h.in
  225. @@ -302,6 +302,7 @@
  226. #define __NR_openat2 (0x40000000 + 437)
  227. #define __NR_pidfd_getfd (0x40000000 + 438)
  228. #define __NR_faccessat2 (0x40000000 + 439)
  229. +#define __NR_process_madvise (0x40000000 + 440)
  230. #define __NR_rt_sigaction (0x40000000 + 512)
  231. diff --git a/arch/x86_64/bits/syscall.h.in b/arch/x86_64/bits/syscall.h.in
  232. index a6117951..e943883d 100644
  233. --- a/arch/x86_64/bits/syscall.h.in
  234. +++ b/arch/x86_64/bits/syscall.h.in
  235. @@ -349,4 +349,5 @@
  236. #define __NR_openat2 437
  237. #define __NR_pidfd_getfd 438
  238. #define __NR_faccessat2 439
  239. +#define __NR_process_madvise 440
  240. diff --git a/configure b/configure
  241. index a5231a0e..ca5cbc0b 100755
  242. --- a/configure
  243. +++ b/configure
  244. @@ -409,7 +409,7 @@ test "$debug" = yes && CFLAGS_AUTO=-g
  245. #
  246. printf "checking whether we should preprocess assembly to add debugging information... "
  247. if fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" &&
  248. - test -f "tools/add-cfi.$ARCH.awk" &&
  249. + test -f "$srcdir/tools/add-cfi.$ARCH.awk" &&
  250. printf ".file 1 \"srcfile.s\"\n.line 1\n.cfi_startproc\n.cfi_endproc" | $CC -g -x assembler -c -o /dev/null 2>/dev/null -
  251. then
  252. ADD_CFI=yes
  253. @@ -671,9 +671,7 @@ trycppif __mips_soft_float "$t" && SUBARCH=${SUBARCH}-sf
  254. fi
  255. if test "$ARCH" = "powerpc" ; then
  256. -trycppif "__NO_FPRS__ && !_SOFT_FLOAT" "$t" && fail \
  257. - "$0: error: compiler's floating point configuration is unsupported"
  258. -trycppif _SOFT_FLOAT "$t" && SUBARCH=${SUBARCH}-sf
  259. +trycppif "_SOFT_FLOAT || __NO_FPRS__" "$t" && SUBARCH=${SUBARCH}-sf
  260. printf "checking whether compiler can use 'd' constraint in asm... "
  261. echo 'double f(double x) { __asm__ ("fabs %0, %1" : "=d"(x) : "d"(x)); return x; }' > "$tmpc"
  262. if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
  263. diff --git a/include/ctype.h b/include/ctype.h
  264. index 7936536f..32bcef4d 100644
  265. --- a/include/ctype.h
  266. +++ b/include/ctype.h
  267. @@ -64,7 +64,9 @@ int isascii(int);
  268. int toascii(int);
  269. #define _tolower(a) ((a)|0x20)
  270. #define _toupper(a) ((a)&0x5f)
  271. +#ifndef __cplusplus
  272. #define isascii(a) (0 ? isascii(a) : (unsigned)(a) < 128)
  273. +#endif
  274. #endif
  275. diff --git a/include/elf.h b/include/elf.h
  276. index b5e7befb..5170f3e2 100644
  277. --- a/include/elf.h
  278. +++ b/include/elf.h
  279. @@ -686,6 +686,7 @@ typedef struct {
  280. #define NT_ARM_PAC_MASK 0x406
  281. #define NT_ARM_PACA_KEYS 0x407
  282. #define NT_ARM_PACG_KEYS 0x408
  283. +#define NT_ARM_TAGGED_ADDR_CTRL 0x409
  284. #define NT_METAG_CBUF 0x500
  285. #define NT_METAG_RPIPE 0x501
  286. #define NT_METAG_TLS 0x502
  287. diff --git a/include/locale.h b/include/locale.h
  288. index ce384381..11106fea 100644
  289. --- a/include/locale.h
  290. +++ b/include/locale.h
  291. @@ -7,7 +7,9 @@ extern "C" {
  292. #include <features.h>
  293. -#ifdef __cplusplus
  294. +#if __cplusplus >= 201103L
  295. +#define NULL nullptr
  296. +#elif defined(__cplusplus)
  297. #define NULL 0L
  298. #else
  299. #define NULL ((void*)0)
  300. diff --git a/include/pthread.h b/include/pthread.h
  301. index 0492f26a..89fd9ff7 100644
  302. --- a/include/pthread.h
  303. +++ b/include/pthread.h
  304. @@ -221,6 +221,7 @@ int pthread_getaffinity_np(pthread_t, size_t, struct cpu_set_t *);
  305. int pthread_setaffinity_np(pthread_t, size_t, const struct cpu_set_t *);
  306. int pthread_getattr_np(pthread_t, pthread_attr_t *);
  307. int pthread_setname_np(pthread_t, const char *);
  308. +int pthread_getname_np(pthread_t, char *, size_t);
  309. int pthread_getattr_default_np(pthread_attr_t *);
  310. int pthread_setattr_default_np(const pthread_attr_t *);
  311. int pthread_tryjoin_np(pthread_t, void **);
  312. diff --git a/include/setjmp.h b/include/setjmp.h
  313. index 2d43abf8..1976af23 100644
  314. --- a/include/setjmp.h
  315. +++ b/include/setjmp.h
  316. @@ -15,25 +15,33 @@ typedef struct __jmp_buf_tag {
  317. unsigned long __ss[128/sizeof(long)];
  318. } jmp_buf[1];
  319. +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
  320. +#define __setjmp_attr __attribute__((__returns_twice__))
  321. +#else
  322. +#define __setjmp_attr
  323. +#endif
  324. +
  325. #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  326. || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
  327. || defined(_BSD_SOURCE)
  328. typedef jmp_buf sigjmp_buf;
  329. -int sigsetjmp (sigjmp_buf, int);
  330. +int sigsetjmp (sigjmp_buf, int) __setjmp_attr;
  331. _Noreturn void siglongjmp (sigjmp_buf, int);
  332. #endif
  333. #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
  334. || defined(_BSD_SOURCE)
  335. -int _setjmp (jmp_buf);
  336. +int _setjmp (jmp_buf) __setjmp_attr;
  337. _Noreturn void _longjmp (jmp_buf, int);
  338. #endif
  339. -int setjmp (jmp_buf);
  340. +int setjmp (jmp_buf) __setjmp_attr;
  341. _Noreturn void longjmp (jmp_buf, int);
  342. #define setjmp setjmp
  343. +#undef __setjmp_attr
  344. +
  345. #ifdef __cplusplus
  346. }
  347. #endif
  348. diff --git a/include/signal.h b/include/signal.h
  349. index 9ed929e4..f270a594 100644
  350. --- a/include/signal.h
  351. +++ b/include/signal.h
  352. @@ -75,6 +75,8 @@ typedef struct sigaltstack stack_t;
  353. #define SEGV_ACCERR 2
  354. #define SEGV_BNDERR 3
  355. #define SEGV_PKUERR 4
  356. +#define SEGV_MTEAERR 8
  357. +#define SEGV_MTESERR 9
  358. #define BUS_ADRALN 1
  359. #define BUS_ADRERR 2
  360. diff --git a/include/stdc-predef.h b/include/stdc-predef.h
  361. index f8cd4b89..af1a2799 100644
  362. --- a/include/stdc-predef.h
  363. +++ b/include/stdc-predef.h
  364. @@ -7,4 +7,7 @@
  365. #define __STDC_IEC_559__ 1
  366. #endif
  367. +#define __STDC_UTF_16__ 1
  368. +#define __STDC_UTF_32__ 1
  369. +
  370. #endif
  371. diff --git a/include/stddef.h b/include/stddef.h
  372. index bd753853..f25b8639 100644
  373. --- a/include/stddef.h
  374. +++ b/include/stddef.h
  375. @@ -1,7 +1,9 @@
  376. #ifndef _STDDEF_H
  377. #define _STDDEF_H
  378. -#ifdef __cplusplus
  379. +#if __cplusplus >= 201103L
  380. +#define NULL nullptr
  381. +#elif defined(__cplusplus)
  382. #define NULL 0L
  383. #else
  384. #define NULL ((void*)0)
  385. diff --git a/include/stdio.h b/include/stdio.h
  386. index 3604198c..d1ed01f0 100644
  387. --- a/include/stdio.h
  388. +++ b/include/stdio.h
  389. @@ -25,7 +25,9 @@ extern "C" {
  390. #include <bits/alltypes.h>
  391. -#ifdef __cplusplus
  392. +#if __cplusplus >= 201103L
  393. +#define NULL nullptr
  394. +#elif defined(__cplusplus)
  395. #define NULL 0L
  396. #else
  397. #define NULL ((void*)0)
  398. diff --git a/include/stdlib.h b/include/stdlib.h
  399. index b54a051f..b507ca33 100644
  400. --- a/include/stdlib.h
  401. +++ b/include/stdlib.h
  402. @@ -7,7 +7,9 @@ extern "C" {
  403. #include <features.h>
  404. -#ifdef __cplusplus
  405. +#if __cplusplus >= 201103L
  406. +#define NULL nullptr
  407. +#elif defined(__cplusplus)
  408. #define NULL 0L
  409. #else
  410. #define NULL ((void*)0)
  411. @@ -146,6 +148,7 @@ int clearenv(void);
  412. #define WCOREDUMP(s) ((s) & 0x80)
  413. #define WIFCONTINUED(s) ((s) == 0xffff)
  414. void *reallocarray (void *, size_t, size_t);
  415. +void qsort_r (void *, size_t, size_t, int (*)(const void *, const void *, void *), void *);
  416. #endif
  417. #ifdef _GNU_SOURCE
  418. diff --git a/include/string.h b/include/string.h
  419. index 795a2abc..43ad0942 100644
  420. --- a/include/string.h
  421. +++ b/include/string.h
  422. @@ -7,7 +7,9 @@ extern "C" {
  423. #include <features.h>
  424. -#ifdef __cplusplus
  425. +#if __cplusplus >= 201103L
  426. +#define NULL nullptr
  427. +#elif defined(__cplusplus)
  428. #define NULL 0L
  429. #else
  430. #define NULL ((void*)0)
  431. diff --git a/include/sys/membarrier.h b/include/sys/membarrier.h
  432. index 10cb3108..11193eda 100644
  433. --- a/include/sys/membarrier.h
  434. +++ b/include/sys/membarrier.h
  435. @@ -9,9 +9,13 @@
  436. #define MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED 16
  437. #define MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE 32
  438. #define MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE 64
  439. +#define MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ 128
  440. +#define MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ 256
  441. #define MEMBARRIER_CMD_SHARED MEMBARRIER_CMD_GLOBAL
  442. +#define MEMBARRIER_CMD_FLAG_CPU 1
  443. +
  444. int membarrier(int, int);
  445. #endif
  446. diff --git a/include/sys/mman.h b/include/sys/mman.h
  447. index 4d603e91..80a3baae 100644
  448. --- a/include/sys/mman.h
  449. +++ b/include/sys/mman.h
  450. @@ -40,6 +40,7 @@ extern "C" {
  451. #define MAP_HUGE_SHIFT 26
  452. #define MAP_HUGE_MASK 0x3f
  453. +#define MAP_HUGE_16KB (14 << 26)
  454. #define MAP_HUGE_64KB (16 << 26)
  455. #define MAP_HUGE_512KB (19 << 26)
  456. #define MAP_HUGE_1MB (20 << 26)
  457. diff --git a/include/sys/mount.h b/include/sys/mount.h
  458. index 57a89c09..09bd6e9d 100644
  459. --- a/include/sys/mount.h
  460. +++ b/include/sys/mount.h
  461. @@ -31,6 +31,7 @@ extern "C" {
  462. #define MS_REMOUNT 32
  463. #define MS_MANDLOCK 64
  464. #define MS_DIRSYNC 128
  465. +#define MS_NOSYMFOLLOW 256
  466. #define MS_NOATIME 1024
  467. #define MS_NODIRATIME 2048
  468. #define MS_BIND 4096
  469. diff --git a/include/sys/prctl.h b/include/sys/prctl.h
  470. index 4b9fcc05..4ba73f42 100644
  471. --- a/include/sys/prctl.h
  472. +++ b/include/sys/prctl.h
  473. @@ -157,6 +157,13 @@ struct prctl_mm_map {
  474. #define PR_SET_TAGGED_ADDR_CTRL 55
  475. #define PR_GET_TAGGED_ADDR_CTRL 56
  476. #define PR_TAGGED_ADDR_ENABLE (1UL << 0)
  477. +#define PR_MTE_TCF_SHIFT 1
  478. +#define PR_MTE_TCF_NONE (0UL << 1)
  479. +#define PR_MTE_TCF_SYNC (1UL << 1)
  480. +#define PR_MTE_TCF_ASYNC (2UL << 1)
  481. +#define PR_MTE_TCF_MASK (3UL << 1)
  482. +#define PR_MTE_TAG_SHIFT 3
  483. +#define PR_MTE_TAG_MASK (0xffffUL << 3)
  484. #define PR_SET_IO_FLUSHER 57
  485. #define PR_GET_IO_FLUSHER 58
  486. diff --git a/include/time.h b/include/time.h
  487. index 5494df18..3d948372 100644
  488. --- a/include/time.h
  489. +++ b/include/time.h
  490. @@ -7,7 +7,9 @@ extern "C" {
  491. #include <features.h>
  492. -#ifdef __cplusplus
  493. +#if __cplusplus >= 201103L
  494. +#define NULL nullptr
  495. +#elif defined(__cplusplus)
  496. #define NULL 0L
  497. #else
  498. #define NULL ((void*)0)
  499. diff --git a/include/unistd.h b/include/unistd.h
  500. index 13064026..212263a7 100644
  501. --- a/include/unistd.h
  502. +++ b/include/unistd.h
  503. @@ -14,8 +14,12 @@ extern "C" {
  504. #define SEEK_SET 0
  505. #define SEEK_CUR 1
  506. #define SEEK_END 2
  507. +#define SEEK_DATA 3
  508. +#define SEEK_HOLE 4
  509. -#ifdef __cplusplus
  510. +#if __cplusplus >= 201103L
  511. +#define NULL nullptr
  512. +#elif defined(__cplusplus)
  513. #define NULL 0L
  514. #else
  515. #define NULL ((void*)0)
  516. diff --git a/include/wchar.h b/include/wchar.h
  517. index 88eb55b1..ed5d774d 100644
  518. --- a/include/wchar.h
  519. +++ b/include/wchar.h
  520. @@ -38,7 +38,9 @@ extern "C" {
  521. #define WCHAR_MIN (-1-0x7fffffff+L'\0')
  522. #endif
  523. -#ifdef __cplusplus
  524. +#if __cplusplus >= 201103L
  525. +#define NULL nullptr
  526. +#elif defined(__cplusplus)
  527. #define NULL 0L
  528. #else
  529. #define NULL ((void*)0)
  530. diff --git a/ldso/dynlink.c b/ldso/dynlink.c
  531. index 6b868c84..5b9c8be4 100644
  532. --- a/ldso/dynlink.c
  533. +++ b/ldso/dynlink.c
  534. @@ -579,6 +579,7 @@ static void *mmap_fixed(void *p, size_t n, int prot, int flags, int fd, off_t of
  535. {
  536. static int no_map_fixed;
  537. char *q;
  538. + if (!n) return p;
  539. if (!no_map_fixed) {
  540. q = mmap(p, n, prot, flags|MAP_FIXED, fd, off);
  541. if (!DL_NOMMU_SUPPORT || q != MAP_FAILED || errno != EINVAL)
  542. @@ -1830,7 +1831,7 @@ void __dls3(size_t *sp, size_t *auxv)
  543. dprintf(2, "%s: cannot load %s: %s\n", ldname, argv[0], strerror(errno));
  544. _exit(1);
  545. }
  546. - Ehdr *ehdr = (void *)map_library(fd, &app);
  547. + Ehdr *ehdr = map_library(fd, &app);
  548. if (!ehdr) {
  549. dprintf(2, "%s: %s: Not a valid dynamic program\n", ldname, argv[0]);
  550. _exit(1);
  551. @@ -2330,7 +2331,8 @@ int dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size_t size, void
  552. info.dlpi_adds = gencnt;
  553. info.dlpi_subs = 0;
  554. info.dlpi_tls_modid = current->tls_id;
  555. - info.dlpi_tls_data = current->tls.image;
  556. + info.dlpi_tls_data = !current->tls_id ? 0 :
  557. + __tls_get_addr((tls_mod_off_t[]){current->tls_id,0});
  558. ret = (callback)(&info, sizeof (info), data);
  559. diff --git a/src/complex/cproj.c b/src/complex/cproj.c
  560. index 9ae1e17c..d2b8f5a9 100644
  561. --- a/src/complex/cproj.c
  562. +++ b/src/complex/cproj.c
  563. @@ -3,6 +3,6 @@
  564. double complex cproj(double complex z)
  565. {
  566. if (isinf(creal(z)) || isinf(cimag(z)))
  567. - return CMPLX(INFINITY, copysign(0.0, creal(z)));
  568. + return CMPLX(INFINITY, copysign(0.0, cimag(z)));
  569. return z;
  570. }
  571. diff --git a/src/complex/cprojf.c b/src/complex/cprojf.c
  572. index 03fab339..15a874bb 100644
  573. --- a/src/complex/cprojf.c
  574. +++ b/src/complex/cprojf.c
  575. @@ -3,6 +3,6 @@
  576. float complex cprojf(float complex z)
  577. {
  578. if (isinf(crealf(z)) || isinf(cimagf(z)))
  579. - return CMPLXF(INFINITY, copysignf(0.0, crealf(z)));
  580. + return CMPLXF(INFINITY, copysignf(0.0, cimagf(z)));
  581. return z;
  582. }
  583. diff --git a/src/complex/cprojl.c b/src/complex/cprojl.c
  584. index 38a494c5..531ffa1c 100644
  585. --- a/src/complex/cprojl.c
  586. +++ b/src/complex/cprojl.c
  587. @@ -9,7 +9,7 @@ long double complex cprojl(long double complex z)
  588. long double complex cprojl(long double complex z)
  589. {
  590. if (isinf(creall(z)) || isinf(cimagl(z)))
  591. - return CMPLXL(INFINITY, copysignl(0.0, creall(z)));
  592. + return CMPLXL(INFINITY, copysignl(0.0, cimagl(z)));
  593. return z;
  594. }
  595. #endif
  596. diff --git a/src/ctype/nonspacing.h b/src/ctype/nonspacing.h
  597. index 5d05a3d1..7746f3b6 100644
  598. --- a/src/ctype/nonspacing.h
  599. +++ b/src/ctype/nonspacing.h
  600. @@ -1,23 +1,23 @@
  601. -16,16,16,18,19,20,21,22,23,24,25,26,27,28,29,30,31,16,16,32,16,16,16,33,34,35,
  602. -36,37,38,39,16,16,40,16,16,16,16,16,16,16,16,16,16,16,41,42,16,16,43,16,16,16,
  603. +16,16,16,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,16,33,16,16,16,34,35,36,
  604. +37,38,39,40,16,16,41,16,16,16,16,16,16,16,16,16,16,16,42,43,16,16,44,16,16,16,
  605. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  606. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  607. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  608. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  609. -16,16,16,16,16,16,16,16,16,16,44,16,45,46,47,48,16,16,16,16,16,16,16,16,16,16,
  610. +16,16,16,16,16,16,16,16,16,16,45,16,46,47,48,49,16,16,16,16,16,16,16,16,16,16,
  611. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  612. +16,16,16,16,16,16,16,50,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  613. +16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,51,16,16,52,
  614. +53,16,54,55,56,16,16,16,16,16,16,57,16,16,58,16,59,60,61,62,63,64,65,66,67,68,
  615. +69,70,16,71,72,73,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  616. +16,74,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  617. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  618. -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,49,16,16,50,
  619. -51,16,52,53,54,16,16,16,16,16,16,55,16,16,56,16,57,58,59,60,61,62,63,64,65,66,
  620. -67,68,16,69,70,71,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  621. -16,72,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  622. +16,16,16,75,76,16,16,16,77,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  623. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  624. -16,16,16,73,74,16,16,16,75,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  625. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  626. -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  627. -16,16,16,16,16,16,16,76,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  628. -16,16,77,78,16,16,16,16,16,16,16,79,16,16,16,16,16,80,81,82,16,16,16,16,16,83,
  629. -84,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  630. +16,16,16,16,16,16,16,78,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  631. +16,16,79,80,16,16,16,16,16,16,16,81,16,16,16,16,16,82,83,84,16,16,16,16,16,85,
  632. +86,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  633. 16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,
  634. 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  635. 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  636. @@ -35,55 +35,57 @@
  637. 242,7,128,127,0,0,0,0,0,0,0,0,0,0,0,0,242,31,0,63,0,0,0,0,0,0,0,0,0,3,0,0,160,
  638. 2,0,0,0,0,0,0,254,127,223,224,255,254,255,255,255,31,64,0,0,0,0,0,0,0,0,0,0,0,
  639. 0,224,253,102,0,0,0,195,1,0,30,0,100,32,0,32,0,0,0,0,0,0,0,0,0,0,0,
  640. -0,0,0,0,0,0,0,0,0,0,0,0,224,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,0,
  641. -0,0,28,0,0,0,12,0,0,0,12,0,0,0,0,0,0,0,176,63,64,254,15,32,0,0,0,0,0,120,0,0,
  642. -0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,135,1,4,14,0,
  643. -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,9,0,0,0,0,0,0,64,127,
  644. -229,31,248,159,0,0,0,0,0,0,255,127,0,0,0,0,0,0,0,0,15,0,0,0,0,0,208,23,4,0,0,
  645. -0,0,248,15,0,3,0,0,0,60,59,0,0,0,0,0,0,64,163,3,0,0,0,0,0,0,240,207,0,0,0,0,0,
  646. -0,0,0,0,0,0,0,0,0,0,0,0,0,0,247,255,253,33,16,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  647. -0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,
  648. +0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,
  649. +255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,224,0,0,0,0,0,0,0,0,0,0,0,0,
  650. +0,0,0,0,0,0,0,0,0,0,28,0,0,0,28,0,0,0,12,0,0,0,12,0,0,0,0,0,0,0,176,63,64,254,
  651. +15,32,0,0,0,0,0,120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,2,0,0,0,0,0,0,0,0,
  652. +0,0,0,0,0,0,135,1,4,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  653. +128,9,0,0,0,0,0,0,64,127,229,31,248,159,0,0,0,0,0,0,255,127,0,0,0,0,0,0,0,0,
  654. +15,0,0,0,0,0,208,23,4,0,0,0,0,248,15,0,3,0,0,0,60,59,0,0,0,0,0,0,64,163,3,0,0,
  655. +0,0,0,0,240,207,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,247,255,253,33,16,
  656. +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,
  657. 251,0,248,0,0,0,124,0,0,0,0,0,0,223,255,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,
  658. 255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,0,0,0,
  659. 0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,0,0,
  660. 0,60,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  661. 0,0,0,128,247,63,0,0,0,192,0,0,0,0,0,0,0,0,0,0,3,0,68,8,0,0,96,0,0,0,0,0,0,0,
  662. 0,0,0,0,0,0,0,0,0,0,0,0,48,0,0,0,255,255,3,128,0,0,0,0,192,63,0,0,128,255,3,0,
  663. -0,0,0,0,7,0,0,0,0,0,200,51,0,0,0,0,32,0,0,0,0,0,0,0,0,126,102,0,8,16,0,0,0,0,
  664. -0,16,0,0,0,0,0,0,157,193,2,0,0,0,0,48,64,
  665. -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,33,0,0,0,0,0,64,
  666. -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,255,255,0,
  667. -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,
  668. -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  669. -0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  670. -0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  671. -0,110,240,0,0,0,0,0,135,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,
  672. -0,0,0,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  673. -0,0,0,192,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,255,
  674. -127,0,0,0,0,0,0,128,3,0,0,0,0,0,120,38,0,32,0,0,0,0,0,0,7,0,0,0,128,239,31,0,
  675. -0,0,0,0,0,0,8,0,3,0,0,0,0,0,192,127,0,30,0,0,0,0,0,0,0,0,0,0,0,128,211,64,0,0,
  676. -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,248,7,0,0,3,0,0,0,0,0,0,24,1,0,0,0,192,
  677. -31,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,92,0,0,64,0,0,0,0,0,
  678. -0,0,0,0,0,248,133,13,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  679. -0,60,176,1,0,0,48,0,0,0,
  680. -0,0,0,0,0,0,0,248,167,1,0,0,0,0,0,0,0,0,0,0,0,0,40,191,0,0,0,0,0,0,0,0,0,0,0,
  681. -0,224,188,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  682. -128,255,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  683. -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,12,1,0,0,0,254,7,0,0,0,0,248,121,128,0,
  684. -126,14,0,0,0,0,0,252,127,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,191,0,0,0,
  685. -0,0,0,0,0,0,0,252,255,255,252,109,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,126,180,191,0,
  686. -0,0,0,0,0,0,0,0,163,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  687. -0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,
  688. -0,0,0,0,0,0,0,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  689. -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,0,0,0,0,0,0,0,127,0,0,0,
  690. -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,
  691. -0,128,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,15,
  692. -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,248,255,231,15,0,0,0,60,0,
  693. -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  694. -0,0,0,255,255,255,255,255,255,127,248,255,255,255,255,255,31,32,0,16,0,0,248,
  695. -254,255,0,0,0,0,0,0,0,0,0,
  696. -0,127,255,255,249,219,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  697. -0,0,0,0,0,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  698. -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  699. -0,0,0,0,0,0,0,0,0,0,0,0,0,127,0,0,0,0,0,0,0,0,0,0,0,0,0,240,7,0,0,0,0,0,0,0,0,
  700. -0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  701. +0,0,0,0,7,0,0,0,0,0,200,51,0,0,0,0,32,0,0,
  702. +0,0,0,0,0,0,126,102,0,8,16,0,0,0,0,0,16,0,0,0,0,0,0,157,193,2,0,0,0,0,48,64,0,
  703. +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,33,0,0,0,0,0,0,0,0,
  704. +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,0,0,0,
  705. +64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,255,
  706. +255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,
  707. +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  708. +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  709. +0,0,0,0,0,0,1,0,0,
  710. +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,110,240,0,
  711. +0,0,0,0,135,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,240,0,0,
  712. +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,255,1,0,
  713. +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,255,127,0,0,0,0,0,0,128,
  714. +3,0,0,0,0,0,120,38,0,32,0,0,0,0,0,0,7,0,0,0,128,239,31,0,0,0,0,0,0,0,8,0,3,0,
  715. +0,0,0,0,192,127,0,30,0,0,0,0,0,0,0,0,0,0,0,128,211,64,0,0,0,0,0,0,0,0,0,0,0,0,
  716. +0,0,0,0,0,0,0,128,248,7,0,0,3,0,0,0,0,0,0,24,1,0,0,0,192,31,31,0,0,0,0,0,0,0,
  717. +0,0,0,0,0,0,0,0,0,
  718. +0,0,0,0,0,0,0,0,255,92,0,0,64,0,0,0,0,0,0,0,0,0,0,248,133,13,0,0,0,0,0,0,0,0,
  719. +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,60,176,1,0,0,48,0,0,0,0,0,0,0,0,0,0,
  720. +248,167,1,0,0,0,0,0,0,0,0,0,0,0,0,40,191,0,0,0,0,0,0,0,0,0,0,0,0,224,188,15,0,
  721. +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,255,6,0,0,0,0,
  722. +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  723. +0,0,0,0,0,0,0,240,12,1,0,0,0,254,7,0,0,0,0,248,121,128,0,126,14,0,0,0,0,0,252,
  724. +127,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,191,0,0,0,0,0,0,0,0,0,0,252,255,
  725. +255,252,109,0,0,0,0,0,0,0,0,
  726. +0,0,0,0,0,0,0,126,180,191,0,0,0,0,0,0,0,0,0,163,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  727. +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,0,0,0,0,0,0,0,255,
  728. +1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  729. +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,0,0,0,0,0,0,0,127,0,0,0,0,0,0,0,0,0,0,0,0,
  730. +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,128,7,0,0,0,0,0,
  731. +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,15,0,0,0,0,0,0,0,0,0,
  732. +0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,248,255,231,15,0,0,0,60,0,0,0,0,0,0,0,0,0,
  733. +0,0,0,0,0,0,0,0,0,28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,
  734. +255,255,255,255,127,248,255,255,255,255,255,31,32,0,16,0,0,248,254,255,0,0,0,
  735. +0,0,0,0,0,0,0,127,255,255,249,219,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  736. +0,0,0,0,0,0,0,0,0,0,0,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  737. +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,0,0,0,0,0,0,0,0,0,
  738. +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,0,0,0,0,0,0,0,0,0,0,0,0,0,240,7,0,0,
  739. +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  740. diff --git a/src/env/__libc_start_main.c b/src/env/__libc_start_main.c
  741. index 8fbe5262..c5b277bd 100644
  742. --- a/src/env/__libc_start_main.c
  743. +++ b/src/env/__libc_start_main.c
  744. @@ -69,7 +69,8 @@ weak_alias(libc_start_init, __libc_start_init);
  745. typedef int lsm2_fn(int (*)(int,char **,char **), int, char **);
  746. static lsm2_fn libc_start_main_stage2;
  747. -int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
  748. +int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv,
  749. + void (*init_dummy)(), void(*fini_dummy)(), void(*ldso_dummy)())
  750. {
  751. char **envp = argv+argc+1;
  752. diff --git a/src/errno/__strerror.h b/src/errno/__strerror.h
  753. index 2d992da5..14925907 100644
  754. --- a/src/errno/__strerror.h
  755. +++ b/src/errno/__strerror.h
  756. @@ -102,3 +102,7 @@ E(EDQUOT, "Quota exceeded")
  757. E(ENOMEDIUM, "No medium found")
  758. E(EMEDIUMTYPE, "Wrong medium type")
  759. E(EMULTIHOP, "Multihop attempted")
  760. +E(ENOKEY, "Required key not available")
  761. +E(EKEYEXPIRED, "Key has expired")
  762. +E(EKEYREVOKED, "Key has been revoked")
  763. +E(EKEYREJECTED, "Key was rejected by service")
  764. diff --git a/src/fenv/powerpc/fenv-sf.c b/src/fenv/powerpc/fenv-sf.c
  765. index 85bef40f..d4248f26 100644
  766. --- a/src/fenv/powerpc/fenv-sf.c
  767. +++ b/src/fenv/powerpc/fenv-sf.c
  768. @@ -1,3 +1,3 @@
  769. -#ifdef _SOFT_FLOAT
  770. +#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
  771. #include "../fenv.c"
  772. #endif
  773. diff --git a/src/fenv/powerpc/fenv.S b/src/fenv/powerpc/fenv.S
  774. index 22cea216..55055d0b 100644
  775. --- a/src/fenv/powerpc/fenv.S
  776. +++ b/src/fenv/powerpc/fenv.S
  777. @@ -1,4 +1,4 @@
  778. -#ifndef _SOFT_FLOAT
  779. +#if !defined(_SOFT_FLOAT) && !defined(__NO_FPRS__)
  780. .global feclearexcept
  781. .type feclearexcept,@function
  782. feclearexcept:
  783. diff --git a/src/include/stdlib.h b/src/include/stdlib.h
  784. index e9da2015..812b04de 100644
  785. --- a/src/include/stdlib.h
  786. +++ b/src/include/stdlib.h
  787. @@ -8,6 +8,7 @@ hidden void __env_rm_add(char *, char *);
  788. hidden int __mkostemps(char *, int, int);
  789. hidden int __ptsname_r(int, char *, size_t);
  790. hidden char *__randname(char *);
  791. +hidden void __qsort_r (void *, size_t, size_t, int (*)(const void *, const void *, void *), void *);
  792. hidden void *__libc_malloc(size_t);
  793. hidden void *__libc_malloc_impl(size_t);
  794. diff --git a/src/ldso/dl_iterate_phdr.c b/src/ldso/dl_iterate_phdr.c
  795. index 86c87ef8..9546dd36 100644
  796. --- a/src/ldso/dl_iterate_phdr.c
  797. +++ b/src/ldso/dl_iterate_phdr.c
  798. @@ -1,5 +1,6 @@
  799. #include <elf.h>
  800. #include <link.h>
  801. +#include "pthread_impl.h"
  802. #include "libc.h"
  803. #define AUX_CNT 38
  804. @@ -35,7 +36,7 @@ static int static_dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size
  805. info.dlpi_subs = 0;
  806. if (tls_phdr) {
  807. info.dlpi_tls_modid = 1;
  808. - info.dlpi_tls_data = (void *)(base + tls_phdr->p_vaddr);
  809. + info.dlpi_tls_data = __tls_get_addr((tls_mod_off_t[]){1,0});
  810. } else {
  811. info.dlpi_tls_modid = 0;
  812. info.dlpi_tls_data = 0;
  813. diff --git a/src/legacy/cuserid.c b/src/legacy/cuserid.c
  814. index 4e78798d..dcaf73d4 100644
  815. --- a/src/legacy/cuserid.c
  816. +++ b/src/legacy/cuserid.c
  817. @@ -2,13 +2,21 @@
  818. #include <pwd.h>
  819. #include <stdio.h>
  820. #include <unistd.h>
  821. +#include <string.h>
  822. char *cuserid(char *buf)
  823. {
  824. + static char usridbuf[L_cuserid];
  825. struct passwd pw, *ppw;
  826. long pwb[256];
  827. - if (getpwuid_r(geteuid(), &pw, (void *)pwb, sizeof pwb, &ppw))
  828. - return 0;
  829. - snprintf(buf, L_cuserid, "%s", pw.pw_name);
  830. + if (buf) *buf = 0;
  831. + getpwuid_r(geteuid(), &pw, (void *)pwb, sizeof pwb, &ppw);
  832. + if (!ppw)
  833. + return buf;
  834. + size_t len = strnlen(pw.pw_name, L_cuserid);
  835. + if (len == L_cuserid)
  836. + return buf;
  837. + if (!buf) buf = usridbuf;
  838. + memcpy(buf, pw.pw_name, len+1);
  839. return buf;
  840. }
  841. diff --git a/src/linux/epoll.c b/src/linux/epoll.c
  842. index deff5b10..93baa814 100644
  843. --- a/src/linux/epoll.c
  844. +++ b/src/linux/epoll.c
  845. @@ -24,9 +24,9 @@ int epoll_ctl(int fd, int op, int fd2, struct epoll_event *ev)
  846. int epoll_pwait(int fd, struct epoll_event *ev, int cnt, int to, const sigset_t *sigs)
  847. {
  848. - int r = __syscall(SYS_epoll_pwait, fd, ev, cnt, to, sigs, _NSIG/8);
  849. + int r = __syscall_cp(SYS_epoll_pwait, fd, ev, cnt, to, sigs, _NSIG/8);
  850. #ifdef SYS_epoll_wait
  851. - if (r==-ENOSYS && !sigs) r = __syscall(SYS_epoll_wait, fd, ev, cnt, to);
  852. + if (r==-ENOSYS && !sigs) r = __syscall_cp(SYS_epoll_wait, fd, ev, cnt, to);
  853. #endif
  854. return __syscall_ret(r);
  855. }
  856. diff --git a/src/locale/strtod_l.c b/src/locale/strtod_l.c
  857. new file mode 100644
  858. index 00000000..574ba148
  859. --- /dev/null
  860. +++ b/src/locale/strtod_l.c
  861. @@ -0,0 +1,22 @@
  862. +#define _GNU_SOURCE
  863. +#include <stdlib.h>
  864. +#include <locale.h>
  865. +
  866. +float strtof_l(const char *restrict s, char **restrict p, locale_t l)
  867. +{
  868. + return strtof(s, p);
  869. +}
  870. +
  871. +double strtod_l(const char *restrict s, char **restrict p, locale_t l)
  872. +{
  873. + return strtod(s, p);
  874. +}
  875. +
  876. +long double strtold_l(const char *restrict s, char **restrict p, locale_t l)
  877. +{
  878. + return strtold(s, p);
  879. +}
  880. +
  881. +weak_alias(strtof_l, __strtof_l);
  882. +weak_alias(strtod_l, __strtod_l);
  883. +weak_alias(strtold_l, __strtold_l);
  884. diff --git a/src/malloc/free.c b/src/malloc/free.c
  885. index f17a952c..3944f7b2 100644
  886. --- a/src/malloc/free.c
  887. +++ b/src/malloc/free.c
  888. @@ -2,5 +2,5 @@
  889. void free(void *p)
  890. {
  891. - return __libc_free(p);
  892. + __libc_free(p);
  893. }
  894. diff --git a/src/malloc/mallocng/aligned_alloc.c b/src/malloc/mallocng/aligned_alloc.c
  895. index 34116896..e0862a83 100644
  896. --- a/src/malloc/mallocng/aligned_alloc.c
  897. +++ b/src/malloc/mallocng/aligned_alloc.c
  898. @@ -22,6 +22,9 @@ void *aligned_alloc(size_t align, size_t len)
  899. if (align <= UNIT) align = UNIT;
  900. unsigned char *p = malloc(len + align - UNIT);
  901. + if (!p)
  902. + return 0;
  903. +
  904. struct meta *g = get_meta(p);
  905. int idx = get_slot_index(p);
  906. size_t stride = get_stride(g);
  907. diff --git a/src/malloc/mallocng/free.c b/src/malloc/mallocng/free.c
  908. index 40745f97..418a085c 100644
  909. --- a/src/malloc/mallocng/free.c
  910. +++ b/src/malloc/mallocng/free.c
  911. @@ -119,7 +119,11 @@ void free(void *p)
  912. if (((uintptr_t)(start-1) ^ (uintptr_t)end) >= 2*PGSZ && g->last_idx) {
  913. unsigned char *base = start + (-(uintptr_t)start & (PGSZ-1));
  914. size_t len = (end-base) & -PGSZ;
  915. - if (len) madvise(base, len, MADV_FREE);
  916. + if (len) {
  917. + int e = errno;
  918. + madvise(base, len, MADV_FREE);
  919. + errno = e;
  920. + }
  921. }
  922. // atomic free without locking if this is neither first or last slot
  923. @@ -139,5 +143,9 @@ void free(void *p)
  924. wrlock();
  925. struct mapinfo mi = nontrivial_free(g, idx);
  926. unlock();
  927. - if (mi.len) munmap(mi.base, mi.len);
  928. + if (mi.len) {
  929. + int e = errno;
  930. + munmap(mi.base, mi.len);
  931. + errno = e;
  932. + }
  933. }
  934. diff --git a/src/malloc/oldmalloc/malloc.c b/src/malloc/oldmalloc/malloc.c
  935. index 53f5f959..25d00d44 100644
  936. --- a/src/malloc/oldmalloc/malloc.c
  937. +++ b/src/malloc/oldmalloc/malloc.c
  938. @@ -11,7 +11,7 @@
  939. #include "malloc_impl.h"
  940. #include "fork_impl.h"
  941. -#define malloc __libc_malloc
  942. +#define malloc __libc_malloc_impl
  943. #define realloc __libc_realloc
  944. #define free __libc_free
  945. @@ -481,12 +481,14 @@ void __bin_chunk(struct chunk *self)
  946. if (size > RECLAIM && (size^(size-osize)) > size-osize) {
  947. uintptr_t a = (uintptr_t)self + SIZE_ALIGN+PAGE_SIZE-1 & -PAGE_SIZE;
  948. uintptr_t b = (uintptr_t)next - SIZE_ALIGN & -PAGE_SIZE;
  949. + int e = errno;
  950. #if 1
  951. __madvise((void *)a, b-a, MADV_DONTNEED);
  952. #else
  953. __mmap((void *)a, b-a, PROT_READ|PROT_WRITE,
  954. MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0);
  955. #endif
  956. + errno = e;
  957. }
  958. unlock_bin(i);
  959. @@ -499,7 +501,9 @@ static void unmap_chunk(struct chunk *self)
  960. size_t len = CHUNK_SIZE(self) + extra;
  961. /* Crash on double free */
  962. if (extra & 1) a_crash();
  963. + int e = errno;
  964. __munmap(base, len);
  965. + errno = e;
  966. }
  967. void free(void *p)
  968. diff --git a/src/math/acoshf.c b/src/math/acoshf.c
  969. index 8a4ec4d5..b773d48e 100644
  970. --- a/src/math/acoshf.c
  971. +++ b/src/math/acoshf.c
  972. @@ -15,12 +15,12 @@ float acoshf(float x)
  973. uint32_t a = u.i & 0x7fffffff;
  974. if (a < 0x3f800000+(1<<23))
  975. - /* |x| < 2, invalid if x < 1 or nan */
  976. + /* |x| < 2, invalid if x < 1 */
  977. /* up to 2ulp error in [1,1.125] */
  978. return log1pf(x-1 + sqrtf((x-1)*(x-1)+2*(x-1)));
  979. - if (a < 0x3f800000+(12<<23))
  980. - /* |x| < 0x1p12 */
  981. + if (u.i < 0x3f800000+(12<<23))
  982. + /* 2 <= x < 0x1p12 */
  983. return logf(2*x - 1/(x+sqrtf(x*x-1)));
  984. - /* x >= 0x1p12 */
  985. + /* x >= 0x1p12 or x <= -2 or nan */
  986. return logf(x) + 0.693147180559945309417232121458176568f;
  987. }
  988. diff --git a/src/math/expm1f.c b/src/math/expm1f.c
  989. index 297e0b44..09a41afe 100644
  990. --- a/src/math/expm1f.c
  991. +++ b/src/math/expm1f.c
  992. @@ -16,7 +16,6 @@
  993. #include "libm.h"
  994. static const float
  995. -o_threshold = 8.8721679688e+01, /* 0x42b17180 */
  996. ln2_hi = 6.9313812256e-01, /* 0x3f317180 */
  997. ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */
  998. invln2 = 1.4426950216e+00, /* 0x3fb8aa3b */
  999. @@ -41,7 +40,7 @@ float expm1f(float x)
  1000. return x;
  1001. if (sign)
  1002. return -1;
  1003. - if (x > o_threshold) {
  1004. + if (hx > 0x42b17217) { /* x > log(FLT_MAX) */
  1005. x *= 0x1p127f;
  1006. return x;
  1007. }
  1008. diff --git a/src/math/fmaf.c b/src/math/fmaf.c
  1009. index 80f5cd8a..7c65acf1 100644
  1010. --- a/src/math/fmaf.c
  1011. +++ b/src/math/fmaf.c
  1012. @@ -77,17 +77,16 @@ float fmaf(float x, float y, float z)
  1013. * If result is inexact, and exactly halfway between two float values,
  1014. * we need to adjust the low-order bit in the direction of the error.
  1015. */
  1016. -#ifdef FE_TOWARDZERO
  1017. - fesetround(FE_TOWARDZERO);
  1018. -#endif
  1019. - volatile double vxy = xy; /* XXX work around gcc CSE bug */
  1020. - double adjusted_result = vxy + z;
  1021. - fesetround(FE_TONEAREST);
  1022. - if (result == adjusted_result) {
  1023. - u.f = adjusted_result;
  1024. + double err;
  1025. + int neg = u.i >> 63;
  1026. + if (neg == (z > xy))
  1027. + err = xy - result + z;
  1028. + else
  1029. + err = z - result + xy;
  1030. + if (neg == (err < 0))
  1031. u.i++;
  1032. - adjusted_result = u.f;
  1033. - }
  1034. - z = adjusted_result;
  1035. + else
  1036. + u.i--;
  1037. + z = u.f;
  1038. return z;
  1039. }
  1040. diff --git a/src/math/powerpc/fabs.c b/src/math/powerpc/fabs.c
  1041. index 0efc21ef..9453a3aa 100644
  1042. --- a/src/math/powerpc/fabs.c
  1043. +++ b/src/math/powerpc/fabs.c
  1044. @@ -1,6 +1,6 @@
  1045. #include <math.h>
  1046. -#if defined(_SOFT_FLOAT) || defined(BROKEN_PPC_D_ASM)
  1047. +#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__) || defined(BROKEN_PPC_D_ASM)
  1048. #include "../fabs.c"
  1049. diff --git a/src/math/powerpc/fabsf.c b/src/math/powerpc/fabsf.c
  1050. index d88b5911..2e9da588 100644
  1051. --- a/src/math/powerpc/fabsf.c
  1052. +++ b/src/math/powerpc/fabsf.c
  1053. @@ -1,6 +1,6 @@
  1054. #include <math.h>
  1055. -#ifdef _SOFT_FLOAT
  1056. +#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
  1057. #include "../fabsf.c"
  1058. diff --git a/src/math/powerpc/fma.c b/src/math/powerpc/fma.c
  1059. index 135c9903..0eb2ba1e 100644
  1060. --- a/src/math/powerpc/fma.c
  1061. +++ b/src/math/powerpc/fma.c
  1062. @@ -1,6 +1,6 @@
  1063. #include <math.h>
  1064. -#if defined(_SOFT_FLOAT) || defined(BROKEN_PPC_D_ASM)
  1065. +#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__) || defined(BROKEN_PPC_D_ASM)
  1066. #include "../fma.c"
  1067. diff --git a/src/math/powerpc/fmaf.c b/src/math/powerpc/fmaf.c
  1068. index a99a2a3b..dc1a749d 100644
  1069. --- a/src/math/powerpc/fmaf.c
  1070. +++ b/src/math/powerpc/fmaf.c
  1071. @@ -1,6 +1,6 @@
  1072. #include <math.h>
  1073. -#ifdef _SOFT_FLOAT
  1074. +#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
  1075. #include "../fmaf.c"
  1076. diff --git a/src/misc/ioctl.c b/src/misc/ioctl.c
  1077. index 49282811..35804f02 100644
  1078. --- a/src/misc/ioctl.c
  1079. +++ b/src/misc/ioctl.c
  1080. @@ -6,6 +6,7 @@
  1081. #include <stddef.h>
  1082. #include <stdint.h>
  1083. #include <string.h>
  1084. +#include <endian.h>
  1085. #include "syscall.h"
  1086. #define alignof(t) offsetof(struct { char c; t x; }, x)
  1087. @@ -53,7 +54,7 @@ static const struct ioctl_compat_map compat_map[] = {
  1088. { _IOWR('A', 0x23, char[136]), _IOWR('A', 0x23, char[132]), 0, WR, 1, 0 },
  1089. { 0, 0, 4, WR, 1, 0 }, /* snd_pcm_sync_ptr (flags only) */
  1090. { 0, 0, 32, WR, 1, OFFS(8,12,16,24,28) }, /* snd_pcm_mmap_status */
  1091. - { 0, 0, 8, WR, 1, OFFS(0,4) }, /* snd_pcm_mmap_control */
  1092. + { 0, 0, 4, WR, 1, 0 }, /* snd_pcm_mmap_control (each member) */
  1093. /* VIDIOC_QUERYBUF, VIDIOC_QBUF, VIDIOC_DQBUF, VIDIOC_PREPARE_BUF */
  1094. { _IOWR('V', 9, new_misaligned(68)), _IOWR('V', 9, char[68]), 68, WR, 1, OFFS(20, 24) },
  1095. @@ -90,7 +91,11 @@ static void convert_ioctl_struct(const struct ioctl_compat_map *map, char *old,
  1096. * if another exception appears this needs changing. */
  1097. convert_ioctl_struct(map+1, old, new, dir);
  1098. convert_ioctl_struct(map+2, old+4, new+8, dir);
  1099. - convert_ioctl_struct(map+3, old+68, new+72, dir);
  1100. + /* snd_pcm_mmap_control, special-cased due to kernel
  1101. + * type definition having been botched. */
  1102. + int adj = BYTE_ORDER==BIG_ENDIAN ? 4 : 0;
  1103. + convert_ioctl_struct(map+3, old+68, new+72+adj, dir);
  1104. + convert_ioctl_struct(map+3, old+72, new+76+3*adj, dir);
  1105. return;
  1106. }
  1107. for (int i=0; i < map->noffs; i++) {
  1108. diff --git a/src/passwd/nscd_query.c b/src/passwd/nscd_query.c
  1109. index d38e371b..dc3406b8 100644
  1110. --- a/src/passwd/nscd_query.c
  1111. +++ b/src/passwd/nscd_query.c
  1112. @@ -40,7 +40,15 @@ retry:
  1113. buf[0] = NSCDVERSION;
  1114. fd = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
  1115. - if (fd < 0) return NULL;
  1116. + if (fd < 0) {
  1117. + if (errno == EAFNOSUPPORT) {
  1118. + f = fopen("/dev/null", "re");
  1119. + if (f)
  1120. + errno = errno_save;
  1121. + return f;
  1122. + }
  1123. + return 0;
  1124. + }
  1125. if(!(f = fdopen(fd, "r"))) {
  1126. close(fd);
  1127. diff --git a/src/process/fdop.h b/src/process/fdop.h
  1128. index 5adf1443..7cf733b2 100644
  1129. --- a/src/process/fdop.h
  1130. +++ b/src/process/fdop.h
  1131. @@ -10,3 +10,8 @@ struct fdop {
  1132. mode_t mode;
  1133. char path[];
  1134. };
  1135. +
  1136. +#define malloc __libc_malloc
  1137. +#define calloc __libc_calloc
  1138. +#define realloc undef
  1139. +#define free __libc_free
  1140. diff --git a/src/process/posix_spawn_file_actions_addclose.c b/src/process/posix_spawn_file_actions_addclose.c
  1141. index cdda5979..0c2ef8fa 100644
  1142. --- a/src/process/posix_spawn_file_actions_addclose.c
  1143. +++ b/src/process/posix_spawn_file_actions_addclose.c
  1144. @@ -5,6 +5,7 @@
  1145. int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *fa, int fd)
  1146. {
  1147. + if (fd < 0) return EBADF;
  1148. struct fdop *op = malloc(sizeof *op);
  1149. if (!op) return ENOMEM;
  1150. op->cmd = FDOP_CLOSE;
  1151. diff --git a/src/process/posix_spawn_file_actions_adddup2.c b/src/process/posix_spawn_file_actions_adddup2.c
  1152. index 0367498f..addca4d4 100644
  1153. --- a/src/process/posix_spawn_file_actions_adddup2.c
  1154. +++ b/src/process/posix_spawn_file_actions_adddup2.c
  1155. @@ -5,6 +5,7 @@
  1156. int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *fa, int srcfd, int fd)
  1157. {
  1158. + if (srcfd < 0 || fd < 0) return EBADF;
  1159. struct fdop *op = malloc(sizeof *op);
  1160. if (!op) return ENOMEM;
  1161. op->cmd = FDOP_DUP2;
  1162. diff --git a/src/process/posix_spawn_file_actions_addfchdir.c b/src/process/posix_spawn_file_actions_addfchdir.c
  1163. index 436c683d..e89ede8c 100644
  1164. --- a/src/process/posix_spawn_file_actions_addfchdir.c
  1165. +++ b/src/process/posix_spawn_file_actions_addfchdir.c
  1166. @@ -6,6 +6,7 @@
  1167. int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *fa, int fd)
  1168. {
  1169. + if (fd < 0) return EBADF;
  1170. struct fdop *op = malloc(sizeof *op);
  1171. if (!op) return ENOMEM;
  1172. op->cmd = FDOP_FCHDIR;
  1173. diff --git a/src/process/posix_spawn_file_actions_addopen.c b/src/process/posix_spawn_file_actions_addopen.c
  1174. index 368922c7..82bbcec9 100644
  1175. --- a/src/process/posix_spawn_file_actions_addopen.c
  1176. +++ b/src/process/posix_spawn_file_actions_addopen.c
  1177. @@ -6,6 +6,7 @@
  1178. int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *restrict fa, int fd, const char *restrict path, int flags, mode_t mode)
  1179. {
  1180. + if (fd < 0) return EBADF;
  1181. struct fdop *op = malloc(sizeof *op + strlen(path) + 1);
  1182. if (!op) return ENOMEM;
  1183. op->cmd = FDOP_OPEN;
  1184. diff --git a/src/setjmp/powerpc/longjmp.S b/src/setjmp/powerpc/longjmp.S
  1185. index e598bd05..611389fe 100644
  1186. --- a/src/setjmp/powerpc/longjmp.S
  1187. +++ b/src/setjmp/powerpc/longjmp.S
  1188. @@ -37,7 +37,37 @@ longjmp:
  1189. lwz 29, 72(3)
  1190. lwz 30, 76(3)
  1191. lwz 31, 80(3)
  1192. -#ifndef _SOFT_FLOAT
  1193. +#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
  1194. + mflr 0
  1195. + bl 1f
  1196. + .hidden __hwcap
  1197. + .long __hwcap-.
  1198. +1: mflr 4
  1199. + lwz 5, 0(4)
  1200. + lwzx 4, 4, 5
  1201. + andis. 4, 4, 0x80
  1202. + beq 1f
  1203. + .long 0x11c35b01 /* evldd 14,88(3) */
  1204. + .long 0x11e36301 /* ... */
  1205. + .long 0x12036b01
  1206. + .long 0x12237301
  1207. + .long 0x12437b01
  1208. + .long 0x12638301
  1209. + .long 0x12838b01
  1210. + .long 0x12a39301
  1211. + .long 0x12c39b01
  1212. + .long 0x12e3a301
  1213. + .long 0x1303ab01
  1214. + .long 0x1323b301
  1215. + .long 0x1343bb01
  1216. + .long 0x1363c301
  1217. + .long 0x1383cb01
  1218. + .long 0x13a3d301
  1219. + .long 0x13c3db01
  1220. + .long 0x13e3e301 /* evldd 31,224(3) */
  1221. + .long 0x11a3eb01 /* evldd 13,232(3) */
  1222. +1: mtlr 0
  1223. +#else
  1224. lfd 14,88(3)
  1225. lfd 15,96(3)
  1226. lfd 16,104(3)
  1227. diff --git a/src/setjmp/powerpc/setjmp.S b/src/setjmp/powerpc/setjmp.S
  1228. index cd91a207..f1fcce33 100644
  1229. --- a/src/setjmp/powerpc/setjmp.S
  1230. +++ b/src/setjmp/powerpc/setjmp.S
  1231. @@ -37,7 +37,37 @@ setjmp:
  1232. stw 29, 72(3)
  1233. stw 30, 76(3)
  1234. stw 31, 80(3)
  1235. -#ifndef _SOFT_FLOAT
  1236. +#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
  1237. + mflr 0
  1238. + bl 1f
  1239. + .hidden __hwcap
  1240. + .long __hwcap-.
  1241. +1: mflr 4
  1242. + lwz 5, 0(4)
  1243. + lwzx 4, 4, 5
  1244. + andis. 4, 4, 0x80
  1245. + beq 1f
  1246. + .long 0x11c35b21 /* evstdd 14,88(3) */
  1247. + .long 0x11e36321 /* ... */
  1248. + .long 0x12036b21
  1249. + .long 0x12237321
  1250. + .long 0x12437b21
  1251. + .long 0x12638321
  1252. + .long 0x12838b21
  1253. + .long 0x12a39321
  1254. + .long 0x12c39b21
  1255. + .long 0x12e3a321
  1256. + .long 0x1303ab21
  1257. + .long 0x1323b321
  1258. + .long 0x1343bb21
  1259. + .long 0x1363c321
  1260. + .long 0x1383cb21
  1261. + .long 0x13a3d321
  1262. + .long 0x13c3db21
  1263. + .long 0x13e3e321 /* evstdd 31,224(3) */
  1264. + .long 0x11a3eb21 /* evstdd 13,232(3) */
  1265. +1: mtlr 0
  1266. +#else
  1267. stfd 14,88(3)
  1268. stfd 15,96(3)
  1269. stfd 16,104(3)
  1270. diff --git a/src/signal/block.c b/src/signal/block.c
  1271. index d7f61001..cc8698f0 100644
  1272. --- a/src/signal/block.c
  1273. +++ b/src/signal/block.c
  1274. @@ -3,9 +3,9 @@
  1275. #include <signal.h>
  1276. static const unsigned long all_mask[] = {
  1277. -#if ULONG_MAX == 0xffffffff && _NSIG == 129
  1278. +#if ULONG_MAX == 0xffffffff && _NSIG > 65
  1279. -1UL, -1UL, -1UL, -1UL
  1280. -#elif ULONG_MAX == 0xffffffff
  1281. +#elif ULONG_MAX == 0xffffffff || _NSIG > 65
  1282. -1UL, -1UL
  1283. #else
  1284. -1UL
  1285. diff --git a/src/stdio/fgetws.c b/src/stdio/fgetws.c
  1286. index b08b3049..195cb435 100644
  1287. --- a/src/stdio/fgetws.c
  1288. +++ b/src/stdio/fgetws.c
  1289. @@ -1,6 +1,5 @@
  1290. #include "stdio_impl.h"
  1291. #include <wchar.h>
  1292. -#include <errno.h>
  1293. wint_t __fgetwc_unlocked(FILE *);
  1294. @@ -12,10 +11,6 @@ wchar_t *fgetws(wchar_t *restrict s, int n, FILE *restrict f)
  1295. FLOCK(f);
  1296. - /* Setup a dummy errno so we can detect EILSEQ. This is
  1297. - * the only way to catch encoding errors in the form of a
  1298. - * partial character just before EOF. */
  1299. - errno = EAGAIN;
  1300. for (; n; n--) {
  1301. wint_t c = __fgetwc_unlocked(f);
  1302. if (c == WEOF) break;
  1303. @@ -23,7 +18,7 @@ wchar_t *fgetws(wchar_t *restrict s, int n, FILE *restrict f)
  1304. if (c == '\n') break;
  1305. }
  1306. *p = 0;
  1307. - if (ferror(f) || errno==EILSEQ) p = s;
  1308. + if (ferror(f)) p = s;
  1309. FUNLOCK(f);
  1310. diff --git a/src/stdio/fseek.c b/src/stdio/fseek.c
  1311. index 439308f7..c07f7e95 100644
  1312. --- a/src/stdio/fseek.c
  1313. +++ b/src/stdio/fseek.c
  1314. @@ -1,7 +1,14 @@
  1315. #include "stdio_impl.h"
  1316. +#include <errno.h>
  1317. int __fseeko_unlocked(FILE *f, off_t off, int whence)
  1318. {
  1319. + /* Fail immediately for invalid whence argument. */
  1320. + if (whence != SEEK_CUR && whence != SEEK_SET && whence != SEEK_END) {
  1321. + errno = EINVAL;
  1322. + return -1;
  1323. + }
  1324. +
  1325. /* Adjust relative offset for unread data in buffer, if any. */
  1326. if (whence == SEEK_CUR && f->rend) off -= f->rend - f->rpos;
  1327. diff --git a/src/stdio/getdelim.c b/src/stdio/getdelim.c
  1328. index d2f5b15a..df114441 100644
  1329. --- a/src/stdio/getdelim.c
  1330. +++ b/src/stdio/getdelim.c
  1331. @@ -55,9 +55,11 @@ ssize_t getdelim(char **restrict s, size_t *restrict n, int delim, FILE *restric
  1332. *s = tmp;
  1333. *n = m;
  1334. }
  1335. - memcpy(*s+i, f->rpos, k);
  1336. - f->rpos += k;
  1337. - i += k;
  1338. + if (k) {
  1339. + memcpy(*s+i, f->rpos, k);
  1340. + f->rpos += k;
  1341. + i += k;
  1342. + }
  1343. if (z) break;
  1344. if ((c = getc_unlocked(f)) == EOF) {
  1345. if (!i || !feof(f)) {
  1346. diff --git a/src/stdio/popen.c b/src/stdio/popen.c
  1347. index 92cb57ee..3ec83394 100644
  1348. --- a/src/stdio/popen.c
  1349. +++ b/src/stdio/popen.c
  1350. @@ -31,25 +31,12 @@ FILE *popen(const char *cmd, const char *mode)
  1351. __syscall(SYS_close, p[1]);
  1352. return NULL;
  1353. }
  1354. - FLOCK(f);
  1355. -
  1356. - /* If the child's end of the pipe happens to already be on the final
  1357. - * fd number to which it will be assigned (either 0 or 1), it must
  1358. - * be moved to a different fd. Otherwise, there is no safe way to
  1359. - * remove the close-on-exec flag in the child without also creating
  1360. - * a file descriptor leak race condition in the parent. */
  1361. - if (p[1-op] == 1-op) {
  1362. - int tmp = fcntl(1-op, F_DUPFD_CLOEXEC, 0);
  1363. - if (tmp < 0) {
  1364. - e = errno;
  1365. - goto fail;
  1366. - }
  1367. - __syscall(SYS_close, p[1-op]);
  1368. - p[1-op] = tmp;
  1369. - }
  1370. e = ENOMEM;
  1371. if (!posix_spawn_file_actions_init(&fa)) {
  1372. + for (FILE *l = *__ofl_lock(); l; l=l->next)
  1373. + if (l->pipe_pid && posix_spawn_file_actions_addclose(&fa, l->fd))
  1374. + goto fail;
  1375. if (!posix_spawn_file_actions_adddup2(&fa, p[1-op], 1-op)) {
  1376. if (!(e = posix_spawn(&pid, "/bin/sh", &fa, 0,
  1377. (char *[]){ "sh", "-c", (char *)cmd, 0 }, __environ))) {
  1378. @@ -58,13 +45,14 @@ FILE *popen(const char *cmd, const char *mode)
  1379. if (!strchr(mode, 'e'))
  1380. fcntl(p[op], F_SETFD, 0);
  1381. __syscall(SYS_close, p[1-op]);
  1382. - FUNLOCK(f);
  1383. + __ofl_unlock();
  1384. return f;
  1385. }
  1386. }
  1387. +fail:
  1388. + __ofl_unlock();
  1389. posix_spawn_file_actions_destroy(&fa);
  1390. }
  1391. -fail:
  1392. fclose(f);
  1393. __syscall(SYS_close, p[1-op]);
  1394. diff --git a/src/stdlib/qsort.c b/src/stdlib/qsort.c
  1395. index da58fd31..314ddc29 100644
  1396. --- a/src/stdlib/qsort.c
  1397. +++ b/src/stdlib/qsort.c
  1398. @@ -24,6 +24,7 @@
  1399. /* Smoothsort, an adaptive variant of Heapsort. Memory usage: O(1).
  1400. Run time: Worst case O(n log n), close to O(n) in the mostly-sorted case. */
  1401. +#define _BSD_SOURCE
  1402. #include <stdint.h>
  1403. #include <stdlib.h>
  1404. #include <string.h>
  1405. @@ -31,7 +32,7 @@
  1406. #include "atomic.h"
  1407. #define ntz(x) a_ctz_l((x))
  1408. -typedef int (*cmpfun)(const void *, const void *);
  1409. +typedef int (*cmpfun)(const void *, const void *, void *);
  1410. static inline int pntz(size_t p[2]) {
  1411. int r = ntz(p[0] - 1);
  1412. @@ -88,7 +89,7 @@ static inline void shr(size_t p[2], int n)
  1413. p[1] >>= n;
  1414. }
  1415. -static void sift(unsigned char *head, size_t width, cmpfun cmp, int pshift, size_t lp[])
  1416. +static void sift(unsigned char *head, size_t width, cmpfun cmp, void *arg, int pshift, size_t lp[])
  1417. {
  1418. unsigned char *rt, *lf;
  1419. unsigned char *ar[14 * sizeof(size_t) + 1];
  1420. @@ -99,10 +100,10 @@ static void sift(unsigned char *head, size_t width, cmpfun cmp, int pshift, size
  1421. rt = head - width;
  1422. lf = head - width - lp[pshift - 2];
  1423. - if((*cmp)(ar[0], lf) >= 0 && (*cmp)(ar[0], rt) >= 0) {
  1424. + if(cmp(ar[0], lf, arg) >= 0 && cmp(ar[0], rt, arg) >= 0) {
  1425. break;
  1426. }
  1427. - if((*cmp)(lf, rt) >= 0) {
  1428. + if(cmp(lf, rt, arg) >= 0) {
  1429. ar[i++] = lf;
  1430. head = lf;
  1431. pshift -= 1;
  1432. @@ -115,7 +116,7 @@ static void sift(unsigned char *head, size_t width, cmpfun cmp, int pshift, size
  1433. cycle(width, ar, i);
  1434. }
  1435. -static void trinkle(unsigned char *head, size_t width, cmpfun cmp, size_t pp[2], int pshift, int trusty, size_t lp[])
  1436. +static void trinkle(unsigned char *head, size_t width, cmpfun cmp, void *arg, size_t pp[2], int pshift, int trusty, size_t lp[])
  1437. {
  1438. unsigned char *stepson,
  1439. *rt, *lf;
  1440. @@ -130,13 +131,13 @@ static void trinkle(unsigned char *head, size_t width, cmpfun cmp, size_t pp[2],
  1441. ar[0] = head;
  1442. while(p[0] != 1 || p[1] != 0) {
  1443. stepson = head - lp[pshift];
  1444. - if((*cmp)(stepson, ar[0]) <= 0) {
  1445. + if(cmp(stepson, ar[0], arg) <= 0) {
  1446. break;
  1447. }
  1448. if(!trusty && pshift > 1) {
  1449. rt = head - width;
  1450. lf = head - width - lp[pshift - 2];
  1451. - if((*cmp)(rt, stepson) >= 0 || (*cmp)(lf, stepson) >= 0) {
  1452. + if(cmp(rt, stepson, arg) >= 0 || cmp(lf, stepson, arg) >= 0) {
  1453. break;
  1454. }
  1455. }
  1456. @@ -150,11 +151,11 @@ static void trinkle(unsigned char *head, size_t width, cmpfun cmp, size_t pp[2],
  1457. }
  1458. if(!trusty) {
  1459. cycle(width, ar, i);
  1460. - sift(head, width, cmp, pshift, lp);
  1461. + sift(head, width, cmp, arg, pshift, lp);
  1462. }
  1463. }
  1464. -void qsort(void *base, size_t nel, size_t width, cmpfun cmp)
  1465. +void __qsort_r(void *base, size_t nel, size_t width, cmpfun cmp, void *arg)
  1466. {
  1467. size_t lp[12*sizeof(size_t)];
  1468. size_t i, size = width * nel;
  1469. @@ -173,16 +174,16 @@ void qsort(void *base, size_t nel, size_t width, cmpfun cmp)
  1470. while(head < high) {
  1471. if((p[0] & 3) == 3) {
  1472. - sift(head, width, cmp, pshift, lp);
  1473. + sift(head, width, cmp, arg, pshift, lp);
  1474. shr(p, 2);
  1475. pshift += 2;
  1476. } else {
  1477. if(lp[pshift - 1] >= high - head) {
  1478. - trinkle(head, width, cmp, p, pshift, 0, lp);
  1479. + trinkle(head, width, cmp, arg, p, pshift, 0, lp);
  1480. } else {
  1481. - sift(head, width, cmp, pshift, lp);
  1482. + sift(head, width, cmp, arg, pshift, lp);
  1483. }
  1484. -
  1485. +
  1486. if(pshift == 1) {
  1487. shl(p, 1);
  1488. pshift = 0;
  1489. @@ -191,12 +192,12 @@ void qsort(void *base, size_t nel, size_t width, cmpfun cmp)
  1490. pshift = 1;
  1491. }
  1492. }
  1493. -
  1494. +
  1495. p[0] |= 1;
  1496. head += width;
  1497. }
  1498. - trinkle(head, width, cmp, p, pshift, 0, lp);
  1499. + trinkle(head, width, cmp, arg, p, pshift, 0, lp);
  1500. while(pshift != 1 || p[0] != 1 || p[1] != 0) {
  1501. if(pshift <= 1) {
  1502. @@ -208,11 +209,13 @@ void qsort(void *base, size_t nel, size_t width, cmpfun cmp)
  1503. pshift -= 2;
  1504. p[0] ^= 7;
  1505. shr(p, 1);
  1506. - trinkle(head - lp[pshift] - width, width, cmp, p, pshift + 1, 1, lp);
  1507. + trinkle(head - lp[pshift] - width, width, cmp, arg, p, pshift + 1, 1, lp);
  1508. shl(p, 1);
  1509. p[0] |= 1;
  1510. - trinkle(head - width, width, cmp, p, pshift, 1, lp);
  1511. + trinkle(head - width, width, cmp, arg, p, pshift, 1, lp);
  1512. }
  1513. head -= width;
  1514. }
  1515. }
  1516. +
  1517. +weak_alias(__qsort_r, qsort_r);
  1518. diff --git a/src/stdlib/qsort_nr.c b/src/stdlib/qsort_nr.c
  1519. new file mode 100644
  1520. index 00000000..efe7ccec
  1521. --- /dev/null
  1522. +++ b/src/stdlib/qsort_nr.c
  1523. @@ -0,0 +1,14 @@
  1524. +#define _BSD_SOURCE
  1525. +#include <stdlib.h>
  1526. +
  1527. +typedef int (*cmpfun)(const void *, const void *);
  1528. +
  1529. +static int wrapper_cmp(const void *v1, const void *v2, void *cmp)
  1530. +{
  1531. + return ((cmpfun)cmp)(v1, v2);
  1532. +}
  1533. +
  1534. +void qsort(void *base, size_t nel, size_t width, cmpfun cmp)
  1535. +{
  1536. + __qsort_r(base, nel, width, wrapper_cmp, cmp);
  1537. +}
  1538. diff --git a/src/stdlib/strtod.c b/src/stdlib/strtod.c
  1539. index a5d0118a..39b9daad 100644
  1540. --- a/src/stdlib/strtod.c
  1541. +++ b/src/stdlib/strtod.c
  1542. @@ -28,10 +28,3 @@ long double strtold(const char *restrict s, char **restrict p)
  1543. {
  1544. return strtox(s, p, 2);
  1545. }
  1546. -
  1547. -weak_alias(strtof, strtof_l);
  1548. -weak_alias(strtod, strtod_l);
  1549. -weak_alias(strtold, strtold_l);
  1550. -weak_alias(strtof, __strtof_l);
  1551. -weak_alias(strtod, __strtod_l);
  1552. -weak_alias(strtold, __strtold_l);
  1553. diff --git a/src/thread/pthread_getname_np.c b/src/thread/pthread_getname_np.c
  1554. new file mode 100644
  1555. index 00000000..85504e45
  1556. --- /dev/null
  1557. +++ b/src/thread/pthread_getname_np.c
  1558. @@ -0,0 +1,25 @@
  1559. +#define _GNU_SOURCE
  1560. +#include <fcntl.h>
  1561. +#include <unistd.h>
  1562. +#include <sys/prctl.h>
  1563. +
  1564. +#include "pthread_impl.h"
  1565. +
  1566. +int pthread_getname_np(pthread_t thread, char *name, size_t len)
  1567. +{
  1568. + int fd, cs, status = 0;
  1569. + char f[sizeof "/proc/self/task//comm" + 3*sizeof(int)];
  1570. +
  1571. + if (len < 16) return ERANGE;
  1572. +
  1573. + if (thread == pthread_self())
  1574. + return prctl(PR_GET_NAME, (unsigned long)name, 0UL, 0UL, 0UL) ? errno : 0;
  1575. +
  1576. + snprintf(f, sizeof f, "/proc/self/task/%d/comm", thread->tid);
  1577. + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
  1578. + if ((fd = open(f, O_RDONLY|O_CLOEXEC)) < 0 || (len = read(fd, name, len)) == -1) status = errno;
  1579. + else name[len-1] = 0; /* remove trailing new line only if successful */
  1580. + if (fd >= 0) close(fd);
  1581. + pthread_setcancelstate(cs, 0);
  1582. + return status;
  1583. +}
  1584. diff --git a/src/thread/pthread_setname_np.c b/src/thread/pthread_setname_np.c
  1585. index 82d35e17..fc2d2306 100644
  1586. --- a/src/thread/pthread_setname_np.c
  1587. +++ b/src/thread/pthread_setname_np.c
  1588. @@ -19,7 +19,7 @@ int pthread_setname_np(pthread_t thread, const char *name)
  1589. snprintf(f, sizeof f, "/proc/self/task/%d/comm", thread->tid);
  1590. pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
  1591. - if ((fd = open(f, O_WRONLY)) < 0 || write(fd, name, len) < 0) status = errno;
  1592. + if ((fd = open(f, O_WRONLY|O_CLOEXEC)) < 0 || write(fd, name, len) < 0) status = errno;
  1593. if (fd >= 0) close(fd);
  1594. pthread_setcancelstate(cs, 0);
  1595. return status;
  1596. diff --git a/src/time/__tz.c b/src/time/__tz.c
  1597. index 09a6317e..c34b3eb7 100644
  1598. --- a/src/time/__tz.c
  1599. +++ b/src/time/__tz.c
  1600. @@ -4,6 +4,7 @@
  1601. #include <stdlib.h>
  1602. #include <string.h>
  1603. #include <sys/mman.h>
  1604. +#include <ctype.h>
  1605. #include "libc.h"
  1606. #include "lock.h"
  1607. #include "fork_impl.h"
  1608. @@ -154,10 +155,21 @@ static void do_tzset()
  1609. }
  1610. if (old_tz) memcpy(old_tz, s, i+1);
  1611. + int posix_form = 0;
  1612. + if (*s != ':') {
  1613. + p = s;
  1614. + char dummy_name[TZNAME_MAX+1];
  1615. + getname(dummy_name, &p);
  1616. + if (p!=s && (*p == '+' || *p == '-' || isdigit(*p)
  1617. + || !strcmp(dummy_name, "UTC")
  1618. + || !strcmp(dummy_name, "GMT")))
  1619. + posix_form = 1;
  1620. + }
  1621. +
  1622. /* Non-suid can use an absolute tzfile pathname or a relative
  1623. * pathame beginning with "."; in secure mode, only the
  1624. * standard path will be searched. */
  1625. - if (*s == ':' || ((p=strchr(s, '/')) && !memchr(s, ',', p-s))) {
  1626. + if (!posix_form) {
  1627. if (*s == ':') s++;
  1628. if (*s == '/' || *s == '.') {
  1629. if (!libc.secure || !strcmp(s, "/etc/localtime"))
  1630. @@ -281,22 +293,20 @@ static size_t scan_trans(long long t, int local, size_t *alt)
  1631. n = (index-trans)>>scale;
  1632. if (a == n-1) return -1;
  1633. if (a == 0) {
  1634. - x = zi_read32(trans + (a<<scale));
  1635. - if (scale == 3) x = x<<32 | zi_read32(trans + (a<<scale) + 4);
  1636. + x = zi_read32(trans);
  1637. + if (scale == 3) x = x<<32 | zi_read32(trans + 4);
  1638. else x = (int32_t)x;
  1639. - if (local) off = (int32_t)zi_read32(types + 6 * index[a-1]);
  1640. + /* Find the lowest non-DST type, or 0 if none. */
  1641. + size_t j = 0;
  1642. + for (size_t i=abbrevs-types; i; i-=6) {
  1643. + if (!types[i-6+4]) j = i-6;
  1644. + }
  1645. + if (local) off = (int32_t)zi_read32(types + j);
  1646. + /* If t is before first transition, use the above-found type
  1647. + * and the index-zero (after transition) type as the alt. */
  1648. if (t - off < (int64_t)x) {
  1649. - for (a=0; a<(abbrevs-types)/6; a++) {
  1650. - if (types[6*a+4] != types[4]) break;
  1651. - }
  1652. - if (a == (abbrevs-types)/6) a = 0;
  1653. - if (types[6*a+4]) {
  1654. - *alt = a;
  1655. - return 0;
  1656. - } else {
  1657. - *alt = 0;
  1658. - return a;
  1659. - }
  1660. + if (alt) *alt = index[0];
  1661. + return j/6;
  1662. }
  1663. }