xxx-xtensa-nptl.patch 113 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515
  1. diff -Nur uClibc-git/include/elf.h uClibc-xtensa/include/elf.h
  2. --- uClibc-git/include/elf.h 2014-06-02 17:40:33.826710944 +0200
  3. +++ uClibc-xtensa/include/elf.h 2014-06-03 16:03:19.065886532 +0200
  4. @@ -3072,8 +3071,11 @@
  5. #define R_XTENSA_SLOT12_ALT 47
  6. #define R_XTENSA_SLOT13_ALT 48
  7. #define R_XTENSA_SLOT14_ALT 49
  8. +#define R_XTENSA_TLSDESC_FN 50
  9. +#define R_XTENSA_TLSDESC_ARG 51
  10. +#define R_XTENSA_TLS_TPOFF 53
  11. /* Keep this the last entry. */
  12. -#define R_XTENSA_NUM 50
  13. +#define R_XTENSA_NUM 54
  14. /* C6X specific relocs */
  15. #define R_C6000_NONE 0
  16. diff -Nur uClibc-git/include/link.h uClibc-xtensa/include/link.h
  17. --- uClibc-git/include/link.h 2014-06-02 17:40:33.846711055 +0200
  18. +++ uClibc-xtensa/include/link.h 2014-06-03 15:28:27.185347373 +0200
  19. @@ -132,6 +132,8 @@
  20. size_t l_tls_modid;
  21. /* Nonzero if _dl_init_static_tls should be called for this module */
  22. unsigned int l_need_tls_init:1;
  23. + /* Address of TLS descriptor hash table. */
  24. + void *l_tlsdesc_table;
  25. #endif
  26. #endif
  27. };
  28. diff -Nur uClibc-git/ldso/include/dl-hash.h uClibc-xtensa/ldso/include/dl-hash.h
  29. --- uClibc-git/ldso/include/dl-hash.h 2014-06-02 17:40:33.902711365 +0200
  30. +++ uClibc-xtensa/ldso/include/dl-hash.h 2014-06-03 15:29:09.505536959 +0200
  31. @@ -70,6 +70,8 @@
  32. size_t l_tls_modid;
  33. /* Nonzero if _dl_init_static_tls should be called for this module */
  34. unsigned int l_need_tls_init:1;
  35. + /* Address of TLS descriptor hash table. */
  36. + void *l_tlsdesc_table;
  37. #endif
  38. ElfW(Addr) mapaddr;
  39. diff -Nur uClibc-git/ldso/include/inline-hashtab.h uClibc-xtensa/ldso/include/inline-hashtab.h
  40. --- uClibc-git/ldso/include/inline-hashtab.h 1970-01-01 01:00:00.000000000 +0100
  41. +++ uClibc-xtensa/ldso/include/inline-hashtab.h 2014-06-03 11:57:42.031052092 +0200
  42. @@ -0,0 +1,265 @@
  43. +/*
  44. + * The hashcode handling code below is heavily inspired in libiberty's
  45. + * hashtab code, but with most adaptation points and support for
  46. + * deleting elements removed.
  47. + *
  48. + * Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
  49. + * Contributed by Vladimir Makarov (vmakarov@cygnus.com).
  50. + */
  51. +
  52. +#ifndef INLINE_HASHTAB_H
  53. +# define INLINE_HASHTAB_H 1
  54. +
  55. +static __always_inline unsigned long
  56. +higher_prime_number(unsigned long n)
  57. +{
  58. + /* These are primes that are near, but slightly smaller than, a power of two. */
  59. + static const unsigned long primes[] = {
  60. + 7,
  61. + 13,
  62. + 31,
  63. + 61,
  64. + 127,
  65. + 251,
  66. + 509,
  67. + 1021,
  68. + 2039,
  69. + 4093,
  70. + 8191,
  71. + 16381,
  72. + 32749,
  73. + 65521,
  74. + 131071,
  75. + 262139,
  76. + 524287,
  77. + 1048573,
  78. + 2097143,
  79. + 4194301,
  80. + 8388593,
  81. + 16777213,
  82. + 33554393,
  83. + 67108859,
  84. + 134217689,
  85. + 268435399,
  86. + 536870909,
  87. + 1073741789,
  88. + /* 4294967291 */
  89. + ((unsigned long) 2147483647) + ((unsigned long) 2147483644),
  90. + };
  91. + const unsigned long *low = &primes[0];
  92. + const unsigned long *high = &primes[ARRAY_SIZE(primes)];
  93. +
  94. + while (low != high) {
  95. + const unsigned long *mid = low + (high - low) / 2;
  96. + if (n > *mid)
  97. + low = mid + 1;
  98. + else
  99. + high = mid;
  100. + }
  101. +
  102. +#if 0
  103. + /* If we've run out of primes, abort. */
  104. + if (n > *low) {
  105. + fprintf(stderr, "Cannot find prime bigger than %lu\n", n);
  106. + abort();
  107. + }
  108. +#endif
  109. +
  110. + return *low;
  111. +}
  112. +
  113. +struct funcdesc_ht
  114. +{
  115. + /* Table itself */
  116. + void **entries;
  117. +
  118. + /* Current size (in entries) of the hash table */
  119. + size_t size;
  120. +
  121. + /* Current number of elements */
  122. + size_t n_elements;
  123. +};
  124. +
  125. +static __always_inline struct funcdesc_ht *
  126. +htab_create(void)
  127. +{
  128. + struct funcdesc_ht *ht = _dl_malloc(sizeof(*ht));
  129. + size_t ent_size;
  130. +
  131. + if (!ht)
  132. + return NULL;
  133. + ht->size = 3;
  134. + ent_size = sizeof(void *) * ht->size;
  135. + ht->entries = _dl_malloc(ent_size);
  136. + if (!ht->entries)
  137. + return NULL;
  138. +
  139. + ht->n_elements = 0;
  140. + _dl_memset(ht->entries, 0, ent_size);
  141. +
  142. + return ht;
  143. +}
  144. +
  145. +/*
  146. + * This is only called from _dl_loadaddr_unmap, so it's safe to call
  147. + * _dl_free(). See the discussion below.
  148. + */
  149. +static __always_inline void
  150. +htab_delete(struct funcdesc_ht *htab)
  151. +{
  152. + size_t i;
  153. +
  154. + for (i = htab->size - 1; i >= 0; i--)
  155. + if (htab->entries[i])
  156. + _dl_free(htab->entries[i]);
  157. +
  158. + _dl_free(htab->entries);
  159. + _dl_free(htab);
  160. +}
  161. +
  162. +/*
  163. + * Similar to htab_find_slot, but without several unwanted side effects:
  164. + * - Does not call htab->eq_f when it finds an existing entry.
  165. + * - Does not change the count of elements/searches/collisions in the
  166. + * hash table.
  167. + * This function also assumes there are no deleted entries in the table.
  168. + * HASH is the hash value for the element to be inserted.
  169. + */
  170. +static __always_inline void **
  171. +find_empty_slot_for_expand(struct funcdesc_ht *htab, int hash)
  172. +{
  173. + size_t size = htab->size;
  174. + unsigned int index = hash % size;
  175. + void **slot = htab->entries + index;
  176. + int hash2;
  177. +
  178. + if (!*slot)
  179. + return slot;
  180. +
  181. + hash2 = 1 + hash % (size - 2);
  182. + for (;;) {
  183. + index += hash2;
  184. + if (index >= size)
  185. + index -= size;
  186. +
  187. + slot = htab->entries + index;
  188. + if (!*slot)
  189. + return slot;
  190. + }
  191. +}
  192. +
  193. +/*
  194. + * The following function changes size of memory allocated for the
  195. + * entries and repeatedly inserts the table elements. The occupancy
  196. + * of the table after the call will be about 50%. Naturally the hash
  197. + * table must already exist. Remember also that the place of the
  198. + * table entries is changed. If memory allocation failures are allowed,
  199. + * this function will return zero, indicating that the table could not be
  200. + * expanded. If all goes well, it will return a non-zero value.
  201. + */
  202. +static __always_inline int
  203. +htab_expand(struct funcdesc_ht *htab, int (*hash_fn) (void *))
  204. +{
  205. + void **oentries;
  206. + void **olimit;
  207. + void **p;
  208. + void **nentries;
  209. + size_t nsize;
  210. +
  211. + oentries = htab->entries;
  212. + olimit = oentries + htab->size;
  213. +
  214. + /*
  215. + * Resize only when table after removal of unused elements is either
  216. + * too full or too empty.
  217. + */
  218. + if (htab->n_elements * 2 > htab->size)
  219. + nsize = higher_prime_number(htab->n_elements * 2);
  220. + else
  221. + nsize = htab->size;
  222. +
  223. + nentries = _dl_malloc(sizeof(*nentries) * nsize);
  224. + _dl_memset(nentries, 0, sizeof(*nentries) * nsize);
  225. + if (nentries == NULL)
  226. + return 0;
  227. + htab->entries = nentries;
  228. + htab->size = nsize;
  229. +
  230. + p = oentries;
  231. + do {
  232. + if (*p)
  233. + *find_empty_slot_for_expand(htab, hash_fn(*p)) = *p;
  234. + p++;
  235. + } while (p < olimit);
  236. +
  237. +#if 0
  238. + /*
  239. + * We can't tell whether this was allocated by the _dl_malloc()
  240. + * built into ld.so or malloc() in the main executable or libc,
  241. + * and calling free() for something that wasn't malloc()ed could
  242. + * do Very Bad Things (TM). Take the conservative approach
  243. + * here, potentially wasting as much memory as actually used by
  244. + * the hash table, even if multiple growths occur. That's not
  245. + * so bad as to require some overengineered solution that would
  246. + * enable us to keep track of how it was allocated.
  247. + */
  248. + _dl_free(oentries);
  249. +#endif
  250. + return 1;
  251. +}
  252. +
  253. +/*
  254. + * This function searches for a hash table slot containing an entry
  255. + * equal to the given element. To delete an entry, call this with
  256. + * INSERT = 0, then call htab_clear_slot on the slot returned (possibly
  257. + * after doing some checks). To insert an entry, call this with
  258. + * INSERT = 1, then write the value you want into the returned slot.
  259. + * When inserting an entry, NULL may be returned if memory allocation
  260. + * fails.
  261. + */
  262. +static __always_inline void **
  263. +htab_find_slot(struct funcdesc_ht *htab, void *ptr, int insert,
  264. + int (*hash_fn)(void *), int (*eq_fn)(void *, void *))
  265. +{
  266. + unsigned int index;
  267. + int hash, hash2;
  268. + size_t size;
  269. + void **entry;
  270. +
  271. + if (htab->size * 3 <= htab->n_elements * 4 &&
  272. + htab_expand(htab, hash_fn) == 0)
  273. + return NULL;
  274. +
  275. + hash = hash_fn(ptr);
  276. +
  277. + size = htab->size;
  278. + index = hash % size;
  279. +
  280. + entry = &htab->entries[index];
  281. + if (!*entry)
  282. + goto empty_entry;
  283. + else if (eq_fn(*entry, ptr))
  284. + return entry;
  285. +
  286. + hash2 = 1 + hash % (size - 2);
  287. + for (;;) {
  288. + index += hash2;
  289. + if (index >= size)
  290. + index -= size;
  291. +
  292. + entry = &htab->entries[index];
  293. + if (!*entry)
  294. + goto empty_entry;
  295. + else if (eq_fn(*entry, ptr))
  296. + return entry;
  297. + }
  298. +
  299. + empty_entry:
  300. + if (!insert)
  301. + return NULL;
  302. +
  303. + htab->n_elements++;
  304. + return entry;
  305. +}
  306. +
  307. +#endif
  308. diff -Nur uClibc-git/ldso/include/ldsodefs.h uClibc-xtensa/ldso/include/ldsodefs.h
  309. --- uClibc-git/ldso/include/ldsodefs.h 2014-06-02 17:40:33.922711475 +0200
  310. +++ uClibc-xtensa/ldso/include/ldsodefs.h 2014-06-03 16:10:51.175659505 +0200
  311. @@ -62,13 +62,18 @@
  312. extern void _dl_allocate_static_tls (struct link_map *map)
  313. internal_function attribute_hidden;
  314. +extern int _dl_try_allocate_static_tls (struct link_map* map)
  315. + internal_function attribute_hidden;
  316. /* Taken from glibc/elf/dl-reloc.c */
  317. #define CHECK_STATIC_TLS(sym_map) \
  318. do { \
  319. - if (unlikely((sym_map)->l_tls_offset == NO_TLS_OFFSET)) \
  320. + if (__builtin_expect ((sym_map)->l_tls_offset == NO_TLS_OFFSET, 0)) \
  321. _dl_allocate_static_tls (sym_map); \
  322. } while (0)
  323. +#define TRY_STATIC_TLS(sym_map) \
  324. + (__builtin_expect ((sym_map)->l_tls_offset != NO_TLS_OFFSET, 1) \
  325. + || _dl_try_allocate_static_tls (sym_map) == 0)
  326. /* These are internal entry points to the two halves of _dl_allocate_tls,
  327. only used within rtld.c itself at startup time. */
  328. diff -Nur uClibc-git/ldso/include/tlsdeschtab.h uClibc-xtensa/ldso/include/tlsdeschtab.h
  329. --- uClibc-git/ldso/include/tlsdeschtab.h 1970-01-01 01:00:00.000000000 +0100
  330. +++ uClibc-xtensa/ldso/include/tlsdeschtab.h 2014-06-03 14:58:29.681335708 +0200
  331. @@ -0,0 +1,119 @@
  332. +/* Hash table for TLS descriptors.
  333. + Copyright (C) 2005-2013 Free Software Foundation, Inc.
  334. + This file is part of the GNU C Library.
  335. + Contributed by Alexandre Oliva <aoliva@redhat.com>
  336. +
  337. + uClibc port by Baruch Siach <baruch@tkos.co.il>
  338. +
  339. + The GNU C Library is free software; you can redistribute it and/or
  340. + modify it under the terms of the GNU Lesser General Public
  341. + License as published by the Free Software Foundation; either
  342. + version 2.1 of the License, or (at your option) any later version.
  343. +
  344. + The GNU C Library is distributed in the hope that it will be useful,
  345. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  346. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  347. + Lesser General Public License for more details.
  348. +
  349. + You should have received a copy of the GNU Lesser General Public
  350. + License along with the GNU C Library; if not, see
  351. + <http://www.gnu.org/licenses/>. */
  352. +
  353. +#ifndef TLSDESCHTAB_H
  354. +# define TLSDESCHTAB_H 1
  355. +
  356. +# ifdef SHARED
  357. +
  358. +# include <inline-hashtab.h>
  359. +
  360. +inline static int
  361. +hash_tlsdesc (void *p)
  362. +{
  363. + struct tlsdesc_dynamic_arg *td = p;
  364. +
  365. + /* We know all entries are for the same module, so ti_offset is the
  366. + only distinguishing entry. */
  367. + return td->tlsinfo.ti_offset;
  368. +}
  369. +
  370. +inline static int
  371. +eq_tlsdesc (void *p, void *q)
  372. +{
  373. + struct tlsdesc_dynamic_arg *tdp = p, *tdq = q;
  374. +
  375. + return tdp->tlsinfo.ti_offset == tdq->tlsinfo.ti_offset;
  376. +}
  377. +
  378. +inline static int
  379. +map_generation (struct link_map *map)
  380. +{
  381. + size_t idx = map->l_tls_modid;
  382. + struct dtv_slotinfo_list *listp = GL(dl_tls_dtv_slotinfo_list);
  383. +
  384. + /* Find the place in the dtv slotinfo list. */
  385. + do
  386. + {
  387. + /* Does it fit in the array of this list element? */
  388. + if (idx < listp->len)
  389. + {
  390. + /* We should never get here for a module in static TLS, so
  391. + we can assume that, if the generation count is zero, we
  392. + still haven't determined the generation count for this
  393. + module. */
  394. + if (listp->slotinfo[idx].gen)
  395. + return listp->slotinfo[idx].gen;
  396. + else
  397. + break;
  398. + }
  399. + idx -= listp->len;
  400. + listp = listp->next;
  401. + }
  402. + while (listp != NULL);
  403. +
  404. + /* If we get to this point, the module still hasn't been assigned an
  405. + entry in the dtv slotinfo data structures, and it will when we're
  406. + done with relocations. At that point, the module will get a
  407. + generation number that is one past the current generation, so
  408. + return exactly that. */
  409. + return GL(dl_tls_generation) + 1;
  410. +}
  411. +
  412. +void *
  413. +internal_function
  414. +_dl_make_tlsdesc_dynamic (struct link_map *map, size_t ti_offset)
  415. +{
  416. + struct funcdesc_ht *ht;
  417. + void **entry;
  418. + struct tlsdesc_dynamic_arg *td, test;
  419. +
  420. + ht = map->l_tlsdesc_table;
  421. + if (! ht)
  422. + {
  423. + ht = htab_create ();
  424. + if (! ht)
  425. + return 0;
  426. + map->l_tlsdesc_table = ht;
  427. + }
  428. +
  429. + test.tlsinfo.ti_module = map->l_tls_modid;
  430. + test.tlsinfo.ti_offset = ti_offset;
  431. + entry = htab_find_slot (ht, &test, 1, hash_tlsdesc, eq_tlsdesc);
  432. + if (*entry)
  433. + {
  434. + td = *entry;
  435. + return td;
  436. + }
  437. +
  438. + *entry = td = _dl_malloc (sizeof (struct tlsdesc_dynamic_arg));
  439. + /* This may be higher than the map's generation, but it doesn't
  440. + matter much. Worst case, we'll have one extra DTV update per
  441. + thread. */
  442. + td->gen_count = map_generation (map);
  443. + td->tlsinfo = test.tlsinfo;
  444. +
  445. + return td;
  446. +}
  447. +
  448. +# endif /* SHARED */
  449. +
  450. +#endif
  451. diff -Nur uClibc-git/ldso/ldso/dl-tls.c uClibc-xtensa/ldso/ldso/dl-tls.c
  452. --- uClibc-git/ldso/ldso/dl-tls.c 2014-06-02 17:40:33.946711608 +0200
  453. +++ uClibc-xtensa/ldso/ldso/dl-tls.c 2014-06-03 16:10:28.547570023 +0200
  454. @@ -100,20 +100,16 @@
  455. * the static TLS area already allocated for each running thread. If this
  456. * object's TLS segment is too big to fit, we fail. If it fits,
  457. * we set MAP->l_tls_offset and return.
  458. - * This function intentionally does not return any value but signals error
  459. - * directly, as static TLS should be rare and code handling it should
  460. - * not be inlined as much as possible.
  461. */
  462. -void
  463. -internal_function __attribute_noinline__
  464. -_dl_allocate_static_tls (struct link_map *map)
  465. +int
  466. +internal_function
  467. +_dl_try_allocate_static_tls (struct link_map* map)
  468. {
  469. /* If the alignment requirements are too high fail. */
  470. if (map->l_tls_align > _dl_tls_static_align)
  471. {
  472. fail:
  473. - _dl_dprintf(2, "cannot allocate memory in static TLS block");
  474. - _dl_exit(30);
  475. + return -1;
  476. }
  477. # ifdef TLS_TCB_AT_TP
  478. @@ -169,6 +165,23 @@
  479. }
  480. else
  481. map->l_need_tls_init = 1;
  482. +
  483. + return 0;
  484. +}
  485. +
  486. +/*
  487. + * This function intentionally does not return any value but signals error
  488. + * directly, as static TLS should be rare and code handling it should
  489. + * not be inlined as much as possible.
  490. + */
  491. +void
  492. +internal_function __attribute_noinline__
  493. +_dl_allocate_static_tls (struct link_map *map)
  494. +{
  495. + if (_dl_try_allocate_static_tls (map)) {
  496. + _dl_dprintf(2, "cannot allocate memory in static TLS block");
  497. + _dl_exit(30);
  498. + }
  499. }
  500. #ifdef SHARED
  501. diff -Nur uClibc-git/ldso/ldso/fdpic/dl-inlines.h uClibc-xtensa/ldso/ldso/fdpic/dl-inlines.h
  502. --- uClibc-git/ldso/ldso/fdpic/dl-inlines.h 2014-06-02 17:40:33.950711630 +0200
  503. +++ uClibc-xtensa/ldso/ldso/fdpic/dl-inlines.h 2014-06-03 11:57:43.263058897 +0200
  504. @@ -5,6 +5,8 @@
  505. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  506. */
  507. +#include <inline-hashtab.h>
  508. +
  509. /* Initialize a DL_LOADADDR_TYPE given a got pointer and a complete load map. */
  510. static __always_inline void
  511. __dl_init_loadaddr_map(struct elf32_fdpic_loadaddr *loadaddr, Elf32_Addr dl_boot_got_pointer,
  512. @@ -143,269 +145,18 @@
  513. return 0;
  514. }
  515. -/*
  516. - * The hashcode handling code below is heavily inspired in libiberty's
  517. - * hashtab code, but with most adaptation points and support for
  518. - * deleting elements removed.
  519. - *
  520. - * Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
  521. - * Contributed by Vladimir Makarov (vmakarov@cygnus.com).
  522. - */
  523. -static __always_inline unsigned long
  524. -higher_prime_number(unsigned long n)
  525. -{
  526. - /* These are primes that are near, but slightly smaller than, a power of two. */
  527. - static const unsigned long primes[] = {
  528. - 7,
  529. - 13,
  530. - 31,
  531. - 61,
  532. - 127,
  533. - 251,
  534. - 509,
  535. - 1021,
  536. - 2039,
  537. - 4093,
  538. - 8191,
  539. - 16381,
  540. - 32749,
  541. - 65521,
  542. - 131071,
  543. - 262139,
  544. - 524287,
  545. - 1048573,
  546. - 2097143,
  547. - 4194301,
  548. - 8388593,
  549. - 16777213,
  550. - 33554393,
  551. - 67108859,
  552. - 134217689,
  553. - 268435399,
  554. - 536870909,
  555. - 1073741789,
  556. - /* 4294967291 */
  557. - ((unsigned long) 2147483647) + ((unsigned long) 2147483644),
  558. - };
  559. - const unsigned long *low = &primes[0];
  560. - const unsigned long *high = &primes[ARRAY_SIZE(primes)];
  561. -
  562. - while (low != high) {
  563. - const unsigned long *mid = low + (high - low) / 2;
  564. - if (n > *mid)
  565. - low = mid + 1;
  566. - else
  567. - high = mid;
  568. - }
  569. -
  570. -#if 0
  571. - /* If we've run out of primes, abort. */
  572. - if (n > *low) {
  573. - fprintf(stderr, "Cannot find prime bigger than %lu\n", n);
  574. - abort();
  575. - }
  576. -#endif
  577. -
  578. - return *low;
  579. -}
  580. -
  581. -struct funcdesc_ht
  582. -{
  583. - /* Table itself */
  584. - struct funcdesc_value **entries;
  585. -
  586. - /* Current size (in entries) of the hash table */
  587. - size_t size;
  588. -
  589. - /* Current number of elements */
  590. - size_t n_elements;
  591. -};
  592. -
  593. -static __always_inline int
  594. -hash_pointer(const void *p)
  595. +static int
  596. +hash_pointer(void *p)
  597. {
  598. return (int) ((long)p >> 3);
  599. }
  600. -static __always_inline struct funcdesc_ht *
  601. -htab_create(void)
  602. -{
  603. - struct funcdesc_ht *ht = _dl_malloc(sizeof(*ht));
  604. - size_t ent_size;
  605. -
  606. - if (!ht)
  607. - return NULL;
  608. - ht->size = 3;
  609. - ent_size = sizeof(struct funcdesc_ht_value *) * ht->size;
  610. - ht->entries = _dl_malloc(ent_size);
  611. - if (!ht->entries)
  612. - return NULL;
  613. -
  614. - ht->n_elements = 0;
  615. - _dl_memset(ht->entries, 0, ent_size);
  616. -
  617. - return ht;
  618. -}
  619. -
  620. -/*
  621. - * This is only called from _dl_loadaddr_unmap, so it's safe to call
  622. - * _dl_free(). See the discussion below.
  623. - */
  624. -static __always_inline void
  625. -htab_delete(struct funcdesc_ht *htab)
  626. -{
  627. - size_t i;
  628. -
  629. - for (i = htab->size - 1; i >= 0; i--)
  630. - if (htab->entries[i])
  631. - _dl_free(htab->entries[i]);
  632. -
  633. - _dl_free(htab->entries);
  634. - _dl_free(htab);
  635. -}
  636. -
  637. -/*
  638. - * Similar to htab_find_slot, but without several unwanted side effects:
  639. - * - Does not call htab->eq_f when it finds an existing entry.
  640. - * - Does not change the count of elements/searches/collisions in the
  641. - * hash table.
  642. - * This function also assumes there are no deleted entries in the table.
  643. - * HASH is the hash value for the element to be inserted.
  644. - */
  645. -static __always_inline struct funcdesc_value **
  646. -find_empty_slot_for_expand(struct funcdesc_ht *htab, int hash)
  647. +static int
  648. +eq_pointer(void *p, void *q)
  649. {
  650. - size_t size = htab->size;
  651. - unsigned int index = hash % size;
  652. - struct funcdesc_value **slot = htab->entries + index;
  653. - int hash2;
  654. -
  655. - if (!*slot)
  656. - return slot;
  657. -
  658. - hash2 = 1 + hash % (size - 2);
  659. - for (;;) {
  660. - index += hash2;
  661. - if (index >= size)
  662. - index -= size;
  663. -
  664. - slot = htab->entries + index;
  665. - if (!*slot)
  666. - return slot;
  667. - }
  668. -}
  669. -
  670. -/*
  671. - * The following function changes size of memory allocated for the
  672. - * entries and repeatedly inserts the table elements. The occupancy
  673. - * of the table after the call will be about 50%. Naturally the hash
  674. - * table must already exist. Remember also that the place of the
  675. - * table entries is changed. If memory allocation failures are allowed,
  676. - * this function will return zero, indicating that the table could not be
  677. - * expanded. If all goes well, it will return a non-zero value.
  678. - */
  679. -static __always_inline int
  680. -htab_expand(struct funcdesc_ht *htab)
  681. -{
  682. - struct funcdesc_value **oentries;
  683. - struct funcdesc_value **olimit;
  684. - struct funcdesc_value **p;
  685. - struct funcdesc_value **nentries;
  686. - size_t nsize;
  687. -
  688. - oentries = htab->entries;
  689. - olimit = oentries + htab->size;
  690. -
  691. - /*
  692. - * Resize only when table after removal of unused elements is either
  693. - * too full or too empty.
  694. - */
  695. - if (htab->n_elements * 2 > htab->size)
  696. - nsize = higher_prime_number(htab->n_elements * 2);
  697. - else
  698. - nsize = htab->size;
  699. -
  700. - nentries = _dl_malloc(sizeof(*nentries) * nsize);
  701. - _dl_memset(nentries, 0, sizeof(*nentries) * nsize);
  702. - if (nentries == NULL)
  703. - return 0;
  704. - htab->entries = nentries;
  705. - htab->size = nsize;
  706. -
  707. - p = oentries;
  708. - do {
  709. - if (*p)
  710. - *find_empty_slot_for_expand(htab, hash_pointer((*p)->entry_point)) = *p;
  711. - p++;
  712. - } while (p < olimit);
  713. -
  714. -#if 0
  715. - /*
  716. - * We can't tell whether this was allocated by the _dl_malloc()
  717. - * built into ld.so or malloc() in the main executable or libc,
  718. - * and calling free() for something that wasn't malloc()ed could
  719. - * do Very Bad Things (TM). Take the conservative approach
  720. - * here, potentially wasting as much memory as actually used by
  721. - * the hash table, even if multiple growths occur. That's not
  722. - * so bad as to require some overengineered solution that would
  723. - * enable us to keep track of how it was allocated.
  724. - */
  725. - _dl_free(oentries);
  726. -#endif
  727. - return 1;
  728. -}
  729. -
  730. -/*
  731. - * This function searches for a hash table slot containing an entry
  732. - * equal to the given element. To delete an entry, call this with
  733. - * INSERT = 0, then call htab_clear_slot on the slot returned (possibly
  734. - * after doing some checks). To insert an entry, call this with
  735. - * INSERT = 1, then write the value you want into the returned slot.
  736. - * When inserting an entry, NULL may be returned if memory allocation
  737. - * fails.
  738. - */
  739. -static __always_inline struct funcdesc_value **
  740. -htab_find_slot(struct funcdesc_ht *htab, void *ptr, int insert)
  741. -{
  742. - unsigned int index;
  743. - int hash, hash2;
  744. - size_t size;
  745. - struct funcdesc_value **entry;
  746. -
  747. - if (htab->size * 3 <= htab->n_elements * 4 &&
  748. - htab_expand(htab) == 0)
  749. - return NULL;
  750. -
  751. - hash = hash_pointer(ptr);
  752. -
  753. - size = htab->size;
  754. - index = hash % size;
  755. -
  756. - entry = &htab->entries[index];
  757. - if (!*entry)
  758. - goto empty_entry;
  759. - else if ((*entry)->entry_point == ptr)
  760. - return entry;
  761. -
  762. - hash2 = 1 + hash % (size - 2);
  763. - for (;;) {
  764. - index += hash2;
  765. - if (index >= size)
  766. - index -= size;
  767. -
  768. - entry = &htab->entries[index];
  769. - if (!*entry)
  770. - goto empty_entry;
  771. - else if ((*entry)->entry_point == ptr)
  772. - return entry;
  773. - }
  774. -
  775. - empty_entry:
  776. - if (!insert)
  777. - return NULL;
  778. + struct funcdesc_value *entry = p;
  779. - htab->n_elements++;
  780. - return entry;
  781. + return entry->entry_point == q;
  782. }
  783. void *
  784. @@ -424,7 +175,7 @@
  785. tpnt->funcdesc_ht = ht;
  786. }
  787. - entry = htab_find_slot(ht, entry_point, 1);
  788. + entry = htab_find_slot(ht, entry_point, 1, hash_pointer, eq_pointer);
  789. if (*entry) {
  790. _dl_assert((*entry)->entry_point == entry_point);
  791. return _dl_stabilize_funcdesc(*entry);
  792. @@ -459,7 +210,8 @@
  793. if (fd->got_value != rpnt->loadaddr.got_value)
  794. continue;
  795. - address = htab_find_slot(rpnt->funcdesc_ht, (void *)fd->entry_point, 0);
  796. + address = htab_find_slot(rpnt->funcdesc_ht, (void *)fd->entry_point, 0,
  797. + hash_pointer, eq_pointer);
  798. if (address && *(struct funcdesc_value *const*)address == fd) {
  799. address = (*(struct funcdesc_value *const*)address)->entry_point;
  800. diff -Nur uClibc-git/ldso/ldso/xtensa/dl-debug.h uClibc-xtensa/ldso/ldso/xtensa/dl-debug.h
  801. --- uClibc-git/ldso/ldso/xtensa/dl-debug.h 2014-06-02 17:40:33.958711675 +0200
  802. +++ uClibc-xtensa/ldso/ldso/xtensa/dl-debug.h 2014-06-03 12:22:20.032058866 +0200
  803. @@ -8,54 +8,31 @@
  804. static const char * const _dl_reltypes_tab[] =
  805. {
  806. - "R_XTENSA_NONE",
  807. - "R_XTENSA_32",
  808. - "R_XTENSA_RTLD",
  809. - "R_XTENSA_GLOB_DAT",
  810. - "R_XTENSA_JMP_SLOT",
  811. - "R_XTENSA_RELATIVE",
  812. - "R_XTENSA_PLT",
  813. - "R_XTENSA_UNUSED7",
  814. - "R_XTENSA_OP0",
  815. - "R_XTENSA_OP1",
  816. - "R_XTENSA_OP2",
  817. - "R_XTENSA_ASM_EXPAND",
  818. - "R_XTENSA_ASM_SIMPLIFY",
  819. - "R_XTENSA_UNUSED13",
  820. - "R_XTENSA_UNUSED14",
  821. - "R_XTENSA_GNU_VTINHERIT",
  822. - "R_XTENSA_GNU_VTENTRY",
  823. - "R_XTENSA_DIFF8",
  824. - "R_XTENSA_DIFF16",
  825. - "R_XTENSA_DIFF32",
  826. - "R_XTENSA_SLOT0_OP",
  827. - "R_XTENSA_SLOT1_OP",
  828. - "R_XTENSA_SLOT2_OP",
  829. - "R_XTENSA_SLOT3_OP",
  830. - "R_XTENSA_SLOT4_OP",
  831. - "R_XTENSA_SLOT5_OP",
  832. - "R_XTENSA_SLOT6_OP",
  833. - "R_XTENSA_SLOT7_OP",
  834. - "R_XTENSA_SLOT8_OP",
  835. - "R_XTENSA_SLOT9_OP",
  836. - "R_XTENSA_SLOT10_OP",
  837. - "R_XTENSA_SLOT11_OP",
  838. - "R_XTENSA_SLOT12_OP",
  839. - "R_XTENSA_SLOT13_OP",
  840. - "R_XTENSA_SLOT14_OP",
  841. - "R_XTENSA_SLOT0_ALT",
  842. - "R_XTENSA_SLOT1_ALT",
  843. - "R_XTENSA_SLOT2_ALT",
  844. - "R_XTENSA_SLOT3_ALT",
  845. - "R_XTENSA_SLOT4_ALT",
  846. - "R_XTENSA_SLOT5_ALT",
  847. - "R_XTENSA_SLOT6_ALT",
  848. - "R_XTENSA_SLOT7_ALT",
  849. - "R_XTENSA_SLOT8_ALT",
  850. - "R_XTENSA_SLOT9_ALT",
  851. - "R_XTENSA_SLOT10_ALT",
  852. - "R_XTENSA_SLOT11_ALT",
  853. - "R_XTENSA_SLOT12_ALT",
  854. - "R_XTENSA_SLOT13_ALT",
  855. - "R_XTENSA_SLOT14_ALT"
  856. + [0] "R_XTENSA_NONE", "R_XTENSA_32",
  857. + [2] "R_XTENSA_RTLD", "R_XTENSA_GLOB_DAT",
  858. + [4] "R_XTENSA_JMP_SLOT", "R_XTENSA_RELATIVE",
  859. + [6] "R_XTENSA_PLT", "R_XTENSA_UNUSED7",
  860. + [8] "R_XTENSA_OP0", "R_XTENSA_OP1",
  861. + [10] "R_XTENSA_OP2", "R_XTENSA_ASM_EXPAND",
  862. + [12] "R_XTENSA_ASM_SIMPLIFY", "R_XTENSA_UNUSED13",
  863. + [14] "R_XTENSA_UNUSED14", "R_XTENSA_GNU_VTINHERIT",
  864. + [16] "R_XTENSA_GNU_VTENTRY", "R_XTENSA_DIFF8",
  865. + [18] "R_XTENSA_DIFF16", "R_XTENSA_DIFF32",
  866. + [20] "R_XTENSA_SLOT0_OP", "R_XTENSA_SLOT1_OP",
  867. + [22] "R_XTENSA_SLOT2_OP", "R_XTENSA_SLOT3_OP",
  868. + [24] "R_XTENSA_SLOT4_OP", "R_XTENSA_SLOT5_OP",
  869. + [26] "R_XTENSA_SLOT6_OP", "R_XTENSA_SLOT7_OP",
  870. + [28] "R_XTENSA_SLOT8_OP", "R_XTENSA_SLOT9_OP",
  871. + [30] "R_XTENSA_SLOT10_OP", "R_XTENSA_SLOT11_OP",
  872. + [32] "R_XTENSA_SLOT12_OP", "R_XTENSA_SLOT13_OP",
  873. + [34] "R_XTENSA_SLOT14_OP", "R_XTENSA_SLOT0_ALT",
  874. + [36] "R_XTENSA_SLOT1_ALT", "R_XTENSA_SLOT2_ALT",
  875. + [38] "R_XTENSA_SLOT3_ALT", "R_XTENSA_SLOT4_ALT",
  876. + [40] "R_XTENSA_SLOT5_ALT", "R_XTENSA_SLOT6_ALT",
  877. + [42] "R_XTENSA_SLOT7_ALT", "R_XTENSA_SLOT8_ALT",
  878. + [44] "R_XTENSA_SLOT9_ALT", "R_XTENSA_SLOT10_ALT",
  879. + [46] "R_XTENSA_SLOT11_ALT", "R_XTENSA_SLOT12_ALT",
  880. + [48] "R_XTENSA_SLOT13_ALT", "R_XTENSA_SLOT14_ALT",
  881. + [50] "R_XTENSA_TLSDESC_FN", "R_XTENSA_TLSDESC_ARG",
  882. + [52] "R_XTENSA_TLS_TPOFF"
  883. };
  884. diff -Nur uClibc-git/ldso/ldso/xtensa/dl-startup.h uClibc-xtensa/ldso/ldso/xtensa/dl-startup.h
  885. --- uClibc-git/ldso/ldso/xtensa/dl-startup.h 2014-06-02 17:40:33.958711675 +0200
  886. +++ uClibc-xtensa/ldso/ldso/xtensa/dl-startup.h 2014-06-03 12:22:20.112059404 +0200
  887. @@ -11,7 +11,6 @@
  888. __asm__ (
  889. " .text\n"
  890. " .align 4\n"
  891. - " .literal_position\n"
  892. " .global _start\n"
  893. " .type _start, @function\n"
  894. " .hidden _start\n"
  895. diff -Nur uClibc-git/ldso/ldso/xtensa/dl-sysdep.h uClibc-xtensa/ldso/ldso/xtensa/dl-sysdep.h
  896. --- uClibc-git/ldso/ldso/xtensa/dl-sysdep.h 2014-06-02 17:40:33.958711675 +0200
  897. +++ uClibc-xtensa/ldso/ldso/xtensa/dl-sysdep.h 2014-06-03 12:22:20.340060933 +0200
  898. @@ -78,10 +78,13 @@
  899. struct elf_resolve;
  900. extern unsigned long _dl_linux_resolver (struct elf_resolve *, int);
  901. -/* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry, so
  902. - undefined references should not be allowed to define the value. */
  903. +/* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
  904. + TLS variable, so undefined references should not be allowed to define
  905. + the value. */
  906. #define elf_machine_type_class(type) \
  907. - (((type) == R_XTENSA_JMP_SLOT) * ELF_RTYPE_CLASS_PLT)
  908. + (((type) == R_XTENSA_JMP_SLOT || (type) == R_XTENSA_TLS_TPOFF \
  909. + || (type) == R_XTENSA_TLSDESC_FN || (type) == R_XTENSA_TLSDESC_ARG) \
  910. + * ELF_RTYPE_CLASS_PLT)
  911. /* Return the link-time address of _DYNAMIC. */
  912. static __always_inline Elf32_Addr
  913. diff -Nur uClibc-git/ldso/ldso/xtensa/dl-tlsdesc.S uClibc-xtensa/ldso/ldso/xtensa/dl-tlsdesc.S
  914. --- uClibc-git/ldso/ldso/xtensa/dl-tlsdesc.S 1970-01-01 01:00:00.000000000 +0100
  915. +++ uClibc-xtensa/ldso/ldso/xtensa/dl-tlsdesc.S 2014-06-03 12:22:20.340060933 +0200
  916. @@ -0,0 +1,96 @@
  917. +/* Thread-local storage handling in the ELF dynamic linker. Xtensa version.
  918. + Copyright (C) 2012-2013 Free Software Foundation, Inc.
  919. + This file is part of the GNU C Library.
  920. +
  921. + The GNU C Library is free software; you can redistribute it and/or
  922. + modify it under the terms of the GNU Lesser General Public
  923. + License as published by the Free Software Foundation; either
  924. + version 2.1 of the License, or (at your option) any later version.
  925. +
  926. + The GNU C Library is distributed in the hope that it will be useful,
  927. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  928. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  929. + Lesser General Public License for more details.
  930. +
  931. + You should have received a copy of the GNU Lesser General Public
  932. + License along with the GNU C Library. If not, see
  933. + <http://www.gnu.org/licenses/>. */
  934. +
  935. +#include <sysdep.h>
  936. +#include <tls.h>
  937. +#include "tlsdesc.h"
  938. +
  939. +
  940. + .text
  941. + .align 4
  942. + .hidden _dl_tlsdesc_return
  943. + .global _dl_tlsdesc_return
  944. + .type _dl_tlsdesc_return, @function
  945. +_dl_tlsdesc_return:
  946. + entry a1, 16
  947. + rur.threadptr a3
  948. + add a2, a2, a3
  949. + retw
  950. + .size _dl_tlsdesc_return, .-_dl_tlsdesc_return
  951. +
  952. +#ifdef SHARED
  953. +
  954. +
  955. + /* This function is used for symbols that need dynamic TLS.
  956. +
  957. + The argument passed to this function points to the TLS descriptor.
  958. +
  959. + The assembly code that follows is a rendition of the following
  960. + C code, hand-optimized a little bit.
  961. +
  962. + ptrdiff_t
  963. + _dl_tlsdesc_dynamic(struct tlsdesc_dynamic_arg *td)
  964. + {
  965. + dtv_t *dtv = (dtv_t *)THREAD_DTV();
  966. + if (td->gen_count <= dtv[0].counter
  967. + && dtv[td->tlsinfo.ti_module].pointer.val
  968. + != TLS_DTV_UNALLOCATED)
  969. + return dtv[td->tlsinfo.ti_module].pointer.val
  970. + + td->tlsinfo.ti_offset - __builtin_thread_pointer();
  971. + return __tls_get_addr (&td->tlsinfo) - __builtin_thread_pointer();
  972. + }
  973. + */
  974. +
  975. + .align 4
  976. + .hidden _dl_tlsdesc_dynamic
  977. + .global _dl_tlsdesc_dynamic
  978. + .type _dl_tlsdesc_dynamic, @function
  979. +_dl_tlsdesc_dynamic:
  980. + entry a1, 32
  981. +
  982. + /* dtv_t *dtv = (dtv_t *)THREAD_DTV(); */
  983. + rur.threadptr a3
  984. + l32i a4, a3, 0
  985. +
  986. + /* if (td->gen_count <= dtv[0].counter */
  987. + l32i a6, a2, TLSDESC_GEN_COUNT
  988. + l32i a7, a4, 0
  989. + blt a7, a6, .Lslow
  990. +
  991. + /* && dtv[td->tlsinfo.ti_module].pointer.val != TLS_DTV_UNALLOCATED) */
  992. + l32i a6, a2, TLSDESC_MODID
  993. + addx8 a6, a3, a6
  994. + l32i a6, a6, 0
  995. + beqi a6, -1, .Lslow
  996. +
  997. + /* return dtv[td->tlsinfo.ti_module].pointer.val
  998. + + td->tlsinfo.ti_offset - __builtin_thread_pointer(); */
  999. + l32i a6, a2, TLSDESC_MODOFF
  1000. + sub a2, a6, a3
  1001. + retw
  1002. +
  1003. + /* return __tls_get_addr (&td->tlsinfo) - __builtin_thread_pointer(); */
  1004. +.Lslow:
  1005. + mov a10, a2
  1006. + movi a8, __tls_get_addr
  1007. + callx8 a8
  1008. + sub a2, a10, a3
  1009. + retw
  1010. + .size _dl_tlsdesc_dynamic, .-_dl_tlsdesc_dynamic
  1011. +
  1012. +#endif /* SHARED */
  1013. diff -Nur uClibc-git/ldso/ldso/xtensa/elfinterp.c uClibc-xtensa/ldso/ldso/xtensa/elfinterp.c
  1014. --- uClibc-git/ldso/ldso/xtensa/elfinterp.c 2014-06-02 17:40:33.958711675 +0200
  1015. +++ uClibc-xtensa/ldso/ldso/xtensa/elfinterp.c 2014-06-03 12:22:20.340060933 +0200
  1016. @@ -31,6 +31,8 @@
  1017. */
  1018. #include "ldso.h"
  1019. +#include "dl-tls.h"
  1020. +#include "tlsdeschtab.h"
  1021. unsigned long
  1022. _dl_linux_resolver (struct elf_resolve *tpnt, int reloc_entry)
  1023. @@ -146,6 +148,9 @@
  1024. int reloc_type;
  1025. int symtab_index;
  1026. char *symname;
  1027. +#if defined USE_TLS && USE_TLS
  1028. + struct elf_resolve *tls_tpnt = NULL;
  1029. +#endif
  1030. struct symbol_ref sym_ref;
  1031. ElfW(Addr) *reloc_addr;
  1032. ElfW(Addr) symbol_addr;
  1033. @@ -172,15 +177,22 @@
  1034. * here, so all bases should be covered.
  1035. */
  1036. if (unlikely (!symbol_addr &&
  1037. + ELF_ST_TYPE (sym_ref.sym->st_info) != STT_TLS &&
  1038. ELF_ST_BIND (sym_ref.sym->st_info) != STB_WEAK)) {
  1039. - _dl_dprintf (2, "%s: can't resolve symbol '%s'\n",
  1040. - _dl_progname, symname);
  1041. - _dl_exit (1);
  1042. + return 1;
  1043. }
  1044. if (_dl_trace_prelink) {
  1045. _dl_debug_lookup (symname, tpnt, &symtab[symtab_index],
  1046. &sym_ref, elf_machine_type_class(reloc_type));
  1047. }
  1048. +#if defined USE_TLS && USE_TLS
  1049. + tls_tpnt = sym_ref.tpnt;
  1050. +#endif
  1051. + } else {
  1052. + symbol_addr =symtab[symtab_index].st_value;
  1053. +#if defined USE_TLS && USE_TLS
  1054. + tls_tpnt = tpnt;
  1055. +#endif
  1056. }
  1057. #if defined (__SUPPORT_LD_DEBUG__)
  1058. @@ -198,8 +210,8 @@
  1059. case R_XTENSA_RTLD:
  1060. if (rpnt->r_addend == 1) {
  1061. - /* Grab the function pointer stashed at the beginning of the
  1062. - GOT by the GOT_INIT function. */
  1063. + /* Grab the function pointer stashed at the beginning
  1064. + of the GOT by the GOT_INIT function. */
  1065. *reloc_addr = *(ElfW(Addr) *) tpnt->dynamic_info[DT_PLTGOT];
  1066. } else if (rpnt->r_addend == 2) {
  1067. /* Store the link map for the object. */
  1068. @@ -213,6 +225,35 @@
  1069. *reloc_addr += tpnt->loadaddr + rpnt->r_addend;
  1070. break;
  1071. +#if defined USE_TLS && USE_TLS
  1072. + case R_XTENSA_TLS_TPOFF:
  1073. + CHECK_STATIC_TLS((struct link_map *) tls_tpnt);
  1074. + *reloc_addr = symbol_addr + tls_tpnt->l_tls_offset + rpnt->r_addend;
  1075. + break;
  1076. + case R_XTENSA_TLSDESC_FN:
  1077. +#ifndef SHARED
  1078. + CHECK_STATIC_TLS((struct link_map *) tls_tpnt);
  1079. +#else
  1080. + if (!TRY_STATIC_TLS ((struct link_map *) tls_tpnt))
  1081. + *reloc_addr = (ElfW(Addr)) _dl_tlsdesc_dynamic;
  1082. + else
  1083. +#endif
  1084. + *reloc_addr = (ElfW(Addr)) _dl_tlsdesc_return;
  1085. + break;
  1086. + case R_XTENSA_TLSDESC_ARG:
  1087. +#ifndef SHARED
  1088. + CHECK_STATIC_TLS((struct link_map *) tls_tpnt);
  1089. +#else
  1090. + if (!TRY_STATIC_TLS ((struct link_map *) tls_tpnt))
  1091. + *reloc_addr = (ElfW(Addr))
  1092. + _dl_make_tlsdesc_dynamic((struct link_map *) tls_tpnt,
  1093. + symbol_addr + *reloc_addr);
  1094. + else
  1095. +#endif
  1096. + *reloc_addr += symbol_addr + tls_tpnt->l_tls_offset;
  1097. + break;
  1098. +#endif
  1099. +
  1100. default:
  1101. return -1; /* Calls _dl_exit(1). */
  1102. }
  1103. diff -Nur uClibc-git/ldso/ldso/xtensa/resolve.S uClibc-xtensa/ldso/ldso/xtensa/resolve.S
  1104. --- uClibc-git/ldso/ldso/xtensa/resolve.S 2014-06-02 17:40:33.958711675 +0200
  1105. +++ uClibc-xtensa/ldso/ldso/xtensa/resolve.S 2014-06-03 12:22:20.344060961 +0200
  1106. @@ -27,7 +27,6 @@
  1107. .text
  1108. .align 4
  1109. - .literal_position
  1110. .global _dl_linux_resolve
  1111. .type _dl_linux_resolve, @function
  1112. _dl_linux_resolve:
  1113. diff -Nur uClibc-git/libc/sysdeps/linux/xtensa/clone.S uClibc-xtensa/libc/sysdeps/linux/xtensa/clone.S
  1114. --- uClibc-git/libc/sysdeps/linux/xtensa/clone.S 2014-06-02 17:40:34.722715903 +0200
  1115. +++ uClibc-xtensa/libc/sysdeps/linux/xtensa/clone.S 2014-06-03 12:04:16.669187814 +0200
  1116. @@ -1,34 +1,38 @@
  1117. -/* Copyright (C) 2001, 2005, 2007 Free Software Foundation, Inc.
  1118. +/* Copyright (C) 2001, 2005 Free Software Foundation, Inc.
  1119. The GNU C Library is free software; you can redistribute it and/or
  1120. - modify it under the terms of the GNU Lesser General Public
  1121. - License as published by the Free Software Foundation; either
  1122. - version 2.1 of the License, or (at your option) any later version.
  1123. + modify it under the terms of the GNU Library General Public License as
  1124. + published by the Free Software Foundation; either version 2 of the
  1125. + License, or (at your option) any later version.
  1126. The GNU C Library is distributed in the hope that it will be useful,
  1127. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1128. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1129. - Lesser General Public License for more details.
  1130. + Library General Public License for more details.
  1131. - You should have received a copy of the GNU Lesser General Public
  1132. - License along with the GNU C Library; if not, see
  1133. - <http://www.gnu.org/licenses/>. */
  1134. + You should have received a copy of the GNU Library General Public
  1135. + License along with the GNU C Library; see the file COPYING.LIB. If not,
  1136. + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  1137. + Boston, MA 02111-1307, USA. */
  1138. /* clone is even more special than fork as it mucks with stacks
  1139. - and invokes a function in the right context after it's all over. */
  1140. + and invokes a function in the right context after its all over. */
  1141. -#include "sysdep.h"
  1142. -#include <sys/syscall.h>
  1143. +#include <features.h>
  1144. +#include <sysdep.h>
  1145. #define _ERRNO_H 1
  1146. #include <bits/errno.h>
  1147. -
  1148. -/* int clone (a2 = int (*fn)(void *arg),
  1149. - a3 = void *child_stack,
  1150. - a4 = int flags,
  1151. - a5 = void *arg,
  1152. - a6 = pid_t *ptid,
  1153. - a7 = struct user_desc *tls,
  1154. - 16(sp) = pid_t *ctid) */
  1155. +#ifdef RESET_PID
  1156. +#include <tls.h>
  1157. +#endif
  1158. +#define __ASSEMBLY__
  1159. +#include <linux/sched.h>
  1160. +
  1161. +/* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
  1162. + a2 a3 a4 a5
  1163. + pid_t *ptid, struct user_desc *tls, pid_t *ctid)
  1164. + a6 a7 16(sp)
  1165. +*/
  1166. .text
  1167. ENTRY (__clone)
  1168. @@ -39,7 +43,7 @@
  1169. /* a2 and a3 are candidates for destruction by system-call return
  1170. parameters. We don't need the stack pointer after the system
  1171. - call. We trust that the kernel will preserve a7, a9, and a6. */
  1172. + call. We trust that the kernel will preserve a6, a7 and a9. */
  1173. mov a9, a5 /* save function argument */
  1174. mov a5, a7
  1175. @@ -48,19 +52,18 @@
  1176. mov a6, a4
  1177. mov a4, a8
  1178. l32i a8, a1, 16 /* child_tid */
  1179. - movi a2, SYS_ify (clone)
  1180. + movi a2, SYS_ify(clone)
  1181. +
  1182. + /* syscall(NR_clone,clone_flags, usp, parent_tid, child_tls, child_tid)
  1183. + a2 a6 a3 a4 a5 a8
  1184. + */
  1185. - /* syscall (a2 = NR_clone,
  1186. - a6 = clone_flags,
  1187. - a3 = usp,
  1188. - a4 = parent_tid,
  1189. - a5 = child_tls,
  1190. - a8 = child_tid) */
  1191. syscall
  1192. bltz a2, SYSCALL_ERROR_LABEL
  1193. beqz a2, .Lthread_start
  1194. - /* Fall through for parent. */
  1195. + /* fall through for parent */
  1196. +
  1197. .Lpseudo_end:
  1198. retw
  1199. @@ -69,32 +72,38 @@
  1200. j SYSCALL_ERROR_LABEL
  1201. .Lthread_start:
  1202. - /* Start child thread. */
  1203. - movi a0, 0 /* terminate the stack frame */
  1204. +
  1205. +#if CLONE_THREAD != 0x00010000 || CLONE_VM != 0x00000100
  1206. +# error invalid values for CLONE_THREAD or CLONE_VM
  1207. +#endif
  1208. #ifdef RESET_PID
  1209. - /* Check and see if we need to reset the PID. */
  1210. - bbsi.l a6, 16, 1f /* CLONE_THREAD = 0x00010000 */
  1211. + bbsi.l a6, 16, .Lskip_restore_pid /* CLONE_THREAD = 0x00010000 */
  1212. movi a2, -1
  1213. - bbsi.l a6, 8, 2f /* CLONE_VM = 0x00000100 */
  1214. - movi a2, SYS_ify (getpid)
  1215. + bbsi a6, 8, .Lgotpid /* CLONE_VM = 0x00000100 */
  1216. + movi a2, SYS_ify(getpid)
  1217. syscall
  1218. -2: rur a3, THREADPTR
  1219. - movi a4, PID_OFFSET
  1220. - add a4, a4, a3
  1221. - s32i a2, a4, 0
  1222. - movi a4, TID_OFFSET
  1223. - add a4, a4, a3
  1224. - s32i a2, a3, 0
  1225. -1:
  1226. -#endif /* RESET_PID */
  1227. +.Lgotpid:
  1228. + rur a3, threadptr
  1229. + movi a0, TLS_PRE_TCB_SIZE
  1230. + sub a3, a3, a0
  1231. + s32i a2, a3, PID
  1232. + s32i a2, a3, TID
  1233. +.Lskip_restore_pid:
  1234. +#endif
  1235. + /* start child thread */
  1236. + movi a0, 0 /* terminate the stack frame */
  1237. mov a6, a9 /* load up the 'arg' parameter */
  1238. callx4 a7 /* call the user's function */
  1239. /* Call _exit. Note that any return parameter from the user's
  1240. - function in a6 is seen as inputs to _exit. */
  1241. - movi a2, JUMPTARGET(_exit)
  1242. + function in a6 is seen as inputs to _exit. */
  1243. +#ifdef PIC
  1244. + movi a2, _exit@PLT
  1245. +#else
  1246. + movi a2, _exit
  1247. +#endif
  1248. callx4 a2
  1249. PSEUDO_END (__clone)
  1250. diff -Nur uClibc-git/libc/sysdeps/linux/xtensa/fork.c uClibc-xtensa/libc/sysdeps/linux/xtensa/fork.c
  1251. --- uClibc-git/libc/sysdeps/linux/xtensa/fork.c 2014-06-02 17:40:34.726715926 +0200
  1252. +++ uClibc-xtensa/libc/sysdeps/linux/xtensa/fork.c 2014-06-03 12:04:16.669187814 +0200
  1253. @@ -20,6 +20,10 @@
  1254. {
  1255. return (pid_t) INLINE_SYSCALL(clone, 2, SIGCHLD, 0);
  1256. }
  1257. -lt_strong_alias(fork)
  1258. -lt_libc_hidden(fork)
  1259. +# ifdef __UCLIBC_HAS_THREADS__
  1260. +strong_alias(fork,__libc_fork)
  1261. +libc_hidden_weak(fork)
  1262. +# else
  1263. +libc_hidden_def(fork)
  1264. +# endif
  1265. #endif
  1266. diff -Nur uClibc-git/libc/sysdeps/linux/xtensa/jmpbuf-unwind.h uClibc-xtensa/libc/sysdeps/linux/xtensa/jmpbuf-unwind.h
  1267. --- uClibc-git/libc/sysdeps/linux/xtensa/jmpbuf-unwind.h 2014-06-02 17:40:34.726715926 +0200
  1268. +++ uClibc-xtensa/libc/sysdeps/linux/xtensa/jmpbuf-unwind.h 2014-06-03 12:04:16.669187814 +0200
  1269. @@ -1,25 +1,23 @@
  1270. -/* Copyright (C) 1997, 1998, 2007 Free Software Foundation, Inc.
  1271. - This file is part of the GNU C Library.
  1272. -
  1273. - The GNU C Library is free software; you can redistribute it and/or
  1274. - modify it under the terms of the GNU Lesser General Public
  1275. - License as published by the Free Software Foundation; either
  1276. - version 2.1 of the License, or (at your option) any later version.
  1277. -
  1278. - The GNU C Library is distributed in the hope that it will be useful,
  1279. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  1280. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1281. - Lesser General Public License for more details.
  1282. -
  1283. - You should have received a copy of the GNU Lesser General Public
  1284. - License along with the GNU C Library; if not, see
  1285. - <http://www.gnu.org/licenses/>. */
  1286. -
  1287. -/* Test if longjmp to JMPBUF would unwind the frame containing a local
  1288. - variable at ADDRESS. */
  1289. -
  1290. +/*
  1291. + * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  1292. + *
  1293. + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  1294. + */
  1295. #include <setjmp.h>
  1296. #include <jmpbuf-offsets.h>
  1297. +/* Test if longjmp to JMPBUF would unwind the frame
  1298. + containing a local variable at ADDRESS. */
  1299. #define _JMPBUF_UNWINDS(jmpbuf, address) \
  1300. ((void *) (address) < (void *) (jmpbuf)[JB_SP])
  1301. +
  1302. +#ifdef __UCLIBC_HAS_THREADS_NATIVE__
  1303. +#include <stdint.h>
  1304. +#include <unwind.h>
  1305. +
  1306. +#define _JMPBUF_CFA_UNWINDS_ADJ(_jmpbuf, _context, _adj) \
  1307. + _JMPBUF_UNWINDS_ADJ (_jmpbuf, (void *) _Unwind_GetCFA (_context), _adj)
  1308. +
  1309. +#define _JMPBUF_UNWINDS_ADJ(_jmpbuf, _address, _adj) \
  1310. + ((uintptr_t) (_address) - (_adj) < (uintptr_t) (_jmpbuf)[JB_SP] - (_adj))
  1311. +#endif
  1312. diff -Nur uClibc-git/libc/sysdeps/linux/xtensa/Makefile.arch uClibc-xtensa/libc/sysdeps/linux/xtensa/Makefile.arch
  1313. --- uClibc-git/libc/sysdeps/linux/xtensa/Makefile.arch 2014-06-02 17:40:34.686715704 +0200
  1314. +++ uClibc-xtensa/libc/sysdeps/linux/xtensa/Makefile.arch 2014-06-03 12:04:16.669187814 +0200
  1315. @@ -5,7 +5,10 @@
  1316. # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  1317. #
  1318. -CSRC-y := brk.c fork.c sigaction.c __syscall_error.c
  1319. +CSRC-y := brk.c sigaction.c __syscall_error.c
  1320. SSRC-y := bsd-_setjmp.S bsd-setjmp.S setjmp.S clone.S \
  1321. sigrestorer.S syscall.S mmap.S windowspill.S __longjmp.S vfork.S
  1322. +
  1323. +CSRC-$(if $(UCLIBC_HAS_THREADS_NATIVE),,y) += fork.c
  1324. +SSRC-$(if $(UCLIBC_HAS_THREADS_NATIVE),,y) += clone.S
  1325. diff -Nur uClibc-git/libc/sysdeps/linux/xtensa/sys/ptrace.h uClibc-xtensa/libc/sysdeps/linux/xtensa/sys/ptrace.h
  1326. --- uClibc-git/libc/sysdeps/linux/xtensa/sys/ptrace.h 1970-01-01 01:00:00.000000000 +0100
  1327. +++ uClibc-xtensa/libc/sysdeps/linux/xtensa/sys/ptrace.h 2014-06-03 11:58:41.563379928 +0200
  1328. @@ -0,0 +1,155 @@
  1329. +/* `ptrace' debugger support interface. Linux version.
  1330. + Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007
  1331. + Free Software Foundation, Inc.
  1332. + This file is part of the GNU C Library.
  1333. +
  1334. + The GNU C Library is free software; you can redistribute it and/or
  1335. + modify it under the terms of the GNU Lesser General Public
  1336. + License as published by the Free Software Foundation; either
  1337. + version 2.1 of the License, or (at your option) any later version.
  1338. +
  1339. + The GNU C Library is distributed in the hope that it will be useful,
  1340. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  1341. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1342. + Lesser General Public License for more details.
  1343. +
  1344. + You should have received a copy of the GNU Lesser General Public
  1345. + License along with the GNU C Library; if not, see
  1346. + <http://www.gnu.org/licenses/>. */
  1347. +
  1348. +#ifndef _SYS_PTRACE_H
  1349. +#define _SYS_PTRACE_H 1
  1350. +
  1351. +#include <features.h>
  1352. +
  1353. +/* Kludge away careless namespace pollution from the kernel. */
  1354. +
  1355. +#undef PTRACE_GETREGS
  1356. +#undef PTRACE_SETREGS
  1357. +#undef PTRACE_GETFPREGS
  1358. +#undef PTRACE_SETFPREGS
  1359. +#undef PTRACE_GETFPREGSIZE
  1360. +
  1361. +
  1362. +__BEGIN_DECLS
  1363. +
  1364. +/* Type of the REQUEST argument to `ptrace.' */
  1365. +enum __ptrace_request
  1366. +{
  1367. + /* Indicate that the process making this request should be traced.
  1368. + All signals received by this process can be intercepted by its
  1369. + parent, and its parent can use the other `ptrace' requests. */
  1370. + PTRACE_TRACEME = 0,
  1371. +#define PT_TRACE_ME PTRACE_TRACEME
  1372. +
  1373. + /* Return the word in the process's text space at address ADDR. */
  1374. + PTRACE_PEEKTEXT = 1,
  1375. +#define PT_READ_I PTRACE_PEEKTEXT
  1376. +
  1377. + /* Return the word in the process's data space at address ADDR. */
  1378. + PTRACE_PEEKDATA = 2,
  1379. +#define PT_READ_D PTRACE_PEEKDATA
  1380. +
  1381. + /* Return the word in the process's user area at offset ADDR. */
  1382. + PTRACE_PEEKUSER = 3,
  1383. +#define PT_READ_U PTRACE_PEEKUSER
  1384. +
  1385. + /* Write the word DATA into the process's text space at address ADDR. */
  1386. + PTRACE_POKETEXT = 4,
  1387. +#define PT_WRITE_I PTRACE_POKETEXT
  1388. +
  1389. + /* Write the word DATA into the process's data space at address ADDR. */
  1390. + PTRACE_POKEDATA = 5,
  1391. +#define PT_WRITE_D PTRACE_POKEDATA
  1392. +
  1393. + /* Write the word DATA into the process's user area at offset ADDR. */
  1394. + PTRACE_POKEUSER = 6,
  1395. +#define PT_WRITE_U PTRACE_POKEUSER
  1396. +
  1397. + /* Continue the process. */
  1398. + PTRACE_CONT = 7,
  1399. +#define PT_CONTINUE PTRACE_CONT
  1400. +
  1401. + /* Kill the process. */
  1402. + PTRACE_KILL = 8,
  1403. +#define PT_KILL PTRACE_KILL
  1404. +
  1405. + /* Single step the process.
  1406. + This is not supported on all machines. */
  1407. + PTRACE_SINGLESTEP = 9,
  1408. +#define PT_STEP PTRACE_SINGLESTEP
  1409. +
  1410. + /* Get all general purpose registers used by a processes.
  1411. + This is not supported on all machines. */
  1412. + PTRACE_GETREGS = 12,
  1413. +#define PT_GETREGS PTRACE_GETREGS
  1414. +
  1415. + /* Set all general purpose registers used by a processes.
  1416. + This is not supported on all machines. */
  1417. + PTRACE_SETREGS = 13,
  1418. +#define PT_SETREGS PTRACE_SETREGS
  1419. +
  1420. + /* Get all floating point registers used by a processes.
  1421. + This is not supported on all machines. */
  1422. + PTRACE_GETFPREGS = 14,
  1423. +#define PT_GETFPREGS PTRACE_GETFPREGS
  1424. +
  1425. + /* Set all floating point registers used by a processes.
  1426. + This is not supported on all machines. */
  1427. + PTRACE_SETFPREGS = 15,
  1428. +#define PT_SETFPREGS PTRACE_SETFPREGS
  1429. +
  1430. + /* Attach to a process that is already running. */
  1431. + PTRACE_ATTACH = 16,
  1432. +#define PT_ATTACH PTRACE_ATTACH
  1433. +
  1434. + /* Detach from a process attached to with PTRACE_ATTACH. */
  1435. + PTRACE_DETACH = 17,
  1436. +#define PT_DETACH PTRACE_DETACH
  1437. +
  1438. + /* Get size required for the buffer holding the floating point registers.
  1439. + This is not supported on all machines. */
  1440. + PTRACE_GETFPREGSIZE = 18,
  1441. +#define PT_GETFPREGSIZE PTRACE_GETFPREGSIZE
  1442. +
  1443. + /* Continue and stop at the next (return from) syscall. */
  1444. + PTRACE_SYSCALL = 24
  1445. +#define PT_SYSCALL PTRACE_SYSCALL
  1446. +};
  1447. +
  1448. +/* Options set using PTRACE_SETOPTIONS. */
  1449. +enum __ptrace_setoptions {
  1450. + PTRACE_O_TRACESYSGOOD = 0x00000001,
  1451. + PTRACE_O_TRACEFORK = 0x00000002,
  1452. + PTRACE_O_TRACEVFORK = 0x00000004,
  1453. + PTRACE_O_TRACECLONE = 0x00000008,
  1454. + PTRACE_O_TRACEEXEC = 0x00000010,
  1455. + PTRACE_O_TRACEVFORKDONE = 0x00000020,
  1456. + PTRACE_O_TRACEEXIT = 0x00000040,
  1457. + PTRACE_O_MASK = 0x0000007f
  1458. +};
  1459. +
  1460. +/* Wait extended result codes for the above trace options. */
  1461. +enum __ptrace_eventcodes {
  1462. + PTRACE_EVENT_FORK = 1,
  1463. + PTRACE_EVENT_VFORK = 2,
  1464. + PTRACE_EVENT_CLONE = 3,
  1465. + PTRACE_EVENT_EXEC = 4,
  1466. + PTRACE_EVENT_VFORK_DONE = 5,
  1467. + PTRACE_EVENT_EXIT = 6
  1468. +};
  1469. +
  1470. +/* Perform process tracing functions. REQUEST is one of the values
  1471. + above, and determines the action to be taken.
  1472. + For all requests except PTRACE_TRACEME, PID specifies the process to be
  1473. + traced.
  1474. +
  1475. + PID and the other arguments described above for the various requests should
  1476. + appear (those that are used for the particular request) as:
  1477. + pid_t PID, void *ADDR, int DATA, void *ADDR2
  1478. + after REQUEST. */
  1479. +extern long int ptrace (enum __ptrace_request __request, ...) __THROW;
  1480. +
  1481. +__END_DECLS
  1482. +
  1483. +#endif /* _SYS_PTRACE_H */
  1484. diff -Nur uClibc-git/libc/sysdeps/linux/xtensa/sysdep.h uClibc-xtensa/libc/sysdeps/linux/xtensa/sysdep.h
  1485. --- uClibc-git/libc/sysdeps/linux/xtensa/sysdep.h 2014-06-02 17:40:34.726715926 +0200
  1486. +++ uClibc-xtensa/libc/sysdeps/linux/xtensa/sysdep.h 2014-06-03 15:24:57.308410770 +0200
  1487. @@ -16,6 +16,10 @@
  1488. License along with the GNU C Library; if not, see
  1489. <http://www.gnu.org/licenses/>. */
  1490. +#ifndef _LINUX_XTENSA_SYSDEP_H
  1491. +#define _LINUX_XTENSA_SYSDEP_H 1
  1492. +
  1493. +#include <common/sysdep.h>
  1494. #include <sys/syscall.h>
  1495. #ifdef __ASSEMBLER__
  1496. @@ -24,12 +28,6 @@
  1497. #define ASM_TYPE_DIRECTIVE(name, typearg) .type name, typearg
  1498. #define ASM_SIZE_DIRECTIVE(name) .size name, . - name
  1499. -#ifdef __STDC__
  1500. -#define C_LABEL(name) name :
  1501. -#else
  1502. -#define C_LABEL(name) name/**/:
  1503. -#endif
  1504. -
  1505. #define ENTRY(name) \
  1506. ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name); \
  1507. ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name), @function); \
  1508. @@ -52,6 +50,15 @@
  1509. #undef END
  1510. #define END(name) ASM_SIZE_DIRECTIVE(name)
  1511. +/* Local label name for asm code. */
  1512. +#ifndef L
  1513. +# ifdef HAVE_ELF
  1514. +# define L(name) .L##name
  1515. +# else
  1516. +# define L(name) name
  1517. +# endif
  1518. +#endif
  1519. +
  1520. /* Define a macro for this directive so it can be removed in a few places. */
  1521. #define LITERAL_POSITION .literal_position
  1522. @@ -123,19 +130,7 @@
  1523. #define PSEUDO_END_ERRVAL(name) \
  1524. END (name)
  1525. -#undef ret_ERRVAL
  1526. -#define ret_ERRVAL retw
  1527. -
  1528. -#if defined RTLD_PRIVATE_ERRNO
  1529. -# define SYSCALL_ERROR_HANDLER \
  1530. -0: movi a4, rtld_errno; \
  1531. - neg a2, a2; \
  1532. - s32i a2, a4, 0; \
  1533. - movi a2, -1; \
  1534. - j .Lpseudo_end;
  1535. -
  1536. -#elif defined _LIBC_REENTRANT
  1537. -
  1538. +#if defined _LIBC_REENTRANT
  1539. # if defined USE___THREAD
  1540. # ifndef NOT_IN_libc
  1541. # define SYSCALL_ERROR_ERRNO __libc_errno
  1542. @@ -170,3 +165,9 @@
  1543. #endif /* _LIBC_REENTRANT */
  1544. #endif /* __ASSEMBLER__ */
  1545. +
  1546. +/* Pointer mangling is not yet supported for Xtensa. */
  1547. +#define PTR_MANGLE(var) (void) (var)
  1548. +#define PTR_DEMANGLE(var) (void) (var)
  1549. +
  1550. +#endif /* _LINUX_XTENSA_SYSDEP_H */
  1551. diff -Nur uClibc-git/libc/sysdeps/linux/xtensa/vfork.S uClibc-xtensa/libc/sysdeps/linux/xtensa/vfork.S
  1552. --- uClibc-git/libc/sysdeps/linux/xtensa/vfork.S 2014-06-02 17:40:34.726715926 +0200
  1553. +++ uClibc-xtensa/libc/sysdeps/linux/xtensa/vfork.S 2014-06-03 12:04:16.669187814 +0200
  1554. @@ -1,4 +1,4 @@
  1555. -/* Copyright (C) 2005, 2007 Free Software Foundation, Inc.
  1556. +/* Copyright (C) 2005-2013 Free Software Foundation, Inc.
  1557. This file is part of the GNU C Library.
  1558. The GNU C Library is free software; you can redistribute it and/or
  1559. @@ -19,72 +19,67 @@
  1560. #include <sys/syscall.h>
  1561. #define _SIGNAL_H
  1562. #include <bits/signum.h>
  1563. +#define __ASSEMBLY__
  1564. +#include <linux/sched.h>
  1565. -/* Clone the calling process, but without copying the whole address space.
  1566. +/*
  1567. + Clone the calling process, but without copying the whole address space.
  1568. The calling process is suspended until the new process exits or is
  1569. replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
  1570. and the process ID of the new process to the old process.
  1571. Note that it is important that we don't create a new stack frame for the
  1572. - caller. */
  1573. + caller.
  1574. -
  1575. -/* The following are defined in linux/sched.h, which unfortunately
  1576. - is not safe for inclusion in an assembly file. */
  1577. -#define CLONE_VM 0x00000100 /* set if VM shared between processes */
  1578. -#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to
  1579. - wake it up on mm_release */
  1580. +*/
  1581. #ifndef SAVE_PID
  1582. -#define SAVE_PID
  1583. +#define SAVE_PID(a,b,c,d)
  1584. #endif
  1585. -
  1586. #ifndef RESTORE_PID
  1587. -#define RESTORE_PID
  1588. +#define RESTORE_PID(a,b,c)
  1589. +#endif
  1590. +#ifndef RESTORE_PID12
  1591. +#define RESTORE_PID12(a,b,c)
  1592. #endif
  1593. +/*
  1594. + pid_t vfork(void);
  1595. + Implemented as __clone_syscall(CLONE_VFORK | CLONE_VM | SIGCHLD, 0)
  1596. + */
  1597. -/* pid_t vfork(void);
  1598. - Implemented as __clone_syscall(CLONE_VFORK | CLONE_VM | SIGCHLD, 0) */
  1599. HIDDEN_ENTRY (__vfork)
  1600. + .literal .Ljumptable, 0, .L4, .L8, .L12
  1601. - movi a6, .Ljumptable
  1602. - extui a2, a0, 30, 2 /* call-size: call4/8/12 = 1/2/3 */
  1603. - addx4 a4, a2, a6 /* find return address in jumptable */
  1604. - l32i a4, a4, 0
  1605. - add a4, a4, a6
  1606. -
  1607. + mov a3, a0 # move return address out of the way
  1608. + movi a0, .Ljumptable
  1609. + extui a2, a3, 30, 2 # call-size: call4/8/12 = 1/2/3
  1610. + addx4 a0, a2, a0 # find return address in jumptable
  1611. slli a2, a2, 30
  1612. - xor a3, a0, a2 /* remove call-size from return addr */
  1613. - extui a5, a4, 30, 2 /* get high bits of jump target */
  1614. - slli a5, a5, 30
  1615. - or a3, a3, a5 /* stuff them into the return address */
  1616. - xor a4, a4, a5 /* clear high bits of jump target */
  1617. - or a0, a4, a2 /* create temporary return address */
  1618. - retw /* "return" to .L4, .L8, or .L12 */
  1619. -
  1620. - .align 4
  1621. -.Ljumptable:
  1622. - .word 0
  1623. - .word .L4 - .Ljumptable
  1624. - .word .L8 - .Ljumptable
  1625. - .word .L12 - .Ljumptable
  1626. + l32i a0, a0, 0
  1627. +
  1628. + xor a3, a3, a2 # remove call-size from return address
  1629. + or a0, a0, a2 # create temporary return address
  1630. + retw
  1631. /* a7: return address */
  1632. +
  1633. .L4: mov a12, a2
  1634. mov a13, a3
  1635. - SAVE_PID
  1636. + SAVE_PID(a5,a15,a2,a3)
  1637. - /* Use syscall 'clone'. Set new stack pointer to the same address. */
  1638. - movi a2, SYS_ify (clone)
  1639. + /* use syscall 'clone' and set new stack pointer to the same address */
  1640. +
  1641. + movi a2, SYS_ify(clone)
  1642. movi a3, 0
  1643. movi a6, CLONE_VM | CLONE_VFORK | SIGCHLD
  1644. +
  1645. syscall
  1646. - RESTORE_PID
  1647. + RESTORE_PID(a5,a15,a2)
  1648. movi a5, -4096
  1649. @@ -94,22 +89,24 @@
  1650. bgeu a6, a5, 1f
  1651. jx a7
  1652. -1: call4 .Lerr /* returns to original caller */
  1653. +1: call4 .Lerr
  1654. /* a11: return address */
  1655. +
  1656. .L8: mov a12, a2
  1657. mov a13, a3
  1658. mov a14, a6
  1659. - SAVE_PID
  1660. + SAVE_PID(a9,a15,a2,a3)
  1661. - movi a2, SYS_ify (clone)
  1662. + movi a2, SYS_ify(clone)
  1663. movi a3, 0
  1664. movi a6, CLONE_VM | CLONE_VFORK | SIGCHLD
  1665. +
  1666. syscall
  1667. - RESTORE_PID
  1668. + RESTORE_PID(a9,a15,a2)
  1669. movi a9, -4096
  1670. @@ -120,22 +117,25 @@
  1671. bgeu a10, a9, 1f
  1672. jx a11
  1673. -1: call8 .Lerr /* returns to original caller */
  1674. +
  1675. +1: call8 .Lerr
  1676. /* a15: return address */
  1677. +
  1678. .L12: mov a12, a2
  1679. mov a13, a3
  1680. mov a14, a6
  1681. - SAVE_PID
  1682. + SAVE_PID (a2,a3,a2,a6)
  1683. - movi a2, SYS_ify (clone)
  1684. + movi a2, SYS_ify(clone)
  1685. movi a3, 0
  1686. movi a6, CLONE_VM | CLONE_VFORK | SIGCHLD
  1687. +
  1688. syscall
  1689. - RESTORE_PID
  1690. + RESTORE_PID12(a3,a6,a15)
  1691. mov a3, a13
  1692. movi a13, -4096
  1693. @@ -147,18 +147,18 @@
  1694. bgeu a14, a13, 1f
  1695. jx a15
  1696. -1: call12 .Lerr /* returns to original caller */
  1697. +1: call12 .Lerr
  1698. .align 4
  1699. +
  1700. .Lerr: entry a1, 16
  1701. - /* Restore the return address. */
  1702. - extui a4, a0, 30, 2 /* get the call-size bits */
  1703. + /* Restore return address */
  1704. +
  1705. + extui a4, a0, 30, 2
  1706. slli a4, a4, 30
  1707. - slli a3, a3, 2 /* clear high bits of target address */
  1708. - srli a3, a3, 2
  1709. - or a0, a3, a4 /* combine them */
  1710. + or a0, a3, a4
  1711. PSEUDO_END (__vfork)
  1712. .Lpseudo_end:
  1713. diff -Nur uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/lowlevellock.c uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/lowlevellock.c
  1714. --- uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/lowlevellock.c 2014-06-02 17:40:35.102718006 +0200
  1715. +++ uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/lowlevellock.c 2014-06-03 12:35:45.097932730 +0200
  1716. @@ -22,8 +22,6 @@
  1717. #include <lowlevellock.h>
  1718. #include <sys/time.h>
  1719. #include <tls.h>
  1720. -#include <tcb-offsets.h>
  1721. -
  1722. void
  1723. __lll_lock_wait_private (int *futex)
  1724. diff -Nur uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/bits/pthreadtypes.h uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/bits/pthreadtypes.h
  1725. --- uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/bits/pthreadtypes.h 1970-01-01 01:00:00.000000000 +0100
  1726. +++ uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/bits/pthreadtypes.h 2014-06-03 12:04:16.669187814 +0200
  1727. @@ -0,0 +1,184 @@
  1728. +/* Copyright (C) 2002-2012 Free Software Foundation, Inc.
  1729. + This file is part of the GNU C Library.
  1730. +
  1731. + The GNU C Library is free software; you can redistribute it and/or
  1732. + modify it under the terms of the GNU Lesser General Public
  1733. + License as published by the Free Software Foundation; either
  1734. + version 2.1 of the License, or (at your option) any later version.
  1735. +
  1736. + The GNU C Library is distributed in the hope that it will be useful,
  1737. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  1738. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1739. + Lesser General Public License for more details.
  1740. +
  1741. + You should have received a copy of the GNU Lesser General Public
  1742. + License along with the GNU C Library. If not, see
  1743. + <http://www.gnu.org/licenses/>. */
  1744. +
  1745. +#ifndef _BITS_PTHREADTYPES_H
  1746. +#define _BITS_PTHREADTYPES_H 1
  1747. +
  1748. +#include <endian.h>
  1749. +
  1750. +#define __SIZEOF_PTHREAD_ATTR_T 36
  1751. +#define __SIZEOF_PTHREAD_MUTEX_T 24
  1752. +#define __SIZEOF_PTHREAD_MUTEXATTR_T 4
  1753. +#define __SIZEOF_PTHREAD_COND_T 48
  1754. +#define __SIZEOF_PTHREAD_COND_COMPAT_T 12
  1755. +#define __SIZEOF_PTHREAD_CONDATTR_T 4
  1756. +#define __SIZEOF_PTHREAD_RWLOCK_T 32
  1757. +#define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
  1758. +#define __SIZEOF_PTHREAD_BARRIER_T 20
  1759. +#define __SIZEOF_PTHREAD_BARRIERATTR_T 4
  1760. +
  1761. +
  1762. +/* Thread identifiers. The structure of the attribute type is not
  1763. + exposed on purpose. */
  1764. +typedef unsigned long int pthread_t;
  1765. +
  1766. +
  1767. +union pthread_attr_t
  1768. +{
  1769. + char __size[__SIZEOF_PTHREAD_ATTR_T];
  1770. + long int __align;
  1771. +};
  1772. +#ifndef __have_pthread_attr_t
  1773. +typedef union pthread_attr_t pthread_attr_t;
  1774. +# define __have_pthread_attr_t 1
  1775. +#endif
  1776. +
  1777. +
  1778. +typedef struct __pthread_internal_slist
  1779. +{
  1780. + struct __pthread_internal_slist *__next;
  1781. +} __pthread_slist_t;
  1782. +
  1783. +
  1784. +/* Data structures for mutex handling. The structure of the attribute
  1785. + type is not exposed on purpose. */
  1786. +typedef union
  1787. +{
  1788. + struct __pthread_mutex_s
  1789. + {
  1790. + int __lock;
  1791. + unsigned int __count;
  1792. + int __owner;
  1793. + /* KIND must stay at this position in the structure to maintain
  1794. + binary compatibility. */
  1795. + int __kind;
  1796. + unsigned int __nusers;
  1797. + __extension__ union
  1798. + {
  1799. + int __spins;
  1800. + __pthread_slist_t __list;
  1801. + };
  1802. + } __data;
  1803. + char __size[__SIZEOF_PTHREAD_MUTEX_T];
  1804. + long int __align;
  1805. +} pthread_mutex_t;
  1806. +
  1807. +typedef union
  1808. +{
  1809. + char __size[__SIZEOF_PTHREAD_MUTEXATTR_T];
  1810. + long int __align;
  1811. +} pthread_mutexattr_t;
  1812. +
  1813. +
  1814. +/* Data structure for conditional variable handling. The structure of
  1815. + the attribute type is not exposed on purpose. */
  1816. +typedef union
  1817. +{
  1818. + struct
  1819. + {
  1820. + int __lock;
  1821. + unsigned int __futex;
  1822. + __extension__ unsigned long long int __total_seq;
  1823. + __extension__ unsigned long long int __wakeup_seq;
  1824. + __extension__ unsigned long long int __woken_seq;
  1825. + void *__mutex;
  1826. + unsigned int __nwaiters;
  1827. + unsigned int __broadcast_seq;
  1828. + } __data;
  1829. + char __size[__SIZEOF_PTHREAD_COND_T];
  1830. + __extension__ long long int __align;
  1831. +} pthread_cond_t;
  1832. +
  1833. +typedef union
  1834. +{
  1835. + char __size[__SIZEOF_PTHREAD_CONDATTR_T];
  1836. + long int __align;
  1837. +} pthread_condattr_t;
  1838. +
  1839. +
  1840. +/* Keys for thread-specific data */
  1841. +typedef unsigned int pthread_key_t;
  1842. +
  1843. +
  1844. +/* Once-only execution */
  1845. +typedef int pthread_once_t;
  1846. +
  1847. +
  1848. +#if defined __USE_UNIX98 || defined __USE_XOPEN2K
  1849. +/* Data structure for read-write lock variable handling. The
  1850. + structure of the attribute type is not exposed on purpose. */
  1851. +typedef union
  1852. +{
  1853. + struct
  1854. + {
  1855. + int __lock;
  1856. + unsigned int __nr_readers;
  1857. + unsigned int __readers_wakeup;
  1858. + unsigned int __writer_wakeup;
  1859. + unsigned int __nr_readers_queued;
  1860. + unsigned int __nr_writers_queued;
  1861. +#if __BYTE_ORDER == __BIG_ENDIAN
  1862. + unsigned char __pad1;
  1863. + unsigned char __pad2;
  1864. + unsigned char __shared;
  1865. + /* FLAGS must stay at this position in the structure to maintain
  1866. + binary compatibility. */
  1867. + unsigned char __flags;
  1868. +#else
  1869. + /* FLAGS must stay at this position in the structure to maintain
  1870. + binary compatibility. */
  1871. + unsigned char __flags;
  1872. + unsigned char __shared;
  1873. + unsigned char __pad1;
  1874. + unsigned char __pad2;
  1875. +#endif
  1876. + int __writer;
  1877. + } __data;
  1878. + char __size[__SIZEOF_PTHREAD_RWLOCK_T];
  1879. + long int __align;
  1880. +} pthread_rwlock_t;
  1881. +
  1882. +typedef union
  1883. +{
  1884. + char __size[__SIZEOF_PTHREAD_RWLOCKATTR_T];
  1885. + long int __align;
  1886. +} pthread_rwlockattr_t;
  1887. +#endif
  1888. +
  1889. +
  1890. +#ifdef __USE_XOPEN2K
  1891. +/* POSIX spinlock data type. */
  1892. +typedef volatile int pthread_spinlock_t;
  1893. +
  1894. +
  1895. +/* POSIX barriers data type. The structure of the type is
  1896. + deliberately not exposed. */
  1897. +typedef union
  1898. +{
  1899. + char __size[__SIZEOF_PTHREAD_BARRIER_T];
  1900. + long int __align;
  1901. +} pthread_barrier_t;
  1902. +
  1903. +typedef union
  1904. +{
  1905. + char __size[__SIZEOF_PTHREAD_BARRIERATTR_T];
  1906. + int __align;
  1907. +} pthread_barrierattr_t;
  1908. +#endif
  1909. +
  1910. +
  1911. +#endif /* bits/pthreadtypes.h */
  1912. diff -Nur uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/bits/semaphore.h uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/bits/semaphore.h
  1913. --- uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/bits/semaphore.h 1970-01-01 01:00:00.000000000 +0100
  1914. +++ uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/bits/semaphore.h 2014-06-03 12:04:16.669187814 +0200
  1915. @@ -0,0 +1,35 @@
  1916. +/* Copyright (C) 2012 Free Software Foundation, Inc.
  1917. + This file is part of the GNU C Library.
  1918. +
  1919. + The GNU C Library is free software; you can redistribute it and/or
  1920. + modify it under the terms of the GNU Lesser General Public
  1921. + License as published by the Free Software Foundation; either
  1922. + version 2.1 of the License, or (at your option) any later version.
  1923. +
  1924. + The GNU C Library is distributed in the hope that it will be useful,
  1925. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  1926. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1927. + Lesser General Public License for more details.
  1928. +
  1929. + You should have received a copy of the GNU Lesser General Public
  1930. + License along with the GNU C Library; if not, write to the Free
  1931. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  1932. + 02111-1307 USA. */
  1933. +
  1934. +#ifndef _SEMAPHORE_H
  1935. +# error "Never use <bits/semaphore.h> directly; include <semaphore.h> instead."
  1936. +#endif
  1937. +
  1938. +
  1939. +#define __SIZEOF_SEM_T 16
  1940. +
  1941. +
  1942. +/* Value returned if `sem_open' failed. */
  1943. +#define SEM_FAILED ((sem_t *) 0)
  1944. +
  1945. +
  1946. +typedef union
  1947. +{
  1948. + char __size[__SIZEOF_SEM_T];
  1949. + long int __align;
  1950. +} sem_t;
  1951. diff -Nur uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/clone.S uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/clone.S
  1952. --- uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/clone.S 1970-01-01 01:00:00.000000000 +0100
  1953. +++ uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/clone.S 2014-06-03 12:04:16.669187814 +0200
  1954. @@ -0,0 +1,3 @@
  1955. +#define RESET_PID
  1956. +#include <tcb-offsets.h>
  1957. +#include <libc/sysdeps/linux/xtensa/clone.S>
  1958. diff -Nur uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/createthread.c uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/createthread.c
  1959. --- uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/createthread.c 1970-01-01 01:00:00.000000000 +0100
  1960. +++ uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/createthread.c 2014-06-03 12:04:16.669187814 +0200
  1961. @@ -0,0 +1,24 @@
  1962. +/* Copyright (C) 2012 Free Software Foundation, Inc.
  1963. + This file is part of the GNU C Library.
  1964. +
  1965. + The GNU C Library is free software; you can redistribute it and/or
  1966. + modify it under the terms of the GNU Lesser General Public
  1967. + License as published by the Free Software Foundation; either
  1968. + version 2.1 of the License, or (at your option) any later version.
  1969. +
  1970. + The GNU C Library is distributed in the hope that it will be useful,
  1971. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  1972. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1973. + Lesser General Public License for more details.
  1974. +
  1975. + You should have received a copy of the GNU Lesser General Public
  1976. + License along with the GNU C Library; if not, write to the Free
  1977. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  1978. + 02111-1307 USA. */
  1979. +
  1980. +/* Value passed to 'clone' for initialization of the thread register. */
  1981. +#define TLS_VALUE (pd + 1)
  1982. +
  1983. +
  1984. +/* Get the real implementation. */
  1985. +#include <sysdeps/pthread/createthread.c>
  1986. diff -Nur uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/fork.c uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/fork.c
  1987. --- uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/fork.c 1970-01-01 01:00:00.000000000 +0100
  1988. +++ uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/fork.c 2014-06-03 12:04:16.669187814 +0200
  1989. @@ -0,0 +1,29 @@
  1990. +/* Copyright (C) 2013 Free Software Foundation, Inc.
  1991. + This file is part of the GNU C Library.
  1992. +
  1993. + The GNU C Library is free software; you can redistribute it and/or
  1994. + modify it under the terms of the GNU Lesser General Public
  1995. + License as published by the Free Software Foundation; either
  1996. + version 2.1 of the License, or (at your option) any later version.
  1997. +
  1998. + The GNU C Library is distributed in the hope that it will be useful,
  1999. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  2000. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2001. + Lesser General Public License for more details.
  2002. +
  2003. + You should have received a copy of the GNU Lesser General Public
  2004. + License along with the GNU C Library; if not, see
  2005. + <http://www.gnu.org/licenses/>. */
  2006. +
  2007. +#include <sched.h>
  2008. +#include <signal.h>
  2009. +#include <sysdep.h>
  2010. +#include <tls.h>
  2011. +
  2012. +
  2013. +#define ARCH_FORK() \
  2014. + INLINE_SYSCALL (clone, 5, \
  2015. + CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, 0, \
  2016. + NULL, NULL, &THREAD_SELF->tid)
  2017. +
  2018. +#include "../fork.c"
  2019. diff -Nur uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/lowlevellock.c uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/lowlevellock.c
  2020. --- uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/lowlevellock.c 1970-01-01 01:00:00.000000000 +0100
  2021. +++ uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/lowlevellock.c 2014-06-03 12:04:16.669187814 +0200
  2022. @@ -0,0 +1,132 @@
  2023. +/* low level locking for pthread library. Generic futex-using version.
  2024. + Copyright (C) 2003-2013 Free Software Foundation, Inc.
  2025. + This file is part of the GNU C Library.
  2026. +
  2027. + The GNU C Library is free software; you can redistribute it and/or
  2028. + modify it under the terms of the GNU Lesser General Public
  2029. + License as published by the Free Software Foundation; either
  2030. + version 2.1 of the License, or (at your option) any later version.
  2031. +
  2032. + The GNU C Library is distributed in the hope that it will be useful,
  2033. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  2034. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2035. + Lesser General Public License for more details.
  2036. +
  2037. + You should have received a copy of the GNU Lesser General Public
  2038. + License along with the GNU C Library. If not, see
  2039. + <http://www.gnu.org/licenses/>. */
  2040. +
  2041. +#include <errno.h>
  2042. +#include <sysdep.h>
  2043. +#include <lowlevellock.h>
  2044. +#include <sys/time.h>
  2045. +
  2046. +void
  2047. +__lll_lock_wait_private (int *futex)
  2048. +{
  2049. + do
  2050. + {
  2051. + int oldval = atomic_compare_and_exchange_val_acq (futex, 2, 1);
  2052. + if (oldval != 0)
  2053. + lll_futex_wait (futex, 2, LLL_PRIVATE);
  2054. + }
  2055. + while (atomic_compare_and_exchange_bool_acq (futex, 2, 0) != 0);
  2056. +}
  2057. +
  2058. +
  2059. +/* These functions don't get included in libc.so */
  2060. +#ifdef IS_IN_libpthread
  2061. +void
  2062. +__lll_lock_wait (int *futex, int private)
  2063. +{
  2064. + do
  2065. + {
  2066. + int oldval = atomic_compare_and_exchange_val_acq (futex, 2, 1);
  2067. + if (oldval != 0)
  2068. + lll_futex_wait (futex, 2, private);
  2069. + }
  2070. + while (atomic_compare_and_exchange_bool_acq (futex, 2, 0) != 0);
  2071. +}
  2072. +
  2073. +
  2074. +int
  2075. +__lll_timedlock_wait (int *futex, const struct timespec *abstime, int private)
  2076. +{
  2077. + struct timespec rt;
  2078. +
  2079. + /* Reject invalid timeouts. */
  2080. + if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000)
  2081. + return EINVAL;
  2082. +
  2083. + /* Upgrade the lock. */
  2084. + if (atomic_exchange_acq (futex, 2) == 0)
  2085. + return 0;
  2086. +
  2087. + do
  2088. + {
  2089. + struct timeval tv;
  2090. +
  2091. + /* Get the current time. */
  2092. + (void) __gettimeofday (&tv, NULL);
  2093. +
  2094. + /* Compute relative timeout. */
  2095. + rt.tv_sec = abstime->tv_sec - tv.tv_sec;
  2096. + rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
  2097. + if (rt.tv_nsec < 0)
  2098. + {
  2099. + rt.tv_nsec += 1000000000;
  2100. + --rt.tv_sec;
  2101. + }
  2102. +
  2103. + /* Already timed out? */
  2104. + if (rt.tv_sec < 0)
  2105. + return ETIMEDOUT;
  2106. +
  2107. + // XYZ: Lost the lock to check whether it was private.
  2108. + lll_futex_timed_wait (futex, 2, &rt, private);
  2109. + }
  2110. + while (atomic_compare_and_exchange_bool_acq (futex, 2, 0) != 0);
  2111. +
  2112. + return 0;
  2113. +}
  2114. +
  2115. +
  2116. +int
  2117. +__lll_timedwait_tid (int *tidp, const struct timespec *abstime)
  2118. +{
  2119. + int tid;
  2120. +
  2121. + if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000)
  2122. + return EINVAL;
  2123. +
  2124. + /* Repeat until thread terminated. */
  2125. + while ((tid = *tidp) != 0)
  2126. + {
  2127. + struct timeval tv;
  2128. + struct timespec rt;
  2129. +
  2130. + /* Get the current time. */
  2131. + (void) __gettimeofday (&tv, NULL);
  2132. +
  2133. + /* Compute relative timeout. */
  2134. + rt.tv_sec = abstime->tv_sec - tv.tv_sec;
  2135. + rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
  2136. + if (rt.tv_nsec < 0)
  2137. + {
  2138. + rt.tv_nsec += 1000000000;
  2139. + --rt.tv_sec;
  2140. + }
  2141. +
  2142. + /* Already timed out? */
  2143. + if (rt.tv_sec < 0)
  2144. + return ETIMEDOUT;
  2145. +
  2146. + /* Wait until thread terminates. */
  2147. + // XYZ: Lost the lock to check whether it was private.
  2148. + if (lll_futex_timed_wait (tidp, tid, &rt, LLL_SHARED) == -ETIMEDOUT)
  2149. + return ETIMEDOUT;
  2150. + }
  2151. +
  2152. + return 0;
  2153. +}
  2154. +#endif
  2155. diff -Nur uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/lowlevellock.h uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/lowlevellock.h
  2156. --- uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/lowlevellock.h 1970-01-01 01:00:00.000000000 +0100
  2157. +++ uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/lowlevellock.h 2014-06-03 12:04:16.669187814 +0200
  2158. @@ -0,0 +1,293 @@
  2159. +/* Copyright (C) 2005-2013 Free Software Foundation, Inc.
  2160. + This file is part of the GNU C Library.
  2161. +
  2162. + The GNU C Library is free software; you can redistribute it and/or
  2163. + modify it under the terms of the GNU Lesser General Public
  2164. + License as published by the Free Software Foundation; either
  2165. + version 2.1 of the License, or (at your option) any later version.
  2166. +
  2167. + The GNU C Library is distributed in the hope that it will be useful,
  2168. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  2169. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2170. + Lesser General Public License for more details.
  2171. +
  2172. + You should have received a copy of the GNU Lesser General Public
  2173. + License along with the GNU C Library. If not, see
  2174. + <http://www.gnu.org/licenses/>. */
  2175. +
  2176. +#ifndef _LOWLEVELLOCK_H
  2177. +#define _LOWLEVELLOCK_H 1
  2178. +
  2179. +#include <time.h>
  2180. +#include <sys/param.h>
  2181. +#include <bits/pthreadtypes.h>
  2182. +#include <atomic.h>
  2183. +#include <sysdep.h>
  2184. +#include <bits/kernel-features.h>
  2185. +
  2186. +#define FUTEX_WAIT 0
  2187. +#define FUTEX_WAKE 1
  2188. +#define FUTEX_REQUEUE 3
  2189. +#define FUTEX_CMP_REQUEUE 4
  2190. +#define FUTEX_WAKE_OP 5
  2191. +#define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE ((4 << 24) | 1)
  2192. +#define FUTEX_LOCK_PI 6
  2193. +#define FUTEX_UNLOCK_PI 7
  2194. +#define FUTEX_TRYLOCK_PI 8
  2195. +#define FUTEX_WAIT_BITSET 9
  2196. +#define FUTEX_WAKE_BITSET 10
  2197. +#define FUTEX_PRIVATE_FLAG 128
  2198. +#define FUTEX_CLOCK_REALTIME 256
  2199. +
  2200. +#define FUTEX_BITSET_MATCH_ANY 0xffffffff
  2201. +
  2202. +/* Values for 'private' parameter of locking macros. Yes, the
  2203. + definition seems to be backwards. But it is not. The bit will be
  2204. + reversed before passing to the system call. */
  2205. +#define LLL_PRIVATE 0
  2206. +#define LLL_SHARED FUTEX_PRIVATE_FLAG
  2207. +
  2208. +
  2209. +#if !defined NOT_IN_libc || defined IS_IN_rtld
  2210. +/* In libc.so or ld.so all futexes are private. */
  2211. +# ifdef __ASSUME_PRIVATE_FUTEX
  2212. +# define __lll_private_flag(fl, private) \
  2213. + ((fl) | FUTEX_PRIVATE_FLAG)
  2214. +# else
  2215. +# define __lll_private_flag(fl, private) \
  2216. + ((fl) | THREAD_GETMEM (THREAD_SELF, header.private_futex))
  2217. +# endif
  2218. +#else
  2219. +# ifdef __ASSUME_PRIVATE_FUTEX
  2220. +# define __lll_private_flag(fl, private) \
  2221. + (((fl) | FUTEX_PRIVATE_FLAG) ^ (private))
  2222. +# else
  2223. +# define __lll_private_flag(fl, private) \
  2224. + (__builtin_constant_p (private) \
  2225. + ? ((private) == 0 \
  2226. + ? ((fl) | THREAD_GETMEM (THREAD_SELF, header.private_futex)) \
  2227. + : (fl)) \
  2228. + : ((fl) | (((private) ^ FUTEX_PRIVATE_FLAG) \
  2229. + & THREAD_GETMEM (THREAD_SELF, header.private_futex))))
  2230. +# endif
  2231. +#endif
  2232. +
  2233. +
  2234. +#define lll_futex_wait(futexp, val, private) \
  2235. + lll_futex_timed_wait(futexp, val, NULL, private)
  2236. +
  2237. +#define lll_futex_timed_wait(futexp, val, timespec, private) \
  2238. + ({ \
  2239. + INTERNAL_SYSCALL_DECL (__err); \
  2240. + long int __ret; \
  2241. + __ret = INTERNAL_SYSCALL (futex, __err, 4, (futexp), \
  2242. + __lll_private_flag (FUTEX_WAIT, private), \
  2243. + (val), (timespec)); \
  2244. + __ret; \
  2245. + })
  2246. +
  2247. +#define lll_futex_timed_wait_bitset(futexp, val, timespec, clockbit, private) \
  2248. + ({ \
  2249. + INTERNAL_SYSCALL_DECL (__err); \
  2250. + long int __ret; \
  2251. + int __op = FUTEX_WAIT_BITSET | clockbit; \
  2252. + __ret = INTERNAL_SYSCALL (futex, __err, 6, (futexp), \
  2253. + __lll_private_flag (__op, private), \
  2254. + (val), (timespec), NULL /* Unused. */, \
  2255. + FUTEX_BITSET_MATCH_ANY); \
  2256. + __ret; \
  2257. + })
  2258. +
  2259. +#define lll_futex_wake(futexp, nr, private) \
  2260. + ({ \
  2261. + INTERNAL_SYSCALL_DECL (__err); \
  2262. + long int __ret; \
  2263. + __ret = INTERNAL_SYSCALL (futex, __err, 4, (futexp), \
  2264. + __lll_private_flag (FUTEX_WAKE, private), \
  2265. + (nr), 0); \
  2266. + __ret; \
  2267. + })
  2268. +
  2269. +#define lll_robust_dead(futexv, private) \
  2270. + do \
  2271. + { \
  2272. + int *__futexp = &(futexv); \
  2273. + atomic_or (__futexp, FUTEX_OWNER_DIED); \
  2274. + lll_futex_wake (__futexp, 1, private); \
  2275. + } \
  2276. + while (0)
  2277. +
  2278. +/* Returns non-zero if error happened, zero if success. */
  2279. +#define lll_futex_requeue(futexp, nr_wake, nr_move, mutex, val, private) \
  2280. + ({ \
  2281. + INTERNAL_SYSCALL_DECL (__err); \
  2282. + long int __ret; \
  2283. + __ret = INTERNAL_SYSCALL (futex, __err, 6, (futexp), \
  2284. + __lll_private_flag (FUTEX_CMP_REQUEUE, private),\
  2285. + (nr_wake), (nr_move), (mutex), (val)); \
  2286. + INTERNAL_SYSCALL_ERROR_P (__ret, __err); \
  2287. + })
  2288. +
  2289. +
  2290. +/* Returns non-zero if error happened, zero if success. */
  2291. +#define lll_futex_wake_unlock(futexp, nr_wake, nr_wake2, futexp2, private) \
  2292. + ({ \
  2293. + INTERNAL_SYSCALL_DECL (__err); \
  2294. + long int __ret; \
  2295. + __ret = INTERNAL_SYSCALL (futex, __err, 6, (futexp), \
  2296. + __lll_private_flag (FUTEX_WAKE_OP, private), \
  2297. + (nr_wake), (nr_wake2), (futexp2), \
  2298. + FUTEX_OP_CLEAR_WAKE_IF_GT_ONE); \
  2299. + INTERNAL_SYSCALL_ERROR_P (__ret, __err); \
  2300. + })
  2301. +
  2302. +
  2303. +#define lll_trylock(lock) \
  2304. + atomic_compare_and_exchange_val_acq(&(lock), 1, 0)
  2305. +
  2306. +#define lll_cond_trylock(lock) \
  2307. + atomic_compare_and_exchange_val_acq(&(lock), 2, 0)
  2308. +
  2309. +#define __lll_robust_trylock(futex, id) \
  2310. + (atomic_compare_and_exchange_val_acq (futex, id, 0) != 0)
  2311. +#define lll_robust_trylock(lock, id) \
  2312. + __lll_robust_trylock (&(lock), id)
  2313. +
  2314. +extern void __lll_lock_wait_private (int *futex) attribute_hidden;
  2315. +extern void __lll_lock_wait (int *futex, int private) attribute_hidden;
  2316. +extern int __lll_robust_lock_wait (int *futex, int private) attribute_hidden;
  2317. +
  2318. +#define __lll_lock(futex, private) \
  2319. + ((void) ({ \
  2320. + int *__futex = (futex); \
  2321. + if (__builtin_expect (atomic_compare_and_exchange_val_acq (__futex, \
  2322. + 1, 0), 0)) \
  2323. + { \
  2324. + if (__builtin_constant_p (private) && (private) == LLL_PRIVATE) \
  2325. + __lll_lock_wait_private (__futex); \
  2326. + else \
  2327. + __lll_lock_wait (__futex, private); \
  2328. + } \
  2329. + }))
  2330. +#define lll_lock(futex, private) __lll_lock (&(futex), private)
  2331. +
  2332. +
  2333. +#define __lll_robust_lock(futex, id, private) \
  2334. + ({ \
  2335. + int *__futex = (futex); \
  2336. + int __val = 0; \
  2337. + \
  2338. + if (__builtin_expect (atomic_compare_and_exchange_bool_acq (__futex, id, \
  2339. + 0), 0)) \
  2340. + __val = __lll_robust_lock_wait (__futex, private); \
  2341. + __val; \
  2342. + })
  2343. +#define lll_robust_lock(futex, id, private) \
  2344. + __lll_robust_lock (&(futex), id, private)
  2345. +
  2346. +
  2347. +#define __lll_cond_lock(futex, private) \
  2348. + ((void) ({ \
  2349. + int *__futex = (futex); \
  2350. + if (__builtin_expect (atomic_exchange_acq (__futex, 2), 0)) \
  2351. + __lll_lock_wait (__futex, private); \
  2352. + }))
  2353. +#define lll_cond_lock(futex, private) __lll_cond_lock (&(futex), private)
  2354. +
  2355. +
  2356. +#define lll_robust_cond_lock(futex, id, private) \
  2357. + __lll_robust_lock (&(futex), (id) | FUTEX_WAITERS, private)
  2358. +
  2359. +
  2360. +extern int __lll_timedlock_wait (int *futex, const struct timespec *,
  2361. + int private) attribute_hidden;
  2362. +extern int __lll_robust_timedlock_wait (int *futex, const struct timespec *,
  2363. + int private) attribute_hidden;
  2364. +
  2365. +#define __lll_timedlock(futex, abstime, private) \
  2366. + ({ \
  2367. + int *__futex = (futex); \
  2368. + int __val = 0; \
  2369. + \
  2370. + if (__builtin_expect (atomic_exchange_acq (__futex, 1), 0)) \
  2371. + __val = __lll_timedlock_wait (__futex, abstime, private); \
  2372. + __val; \
  2373. + })
  2374. +#define lll_timedlock(futex, abstime, private) \
  2375. + __lll_timedlock (&(futex), abstime, private)
  2376. +
  2377. +
  2378. +#define __lll_robust_timedlock(futex, abstime, id, private) \
  2379. + ({ \
  2380. + int *__futex = (futex); \
  2381. + int __val = 0; \
  2382. + \
  2383. + if (__builtin_expect (atomic_compare_and_exchange_bool_acq (__futex, id, \
  2384. + 0), 0)) \
  2385. + __val = __lll_robust_timedlock_wait (__futex, abstime, private); \
  2386. + __val; \
  2387. + })
  2388. +#define lll_robust_timedlock(futex, abstime, id, private) \
  2389. + __lll_robust_timedlock (&(futex), abstime, id, private)
  2390. +
  2391. +
  2392. +#define __lll_unlock(futex, private) \
  2393. + (void) \
  2394. + ({ int *__futex = (futex); \
  2395. + int __oldval = atomic_exchange_rel (__futex, 0); \
  2396. + if (__builtin_expect (__oldval > 1, 0)) \
  2397. + lll_futex_wake (__futex, 1, private); \
  2398. + })
  2399. +#define lll_unlock(futex, private) __lll_unlock(&(futex), private)
  2400. +
  2401. +
  2402. +#define __lll_robust_unlock(futex, private) \
  2403. + (void) \
  2404. + ({ int *__futex = (futex); \
  2405. + int __oldval = atomic_exchange_rel (__futex, 0); \
  2406. + if (__builtin_expect (__oldval & FUTEX_WAITERS, 0)) \
  2407. + lll_futex_wake (__futex, 1, private); \
  2408. + })
  2409. +#define lll_robust_unlock(futex, private) \
  2410. + __lll_robust_unlock(&(futex), private)
  2411. +
  2412. +
  2413. +#define lll_islocked(futex) \
  2414. + (futex != 0)
  2415. +
  2416. +
  2417. +/* Our internal lock implementation is identical to the binary-compatible
  2418. + mutex implementation. */
  2419. +
  2420. +/* Initializers for lock. */
  2421. +#define LLL_LOCK_INITIALIZER (0)
  2422. +#define LLL_LOCK_INITIALIZER_LOCKED (1)
  2423. +
  2424. +/* The states of a lock are:
  2425. + 0 - untaken
  2426. + 1 - taken by one user
  2427. + >1 - taken by more users */
  2428. +
  2429. +/* The kernel notifies a process which uses CLONE_CHILD_CLEARTID via futex
  2430. + wakeup when the clone terminates. The memory location contains the
  2431. + thread ID while the clone is running and is reset to zero
  2432. + afterwards. */
  2433. +#define lll_wait_tid(tid) \
  2434. + do { \
  2435. + __typeof (tid) __tid; \
  2436. + while ((__tid = (tid)) != 0) \
  2437. + lll_futex_wait (&(tid), __tid, LLL_SHARED);\
  2438. + } while (0)
  2439. +
  2440. +extern int __lll_timedwait_tid (int *, const struct timespec *)
  2441. + attribute_hidden;
  2442. +
  2443. +#define lll_timedwait_tid(tid, abstime) \
  2444. + ({ \
  2445. + int __res = 0; \
  2446. + if ((tid) != 0) \
  2447. + __res = __lll_timedwait_tid (&(tid), (abstime)); \
  2448. + __res; \
  2449. + })
  2450. +
  2451. +#endif /* lowlevellock.h */
  2452. diff -Nur uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/Makefile.arch uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/Makefile.arch
  2453. --- uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/Makefile.arch 1970-01-01 01:00:00.000000000 +0100
  2454. +++ uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/Makefile.arch 2014-06-03 12:04:16.669187814 +0200
  2455. @@ -0,0 +1,17 @@
  2456. +# Makefile for uClibc NPTL
  2457. +#
  2458. +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  2459. +#
  2460. +
  2461. +libc_linux_arch_CSRC = fork.c
  2462. +libc_linux_arch_SSRC = clone.S vfork.S
  2463. +libpthread_linux_arch_CSRC = pthread_once.c
  2464. +libpthread_linux_arch_SSRC = pt-vfork.S
  2465. +
  2466. +CFLAGS-OMIT-fork.c = -DNOT_IN_libc -DIS_IN_libpthread
  2467. +ASFLAGS-pt-vfork.S = -DNOT_IN_libc -DIS_IN_libpthread -D_LIBC_REENTRANT
  2468. +
  2469. +ASFLAGS-clone.S = -D_LIBC_REENTRANT
  2470. +ASFLAGS-vfork.S = -D_LIBC_REENTRANT
  2471. +ASFLAGS-syscall.S = -D_LIBC_REENTRANT
  2472. +ASFLAGS-mmap.S = -D_LIBC_REENTRANT
  2473. diff -Nur uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/pthread_once.c uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/pthread_once.c
  2474. --- uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/pthread_once.c 1970-01-01 01:00:00.000000000 +0100
  2475. +++ uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/pthread_once.c 2014-06-03 12:04:16.669187814 +0200
  2476. @@ -0,0 +1,89 @@
  2477. +/* Copyright (C) 2004-2013 Free Software Foundation, Inc.
  2478. + This file is part of the GNU C Library.
  2479. +
  2480. + The GNU C Library is free software; you can redistribute it and/or
  2481. + modify it under the terms of the GNU Lesser General Public
  2482. + License as published by the Free Software Foundation; either
  2483. + version 2.1 of the License, or (at your option) any later version.
  2484. +
  2485. + The GNU C Library is distributed in the hope that it will be useful,
  2486. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  2487. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2488. + Lesser General Public License for more details.
  2489. +
  2490. + You should have received a copy of the GNU Lesser General Public
  2491. + License along with the GNU C Library. If not, see
  2492. + <http://www.gnu.org/licenses/>. */
  2493. +
  2494. +#include "pthreadP.h"
  2495. +#include <lowlevellock.h>
  2496. +
  2497. +unsigned long int __fork_generation attribute_hidden;
  2498. +
  2499. +static void
  2500. +clear_once_control (void *arg)
  2501. +{
  2502. + pthread_once_t *once_control = (pthread_once_t *) arg;
  2503. +
  2504. + *once_control = 0;
  2505. + lll_futex_wake (once_control, INT_MAX, LLL_PRIVATE);
  2506. +}
  2507. +
  2508. +int
  2509. +__pthread_once (pthread_once_t *once_control, void (*init_routine) (void))
  2510. +{
  2511. + for (;;)
  2512. + {
  2513. + int oldval;
  2514. + int newval;
  2515. +
  2516. + /* Pseudo code:
  2517. + newval = __fork_generation | 1;
  2518. + oldval = *once_control;
  2519. + if ((oldval & 2) == 0)
  2520. + *once_control = newval;
  2521. + Do this atomically.
  2522. + */
  2523. + do
  2524. + {
  2525. + newval = __fork_generation | 1;
  2526. + oldval = *once_control;
  2527. + if (oldval & 2)
  2528. + break;
  2529. + } while (atomic_compare_and_exchange_val_acq (once_control, newval, oldval) != oldval);
  2530. +
  2531. + /* Check if the initializer has already been done. */
  2532. + if ((oldval & 2) != 0)
  2533. + return 0;
  2534. +
  2535. + /* Check if another thread already runs the initializer. */
  2536. + if ((oldval & 1) == 0)
  2537. + break;
  2538. +
  2539. + /* Check whether the initializer execution was interrupted by a fork. */
  2540. + if (oldval != newval)
  2541. + break;
  2542. +
  2543. + /* Same generation, some other thread was faster. Wait. */
  2544. + lll_futex_wait (once_control, oldval, LLL_PRIVATE);
  2545. + }
  2546. +
  2547. + /* This thread is the first here. Do the initialization.
  2548. + Register a cleanup handler so that in case the thread gets
  2549. + interrupted the initialization can be restarted. */
  2550. + pthread_cleanup_push (clear_once_control, once_control);
  2551. +
  2552. + init_routine ();
  2553. +
  2554. + pthread_cleanup_pop (0);
  2555. +
  2556. + /* Say that the initialisation is done. */
  2557. + *once_control = __fork_generation | 2;
  2558. +
  2559. + /* Wake up all other threads. */
  2560. + lll_futex_wake (once_control, INT_MAX, LLL_PRIVATE);
  2561. +
  2562. + return 0;
  2563. +}
  2564. +weak_alias (__pthread_once, pthread_once)
  2565. +strong_alias (__pthread_once, __pthread_once_internal)
  2566. diff -Nur uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/pt-initfini.c uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/pt-initfini.c
  2567. --- uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/pt-initfini.c 1970-01-01 01:00:00.000000000 +0100
  2568. +++ uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/pt-initfini.c 2014-06-03 12:04:16.669187814 +0200
  2569. @@ -0,0 +1,134 @@
  2570. +/* Special .init and .fini section support. Linuxthread version.
  2571. + Copyright (C) 1995,1996,1997,2000,2001,2002 Free Software Foundation, Inc.
  2572. + This file is part of the GNU C Library.
  2573. +
  2574. + The GNU C Library is free software; you can redistribute it
  2575. + and/or modify it under the terms of the GNU Lesser General Public
  2576. + License as published by the Free Software Foundation; either
  2577. + version 2 of the License, or (at your option) any later version.
  2578. +
  2579. + In addition to the permissions in the GNU Lesser General Public
  2580. + License, the Free Software Foundation gives you unlimited
  2581. + permission to link the compiled version of this file with other
  2582. + programs, and to distribute those programs without any restriction
  2583. + coming from the use of this file. (The Library General Public
  2584. + License restrictions do apply in other respects; for example, they
  2585. + cover modification of the file, and distribution when not linked
  2586. + into another program.)
  2587. +
  2588. + The GNU C Library is distributed in the hope that it will be
  2589. + useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  2590. + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2591. + GNU Lesser General Public License for more details.
  2592. +
  2593. + You should have received a copy of the GNU Lesser General Public
  2594. + License along with the GNU C Library; see the file COPYING.LIB. If not,
  2595. + see <http://www.gnu.org/licenses/>. */
  2596. +
  2597. +/* This file is compiled into assembly code which is then munged by a sed
  2598. + script into two files: crti.s and crtn.s.
  2599. +
  2600. + * crti.s puts a function prologue at the beginning of the
  2601. + .init and .fini sections and defines global symbols for
  2602. + those addresses, so they can be called as functions.
  2603. +
  2604. + * crtn.s puts the corresponding function epilogues
  2605. + in the .init and .fini sections. */
  2606. +
  2607. +#include <stdlib.h>
  2608. +
  2609. +/* We use embedded asm for .section unconditionally, as this makes it
  2610. + easier to insert the necessary directives into crtn.S. */
  2611. +#define SECTION(x) __asm__ (".section " x )
  2612. +
  2613. +/* Embed an #include to pull in the alignment and .end directives. */
  2614. +__asm__ ("\n#include \"defs.h\"");
  2615. +__asm__ ("\n#if defined __i686 && defined __ASSEMBLER__");
  2616. +__asm__ ("\n#undef __i686");
  2617. +__asm__ ("\n#define __i686 __i686");
  2618. +__asm__ ("\n#endif");
  2619. +
  2620. +/* The initial common code ends here. */
  2621. +__asm__ ("\n/*@HEADER_ENDS*/");
  2622. +
  2623. +/* To determine whether we need .end and .align: */
  2624. +__asm__ ("\n/*@TESTS_BEGIN*/");
  2625. +extern void dummy (void (*foo) (void));
  2626. +void
  2627. +dummy (void (*foo) (void))
  2628. +{
  2629. + if (foo)
  2630. + (*foo) ();
  2631. +}
  2632. +__asm__ ("\n/*@TESTS_END*/");
  2633. +
  2634. +/* The beginning of _init: */
  2635. +__asm__ ("\n/*@_init_PROLOG_BEGINS*/");
  2636. +
  2637. +static void
  2638. +call_initialize_minimal (void)
  2639. +{
  2640. + extern void __pthread_initialize_minimal_internal (void)
  2641. + __attribute ((visibility ("hidden")));
  2642. +
  2643. + __pthread_initialize_minimal_internal ();
  2644. +}
  2645. +
  2646. +SECTION (".init");
  2647. +extern void __attribute__ ((section (".init"))) _init (void);
  2648. +void
  2649. +_init (void)
  2650. +{
  2651. + /* The very first thing we must do is to set up the registers. */
  2652. + call_initialize_minimal ();
  2653. +
  2654. + __asm__ ("ALIGN");
  2655. + __asm__("END_INIT");
  2656. + /* Now the epilog. */
  2657. + __asm__ ("\n/*@_init_PROLOG_ENDS*/");
  2658. + __asm__ ("\n/*@_init_EPILOG_BEGINS*/");
  2659. + SECTION(".init");
  2660. +}
  2661. +__asm__ ("END_INIT");
  2662. +
  2663. +/* End of the _init epilog, beginning of the _fini prolog. */
  2664. +__asm__ ("\n/*@_init_EPILOG_ENDS*/");
  2665. +__asm__ ("\n/*@_fini_PROLOG_BEGINS*/");
  2666. +
  2667. +SECTION (".fini");
  2668. +extern void __attribute__ ((section (".fini"))) _fini (void);
  2669. +void
  2670. +_fini (void)
  2671. +{
  2672. +
  2673. + /* End of the _fini prolog. */
  2674. + __asm__ ("ALIGN");
  2675. + __asm__ ("END_FINI");
  2676. + __asm__ ("\n/*@_fini_PROLOG_ENDS*/");
  2677. +
  2678. + /* Xtensa: It doesn't really matter whether GCC thinks this is a leaf
  2679. + function or not, and the scripts that are supposed to remove the
  2680. + call don't catch the literal, resulting in an undefined symbol
  2681. + reference. */
  2682. +#if 0
  2683. + {
  2684. + /* Let GCC know that _fini is not a leaf function by having a dummy
  2685. + function call here. We arrange for this call to be omitted from
  2686. + either crt file. */
  2687. + extern void i_am_not_a_leaf (void);
  2688. + i_am_not_a_leaf ();
  2689. + }
  2690. +#endif
  2691. +
  2692. + /* Beginning of the _fini epilog. */
  2693. + __asm__ ("\n/*@_fini_EPILOG_BEGINS*/");
  2694. + SECTION (".fini");
  2695. +}
  2696. +__asm__ ("END_FINI");
  2697. +
  2698. +/* End of the _fini epilog. Any further generated assembly (e.g. .ident)
  2699. + is shared between both crt files. */
  2700. +__asm__ ("\n/*@_fini_EPILOG_ENDS*/");
  2701. +__asm__ ("\n/*@TRAILER_BEGINS*/");
  2702. +
  2703. +/* End of file. */
  2704. diff -Nur uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/pt-vfork.S uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/pt-vfork.S
  2705. --- uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/pt-vfork.S 1970-01-01 01:00:00.000000000 +0100
  2706. +++ uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/pt-vfork.S 2014-06-03 12:04:16.669187814 +0200
  2707. @@ -0,0 +1,48 @@
  2708. +/* Copyright (C) 2013 Free Software Foundation, Inc.
  2709. + This file is part of the GNU C Library.
  2710. +
  2711. + The GNU C Library is free software; you can redistribute it and/or
  2712. + modify it under the terms of the GNU Lesser General Public
  2713. + License as published by the Free Software Foundation; either
  2714. + version 2.1 of the License, or (at your option) any later version.
  2715. +
  2716. + The GNU C Library is distributed in the hope that it will be useful,
  2717. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  2718. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2719. + Lesser General Public License for more details.
  2720. +
  2721. + You should have received a copy of the GNU Lesser General Public
  2722. + License along with the GNU C Library. If not, see
  2723. + <http://www.gnu.org/licenses/>. */
  2724. +
  2725. +#include <tls.h>
  2726. +
  2727. +/*
  2728. + Save the PID value (save the negated value)
  2729. + Registers ar, as are available; pid, tp are preserved across
  2730. + */
  2731. +#define SAVE_PID(pid, tp, ar, as) \
  2732. + rur tp, threadptr; \
  2733. + movi ar, TLS_PRE_TCB_SIZE; \
  2734. + sub tp, tp, ar; \
  2735. + l32i pid, tp, PID; \
  2736. + neg ar, pid; \
  2737. + s32i pid, tp, PID; \
  2738. +
  2739. +/*
  2740. + Restore the PID value if we are back in the parent.
  2741. + */
  2742. +#define RESTORE_PID(pid, tp, res) \
  2743. + beqz res, 1f; \
  2744. + s32i pid, tp, PID; \
  2745. +1:
  2746. +
  2747. +#define RESTORE_PID12(ar, as, at) \
  2748. + rur as, threadptr; \
  2749. + movi ar, TLS_PRE_TCB_SIZE; \
  2750. + sub as, as, ar; \
  2751. + l32i ar, as, PID; \
  2752. + neg ar, ar; \
  2753. + s32i ar, as, PID;
  2754. +
  2755. +#include <libc/sysdeps/linux/xtensa/vfork.S>
  2756. diff -Nur uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/sysdep-cancel.h uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/sysdep-cancel.h
  2757. --- uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/sysdep-cancel.h 1970-01-01 01:00:00.000000000 +0100
  2758. +++ uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/sysdep-cancel.h 2014-06-03 12:04:16.669187814 +0200
  2759. @@ -0,0 +1,108 @@
  2760. +/* Copyright (C) 2003 Free Software Foundation, Inc.
  2761. + This file is part of the GNU C Library.
  2762. +
  2763. + The GNU C Library is free software; you can redistribute it and/or
  2764. + modify it under the terms of the GNU Lesser General Public
  2765. + License as published by the Free Software Foundation; either
  2766. + version 2.1 of the License, or (at your option) any later version.
  2767. +
  2768. + The GNU C Library is distributed in the hope that it will be useful,
  2769. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  2770. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2771. + Lesser General Public License for more details.
  2772. +
  2773. + You should have received a copy of the GNU Lesser General Public
  2774. + License along with the GNU C Library; if not, write to the Free
  2775. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  2776. + 02111-1307 USA. */
  2777. +
  2778. +#include <sysdep.h>
  2779. +#include <tls.h>
  2780. +/* #include <pt-machine.h> */
  2781. +#ifndef __ASSEMBLER__
  2782. +# include <pthreadP.h>
  2783. +#endif
  2784. +
  2785. +#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
  2786. +// FIXME: ENTRY includes an entry instruction, here we'd want entry sp, 48!
  2787. +# undef PSEUDO
  2788. +# define PSEUDO(name, syscall_name, args) \
  2789. + .text; \
  2790. + ENTRY (name) \
  2791. + SINGLE_THREAD_P(a15); \
  2792. + bnez a15, .Lpseudo_cancel; \
  2793. + DO_CALL (syscall_name, args); \
  2794. + bgez a2, .Lpseudo_done; \
  2795. + movi a4, -4095; \
  2796. + blt a2, a4, .Lpseudo_done; \
  2797. + j SYSCALL_ERROR_LABEL; \
  2798. + .Lpseudo_done: \
  2799. + retw; \
  2800. + .Lpseudo_cancel: \
  2801. + /* The syscall args are in a2...a7; no need to save */ \
  2802. + CENABLE; \
  2803. + /* The return value is in a10 and preserved across the syscall */ \
  2804. + DO_CALL (syscall_name, args); \
  2805. + CDISABLE; \
  2806. + bgez a2, .Lpseudo_end; \
  2807. + movi a4, -4095; \
  2808. + blt a2, a4, .Lpseudo_end; \
  2809. + j SYSCALL_ERROR_LABEL; \
  2810. + .Lpseudo_end:
  2811. +
  2812. +
  2813. +# ifdef IS_IN_libpthread
  2814. +# define CENABLE_FUNC __pthread_enable_asynccancel
  2815. +# define CDISABLE_FUNC __pthread_disable_asynccancel
  2816. +# define __local_multiple_threads __pthread_multiple_threads
  2817. +# elif !defined NOT_IN_libc
  2818. +# define CENABLE_FUNC __libc_enable_asynccancel
  2819. +# define CDISABLE_FUNC __libc_disable_asynccancel
  2820. +# define __local_multiple_threads __libc_multiple_threads
  2821. +# elif defined IS_IN_librt
  2822. +# define CENABLE_FUNC __librt_enable_asynccancel
  2823. +# define CDISABLE_FUNC __librt_disable_asynccancel
  2824. +# else
  2825. +# error Unsupported library
  2826. +# endif
  2827. +
  2828. +# define CENABLE movi a8, CENABLE_FUNC; \
  2829. + callx8 a8
  2830. +# define CDISABLE movi a8, CDISABLE_FUNC; \
  2831. + callx8 a8
  2832. +
  2833. +# if defined IS_IN_libpthread || !defined NOT_IN_libc
  2834. +# ifndef __ASSEMBLER__
  2835. +extern int __local_multiple_threads attribute_hidden;
  2836. +# define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
  2837. +# else
  2838. +# define SINGLE_THREAD_P(reg) movi reg, __local_multiple_threads; \
  2839. + l32i reg, reg, 0;
  2840. +# endif
  2841. +
  2842. +# else
  2843. +# ifndef __ASSEMBLER__
  2844. +# define SINGLE_THREAD_P \
  2845. + __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  2846. + header.multiple_threads) == 0, 1)
  2847. +# else
  2848. +# define SINGLE_THREAD_P(reg) \
  2849. + rur reg, threadptr; \
  2850. + l32i reg, reg, MULTIPLE_THREADS_OFFSET;
  2851. +# endif
  2852. +# endif
  2853. +
  2854. +#else
  2855. +
  2856. +/* This code should never be used but we define it anyhow. */
  2857. +# define SINGLE_THREAD_P (1)
  2858. +# define NO_CANCELLATION 1
  2859. +
  2860. +#endif
  2861. +
  2862. +
  2863. +#ifndef __ASSEMBLER__
  2864. +# define RTLD_SINGLE_THREAD_P \
  2865. + __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  2866. + header.multiple_threads) == 0, 1)
  2867. +#endif
  2868. diff -Nur uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/vfork.S uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/vfork.S
  2869. --- uClibc-git/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/vfork.S 1970-01-01 01:00:00.000000000 +0100
  2870. +++ uClibc-xtensa/libpthread/nptl/sysdeps/unix/sysv/linux/xtensa/vfork.S 2014-06-03 12:04:16.669187814 +0200
  2871. @@ -0,0 +1,59 @@
  2872. +/* Copyright (C) 2013 Free Software Foundation, Inc.
  2873. + This file is part of the GNU C Library.
  2874. +
  2875. + The GNU C Library is free software; you can redistribute it and/or
  2876. + modify it under the terms of the GNU Lesser General Public
  2877. + License as published by the Free Software Foundation; either
  2878. + version 2.1 of the License, or (at your option) any later version.
  2879. +
  2880. + The GNU C Library is distributed in the hope that it will be useful,
  2881. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  2882. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2883. + Lesser General Public License for more details.
  2884. +
  2885. + You should have received a copy of the GNU Lesser General Public
  2886. + License along with the GNU C Library. If not, see
  2887. + <http://www.gnu.org/licenses/>. */
  2888. +
  2889. +#include <tls.h>
  2890. +
  2891. +/*
  2892. + Save the PID value, save 0x80000000 if PID was 0.
  2893. + Registers a2 and a3 are available; ar should return the PID and as threadptr
  2894. + */
  2895. +
  2896. +#define SAVE_PID(pid,tp,ar,as) \
  2897. + rur tp, threadptr; \
  2898. + movi ar, TLS_PRE_TCB_SIZE; \
  2899. + sub tp, tp, ar; \
  2900. + l32i pid, tp, PID; \
  2901. + neg ar, pid; \
  2902. + movi as, 0x80000000; \
  2903. + moveqz ar, as, ar; \
  2904. + s32i ar, tp, PID; \
  2905. +
  2906. +/*
  2907. + Restore the PID value, restore to 0 if saved value was 0x80000000
  2908. + Return value from the syscall is in a2.
  2909. + */
  2910. +#define RESTORE_PID(pid,tp,res) \
  2911. + beqz res, 1f; \
  2912. + s32i pid, tp, PID; \
  2913. +1:
  2914. +
  2915. +/*
  2916. + Special version for call12, where we don't have enough registers
  2917. + available to preserve the original PID.
  2918. + */
  2919. +#define RESTORE_PID12(ar, as, at) \
  2920. + rur as, threadptr; \
  2921. + movi ar, TLS_PRE_TCB_SIZE; \
  2922. + sub as, as, ar; \
  2923. + l32i ar, as, PID; \
  2924. + movi at, 0x80000000; \
  2925. + sub at, at, ar; \
  2926. + neg ar, ar; \
  2927. + moveqz ar, at, at; \
  2928. + s32i ar, as, PID;
  2929. +
  2930. +#include <libc/sysdeps/linux/xtensa/vfork.S>
  2931. diff -Nur uClibc-git/libpthread/nptl/sysdeps/xtensa/dl-tls.h uClibc-xtensa/libpthread/nptl/sysdeps/xtensa/dl-tls.h
  2932. --- uClibc-git/libpthread/nptl/sysdeps/xtensa/dl-tls.h 1970-01-01 01:00:00.000000000 +0100
  2933. +++ uClibc-xtensa/libpthread/nptl/sysdeps/xtensa/dl-tls.h 2014-06-03 12:04:16.669187814 +0200
  2934. @@ -0,0 +1,58 @@
  2935. +/* Thread-local storage handling in the ELF dynamic linker. Xtensa version.
  2936. + Copyright (C) 2013 Free Software Foundation, Inc.
  2937. + This file is part of the GNU C Library.
  2938. +
  2939. + The GNU C Library is free software; you can redistribute it and/or
  2940. + modify it under the terms of the GNU Lesser General Public
  2941. + License as published by the Free Software Foundation; either
  2942. + version 2.1 of the License, or (at your option) any later version.
  2943. +
  2944. + The GNU C Library is distributed in the hope that it will be useful,
  2945. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  2946. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2947. + Lesser General Public License for more details.
  2948. +
  2949. + You should have received a copy of the GNU Lesser General Public
  2950. + License along with the GNU C Library; if not, write to the Free
  2951. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  2952. + 02111-1307 USA. */
  2953. +
  2954. +#ifndef _XTENSA_DL_TLS_H
  2955. +#define _XTENSA_DL_TLS_H 1
  2956. +
  2957. +/* Type used for the representation of TLS information in the GOT. */
  2958. +typedef struct
  2959. +{
  2960. + unsigned long int ti_module;
  2961. + unsigned long int ti_offset;
  2962. +} tls_index;
  2963. +
  2964. +extern void *__tls_get_addr (tls_index *ti);
  2965. +
  2966. +/* Type used to represent a TLS descriptor. */
  2967. +struct tlsdesc
  2968. +{
  2969. + union
  2970. + {
  2971. + void *pointer;
  2972. + long value;
  2973. + } argument;
  2974. + ptrdiff_t (*entry)(struct tlsdesc *);
  2975. +};
  2976. +
  2977. +/* Type used as the argument in a TLS descriptor for a symbol that
  2978. + needs dynamic TLS offsets. */
  2979. +struct tlsdesc_dynamic_arg
  2980. +{
  2981. + tls_index tlsinfo;
  2982. + size_t gen_count;
  2983. +};
  2984. +
  2985. +extern ptrdiff_t attribute_hidden
  2986. + _dl_tlsdesc_return(struct tlsdesc_dynamic_arg *);
  2987. +
  2988. +extern void *_dl_make_tlsdesc_dynamic (struct link_map *map, size_t ti_offset);
  2989. +extern ptrdiff_t attribute_hidden
  2990. + _dl_tlsdesc_dynamic(struct tlsdesc_dynamic_arg *);
  2991. +
  2992. +#endif
  2993. diff -Nur uClibc-git/libpthread/nptl/sysdeps/xtensa/jmpbuf-unwind.h uClibc-xtensa/libpthread/nptl/sysdeps/xtensa/jmpbuf-unwind.h
  2994. --- uClibc-git/libpthread/nptl/sysdeps/xtensa/jmpbuf-unwind.h 1970-01-01 01:00:00.000000000 +0100
  2995. +++ uClibc-xtensa/libpthread/nptl/sysdeps/xtensa/jmpbuf-unwind.h 2014-06-03 12:04:16.669187814 +0200
  2996. @@ -0,0 +1,32 @@
  2997. +/* Copyright (C) 2005,2006 Free Software Foundation, Inc.
  2998. + This file is part of the GNU C Library.
  2999. +
  3000. + The GNU C Library is free software; you can redistribute it and/or
  3001. + modify it under the terms of the GNU Lesser General Public
  3002. + License as published by the Free Software Foundation; either
  3003. + version 2.1 of the License, or (at your option) any later version.
  3004. +
  3005. + The GNU C Library is distributed in the hope that it will be useful,
  3006. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  3007. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3008. + Lesser General Public License for more details.
  3009. +
  3010. + You should have received a copy of the GNU Lesser General Public
  3011. + License along with the GNU C Library; if not, see
  3012. + <http://www.gnu.org/licenses/>. */
  3013. +
  3014. +#include <setjmp.h>
  3015. +#include <stdint.h>
  3016. +#include <unwind.h>
  3017. +
  3018. +/* Test if longjmp to JMPBUF would unwind the frame
  3019. + containing a local variable at ADDRESS. */
  3020. +#undef _JMPBUF_UNWINDS
  3021. +#define _JMPBUF_UNWINDS(jmpbuf, address, demangle) \
  3022. + ((void *) (address) < (void *) demangle (jmpbuf[JB_SP]))
  3023. +
  3024. +#define _JMPBUF_CFA_UNWINDS_ADJ(_jmpbuf, _context, _adj) \
  3025. + _JMPBUF_UNWINDS_ADJ (_jmpbuf, (void *) _Unwind_GetCFA (_context), _adj)
  3026. +
  3027. +#define _JMPBUF_UNWINDS_ADJ(_jmpbuf, _address, _adj) \
  3028. + ((uintptr_t) (_address) - (_adj) < (uintptr_t) (_jmpbuf)[JB_SP] - (_adj))
  3029. diff -Nur uClibc-git/libpthread/nptl/sysdeps/xtensa/libc-tls.c uClibc-xtensa/libpthread/nptl/sysdeps/xtensa/libc-tls.c
  3030. --- uClibc-git/libpthread/nptl/sysdeps/xtensa/libc-tls.c 1970-01-01 01:00:00.000000000 +0100
  3031. +++ uClibc-xtensa/libpthread/nptl/sysdeps/xtensa/libc-tls.c 2014-06-03 12:04:16.669187814 +0200
  3032. @@ -0,0 +1,36 @@
  3033. +/* Thread-local storage handling in the ELF dynamic linker. Xtensa version.
  3034. + Copyright (C) 2005 Free Software Foundation, Inc.
  3035. + This file is part of the GNU C Library.
  3036. +
  3037. + The GNU C Library is free software; you can redistribute it and/or
  3038. + modify it under the terms of the GNU Lesser General Public
  3039. + License as published by the Free Software Foundation; either
  3040. + version 2.1 of the License, or (at your option) any later version.
  3041. +
  3042. + The GNU C Library is distributed in the hope that it will be useful,
  3043. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  3044. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3045. + Lesser General Public License for more details.
  3046. +
  3047. + You should have received a copy of the GNU Lesser General Public
  3048. + License along with the GNU C Library; if not, see
  3049. + <http://www.gnu.org/licenses/>. */
  3050. +
  3051. +#include <sysdeps/generic/libc-tls.c>
  3052. +#include <dl-tls.h>
  3053. +
  3054. +#if defined(USE_TLS) && USE_TLS
  3055. +
  3056. +/* On Xtensa, linker optimizations are not required, so __tls_get_addr
  3057. + can be called even in statically linked binaries. In this case module
  3058. + must be always 1 and PT_TLS segment exist in the binary, otherwise it
  3059. + would not link. */
  3060. +
  3061. +void *
  3062. +__tls_get_addr (tls_index *ti)
  3063. +{
  3064. + dtv_t *dtv = THREAD_DTV ();
  3065. + return (char *) dtv[1].pointer.val + ti->ti_offset;
  3066. +}
  3067. +
  3068. +#endif
  3069. diff -Nur uClibc-git/libpthread/nptl/sysdeps/xtensa/Makefile.arch uClibc-xtensa/libpthread/nptl/sysdeps/xtensa/Makefile.arch
  3070. --- uClibc-git/libpthread/nptl/sysdeps/xtensa/Makefile.arch 1970-01-01 01:00:00.000000000 +0100
  3071. +++ uClibc-xtensa/libpthread/nptl/sysdeps/xtensa/Makefile.arch 2014-06-03 12:04:16.669187814 +0200
  3072. @@ -0,0 +1,40 @@
  3073. +# Copyright (C) 2012 Free Software Foundation, Inc.
  3074. +# This file is part of the GNU C Library.
  3075. +#
  3076. +# The GNU C Library is free software; you can redistribute it and/or
  3077. +# modify it under the terms of the GNU Lesser General Public
  3078. +# License as published by the Free Software Foundation; either
  3079. +# version 2.1 of the License, or (at your option) any later version.
  3080. +#
  3081. +# The GNU C Library is distributed in the hope that it will be useful,
  3082. +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  3083. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3084. +# Lesser General Public License for more details.
  3085. +#
  3086. +# You should have received a copy of the GNU Lesser General Public
  3087. +# License along with the GNU C Library; if not, write to the Free
  3088. +# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  3089. +# 02111-1307 USA.
  3090. +
  3091. +CFLAGS-pt-raise.c = -DNOT_IN_libc -DIS_IN_libpthread
  3092. +
  3093. +ASFLAGS-dl-tlsdesc.S = -DNOT_IN_libc=1
  3094. +ASFLAGS-pthread_spin_lock.S = -DNOT_IN_libc -DIS_IN_libpthread
  3095. +ASFLAGS-pthread_spin_trylock.S = -DNOT_IN_libc -DIS_IN_libpthread
  3096. +ASFLAGS-nptl-sysdep.S = -DNOT_IN_libc -DIS_IN_libpthread \
  3097. + -D_LIBC_REENTRANT \
  3098. + -I$(top_srcdir)libc/sysdeps/linux/xtensa
  3099. +
  3100. +libc_arch_a_CSRC = libc-tls.c
  3101. +librt_arch_a_SSRC = dl-tlsdesc.S
  3102. +
  3103. +CFLAGS-gen_tlsdesc.c = -S
  3104. +$(libpthread_arch_OUT)/gen_tlsdesc.c: $(libpthread_arch_DIR)/tlsdesc.sym | $(libpthread_arch_OUT)
  3105. + $(do_awk) $(top_srcdir)extra/scripts/gen-as-const.awk $< > $@
  3106. +$(libpthread_arch_OUT)/gen_tlsdesc.s: $(libpthread_arch_OUT)/gen_tlsdesc.c | headers
  3107. + $(compile.c)
  3108. +libpthread-generated-y += $(libpthread_arch_OUT)/gen_tlsdesc.s
  3109. +$(libpthread_arch_OUT)/tlsdesc.h: $(libpthread_arch_OUT)/gen_tlsdesc.s
  3110. + $(do_sed) $(PTHREAD_GENERATE_MANGLE) $< > $@
  3111. + @if test ! -s $@ ; then rm -f $@ ; false ; fi
  3112. +pregen-headers-$(UCLIBC_HAS_THREADS_NATIVE) += $(libpthread_arch_OUT)/tlsdesc.h
  3113. diff -Nur uClibc-git/libpthread/nptl/sysdeps/xtensa/pthreaddef.h uClibc-xtensa/libpthread/nptl/sysdeps/xtensa/pthreaddef.h
  3114. --- uClibc-git/libpthread/nptl/sysdeps/xtensa/pthreaddef.h 1970-01-01 01:00:00.000000000 +0100
  3115. +++ uClibc-xtensa/libpthread/nptl/sysdeps/xtensa/pthreaddef.h 2014-06-03 12:04:16.669187814 +0200
  3116. @@ -0,0 +1,39 @@
  3117. +/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
  3118. + This file is part of the GNU C Library.
  3119. +
  3120. + The GNU C Library is free software; you can redistribute it and/or
  3121. + modify it under the terms of the GNU Lesser General Public
  3122. + License as published by the Free Software Foundation; either
  3123. + version 2.1 of the License, or (at your option) any later version.
  3124. +
  3125. + The GNU C Library is distributed in the hope that it will be useful,
  3126. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  3127. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3128. + Lesser General Public License for more details.
  3129. +
  3130. + You should have received a copy of the GNU Lesser General Public
  3131. + License along with the GNU C Library; if not, write to the Free
  3132. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  3133. + 02111-1307 USA. */
  3134. +
  3135. +/* Default stack size. */
  3136. +#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024)
  3137. +
  3138. +/* Required stack pointer alignment at beginning. */
  3139. +#define STACK_ALIGN 16
  3140. +
  3141. +/* Minimal stack size after allocating thread descriptor and guard size. */
  3142. +#define MINIMAL_REST_STACK 2048
  3143. +
  3144. +/* Alignment requirement for TCB. */
  3145. +#define TCB_ALIGNMENT 16
  3146. +
  3147. +
  3148. +/* Location of current stack frame. */
  3149. +#define CURRENT_STACK_FRAME __builtin_frame_address (0)
  3150. +
  3151. +
  3152. +/* XXX Until we have a better place keep the definitions here. */
  3153. +
  3154. +#define __exit_thread_inline(val) \
  3155. + INLINE_SYSCALL (exit, 1, (val))
  3156. diff -Nur uClibc-git/libpthread/nptl/sysdeps/xtensa/pthread_spin_lock.S uClibc-xtensa/libpthread/nptl/sysdeps/xtensa/pthread_spin_lock.S
  3157. --- uClibc-git/libpthread/nptl/sysdeps/xtensa/pthread_spin_lock.S 1970-01-01 01:00:00.000000000 +0100
  3158. +++ uClibc-xtensa/libpthread/nptl/sysdeps/xtensa/pthread_spin_lock.S 2014-06-03 12:04:16.669187814 +0200
  3159. @@ -0,0 +1,37 @@
  3160. +/* Copyright (C) 2012 Free Software Foundation, Inc.
  3161. + This file is part of the GNU C Library.
  3162. +
  3163. + The GNU C Library is free software; you can redistribute it and/or
  3164. + modify it under the terms of the GNU Lesser General Public
  3165. + License as published by the Free Software Foundation; either
  3166. + version 2.1 of the License, or (at your option) any later version.
  3167. +
  3168. + The GNU C Library is distributed in the hope that it will be useful,
  3169. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  3170. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3171. + Lesser General Public License for more details.
  3172. +
  3173. + You should have received a copy of the GNU Lesser General Public
  3174. + License along with the GNU C Library; if not, write to the Free
  3175. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  3176. + 02111-1307 USA. */
  3177. +
  3178. + .text
  3179. + .align 4
  3180. +
  3181. + .globl pthread_spin_lock
  3182. +pthread_spin_lock:
  3183. +
  3184. + entry a1, 16
  3185. +
  3186. + movi a3, 0
  3187. + wsr a3, scompare1
  3188. + movi a3, 1
  3189. +1: s32c1i a3, a2, 0
  3190. + bnez a3, 1b
  3191. + movi a2, 0
  3192. +
  3193. + retw
  3194. +
  3195. + .type pthread_spin_lock, @function
  3196. + .size pthread_spin_lock, .-pthread_spin_lock
  3197. diff -Nur uClibc-git/libpthread/nptl/sysdeps/xtensa/pthread_spin_trylock.S uClibc-xtensa/libpthread/nptl/sysdeps/xtensa/pthread_spin_trylock.S
  3198. --- uClibc-git/libpthread/nptl/sysdeps/xtensa/pthread_spin_trylock.S 1970-01-01 01:00:00.000000000 +0100
  3199. +++ uClibc-xtensa/libpthread/nptl/sysdeps/xtensa/pthread_spin_trylock.S 2014-06-03 12:04:16.669187814 +0200
  3200. @@ -0,0 +1,40 @@
  3201. +/* Copyright (C) 2005 Free Software Foundation, Inc.
  3202. + This file is part of the GNU C Library.
  3203. +
  3204. + The GNU C Library is free software; you can redistribute it and/or
  3205. + modify it under the terms of the GNU Lesser General Public
  3206. + License as published by the Free Software Foundation; either
  3207. + version 2.1 of the License, or (at your option) any later version.
  3208. +
  3209. + The GNU C Library is distributed in the hope that it will be useful,
  3210. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  3211. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3212. + Lesser General Public License for more details.
  3213. +
  3214. + You should have received a copy of the GNU Lesser General Public
  3215. + License along with the GNU C Library; if not, write to the Free
  3216. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  3217. + 02111-1307 USA. */
  3218. +
  3219. +#define _ERRNO_H 1
  3220. +#include <bits/errno.h>
  3221. +
  3222. + .text
  3223. + .align 4
  3224. +
  3225. + .globl pthread_spin_trylock
  3226. +pthread_spin_trylock:
  3227. +
  3228. + entry a1, 16
  3229. +
  3230. + movi a3, 0
  3231. + wsr a3, scompare1
  3232. + movi a3, 1
  3233. + s32c1i a3, a2, 0
  3234. + movi a2, EBUSY
  3235. + moveqz a2, a3, a3
  3236. +
  3237. + retw
  3238. +
  3239. + .type pthread_spin_trylock, @function
  3240. + .size pthread_spin_trylock, .-pthread_spin_trylock
  3241. diff -Nur uClibc-git/libpthread/nptl/sysdeps/xtensa/tcb-offsets.sym uClibc-xtensa/libpthread/nptl/sysdeps/xtensa/tcb-offsets.sym
  3242. --- uClibc-git/libpthread/nptl/sysdeps/xtensa/tcb-offsets.sym 1970-01-01 01:00:00.000000000 +0100
  3243. +++ uClibc-xtensa/libpthread/nptl/sysdeps/xtensa/tcb-offsets.sym 2014-06-03 12:04:16.669187814 +0200
  3244. @@ -0,0 +1,7 @@
  3245. +#include <sysdep.h>
  3246. +#include <tls.h>
  3247. +
  3248. +TLS_PRE_TCB_SIZE sizeof (struct pthread)
  3249. +MULTIPLE_THREADS_OFFSET offsetof (struct pthread, header.multiple_threads)
  3250. +PID offsetof (struct pthread, pid)
  3251. +TID offsetof (struct pthread, tid)
  3252. diff -Nur uClibc-git/libpthread/nptl/sysdeps/xtensa/tlsdesc.sym uClibc-xtensa/libpthread/nptl/sysdeps/xtensa/tlsdesc.sym
  3253. --- uClibc-git/libpthread/nptl/sysdeps/xtensa/tlsdesc.sym 1970-01-01 01:00:00.000000000 +0100
  3254. +++ uClibc-xtensa/libpthread/nptl/sysdeps/xtensa/tlsdesc.sym 2014-06-03 12:04:16.669187814 +0200
  3255. @@ -0,0 +1,10 @@
  3256. +#include <stddef.h>
  3257. +#include <sysdep.h>
  3258. +#include <tls.h>
  3259. +#include <link.h>
  3260. +#include <dl-tls.h>
  3261. +
  3262. +TLSDESC_ARG offsetof(struct tlsdesc, argument)
  3263. +TLSDESC_GEN_COUNT offsetof(struct tlsdesc_dynamic_arg, gen_count)
  3264. +TLSDESC_MODID offsetof(struct tlsdesc_dynamic_arg, tlsinfo.ti_module)
  3265. +TLSDESC_MODOFF offsetof(struct tlsdesc_dynamic_arg, tlsinfo.ti_offset)
  3266. diff -Nur uClibc-git/libpthread/nptl/sysdeps/xtensa/tls.h uClibc-xtensa/libpthread/nptl/sysdeps/xtensa/tls.h
  3267. --- uClibc-git/libpthread/nptl/sysdeps/xtensa/tls.h 1970-01-01 01:00:00.000000000 +0100
  3268. +++ uClibc-xtensa/libpthread/nptl/sysdeps/xtensa/tls.h 2014-06-03 12:04:16.669187814 +0200
  3269. @@ -0,0 +1,159 @@
  3270. +/* Definition for thread-local data handling. NPTL/Xtensa version.
  3271. + Copyright (C) 2012 Free Software Foundation, Inc.
  3272. + This file is part of the GNU C Library.
  3273. +
  3274. + The GNU C Library is free software; you can redistribute it and/or
  3275. + modify it under the terms of the GNU Lesser General Public
  3276. + License as published by the Free Software Foundation; either
  3277. + version 2.1 of the License, or (at your option) any later version.
  3278. +
  3279. + The GNU C Library is distributed in the hope that it will be useful,
  3280. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  3281. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3282. + Lesser General Public License for more details.
  3283. +
  3284. + You should have received a copy of the GNU Lesser General Public
  3285. + License along with the GNU C Library; if not, write to the Free
  3286. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  3287. + 02111-1307 USA. */
  3288. +
  3289. +#ifndef _TLS_H
  3290. +#define _TLS_H
  3291. +
  3292. +#ifndef __ASSEMBLER__
  3293. +
  3294. +# include <stdbool.h>
  3295. +# include <stddef.h>
  3296. +# include <stdint.h>
  3297. +
  3298. +/* Type for the dtv. */
  3299. +typedef union dtv
  3300. +{
  3301. + size_t counter;
  3302. + struct
  3303. + {
  3304. + void *val;
  3305. + bool is_static;
  3306. + } pointer;
  3307. +} dtv_t;
  3308. +
  3309. +
  3310. +#else /* __ASSEMBLER__ */
  3311. +# include <tcb-offsets.h>
  3312. +#endif /* __ASSEMBLER__ */
  3313. +
  3314. +/* We require TLS support in the tools. */
  3315. +#define HAVE_TLS_SUPPORT 1
  3316. +#define HAVE_TLS_MODEL_ATTRIBUTE 1
  3317. +#define HAVE___THREAD 1
  3318. +
  3319. +/* Signal that TLS support is available. */
  3320. +#define USE_TLS 1
  3321. +
  3322. +#ifndef __ASSEMBLER__
  3323. +
  3324. +/* Get system call information. */
  3325. +# include <sysdep.h>
  3326. +
  3327. +/* The TLS blocks start right after the TCB. */
  3328. +# define TLS_DTV_AT_TP 1
  3329. +
  3330. +/* Get the thread descriptor definition. */
  3331. +# include <../../descr.h>
  3332. +
  3333. +typedef struct
  3334. +{
  3335. + dtv_t *dtv;
  3336. + void *private;
  3337. +} tcbhead_t;
  3338. +
  3339. +/* This is the size of the initial TCB. */
  3340. +# define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
  3341. +
  3342. +/* Alignment requirements for the initial TCB. */
  3343. +# define TLS_INIT_TCB_ALIGN 16
  3344. +
  3345. +/* This is the size of the TCB. */
  3346. +# define TLS_TCB_SIZE sizeof (tcbhead_t)
  3347. +
  3348. +/* This is the size we need before TCB. */
  3349. +# define TLS_PRE_TCB_SIZE sizeof (struct pthread)
  3350. +
  3351. +/* Alignment requirements for the TCB. */
  3352. +# define TLS_TCB_ALIGN 16
  3353. +
  3354. +
  3355. +/* Install the dtv pointer. The pointer passed is to the element with
  3356. + index -1 which contain the length. */
  3357. +# define INSTALL_DTV(tcbp, dtvp) \
  3358. + (((tcbhead_t *) (tcbp))->dtv = (dtvp) + 1)
  3359. +
  3360. +/* Install new dtv for current thread. */
  3361. +# define INSTALL_NEW_DTV(dtv) \
  3362. + ({ tcbhead_t *__tcbp; \
  3363. + __asm__ __volatile__ ("rur %0, threadptr" : "=r" (__tcbp)); \
  3364. + __tcbp->dtv = (dtv); }) \
  3365. +
  3366. +/* Return dtv of given thread descriptor. */
  3367. +# define GET_DTV(tcbp) \
  3368. + (((tcbhead_t *) (tcbp))->dtv)
  3369. +
  3370. +/* Code to initially initialize the thread pointer. This might need
  3371. + special attention since 'errno' is not yet available and if the
  3372. + operation can cause a failure 'errno' must not be touched. */
  3373. +# define TLS_INIT_TP(tcbp, secondcall) \
  3374. + ({ __asm__ __volatile__ ("wur %0, threadptr" : : "r" (tcbp)); 0; })
  3375. +
  3376. +/* Return the address of the dtv for the current thread. */
  3377. +# define THREAD_DTV() \
  3378. + ({ tcbhead_t *__tcbp; \
  3379. + __asm__ __volatile__ ("rur %0, threadptr" : "=r" (__tcbp)); \
  3380. + __tcbp->dtv; })
  3381. +
  3382. +/* Return the thread descriptor for the current thread. */
  3383. +# define THREAD_SELF \
  3384. + ({ struct pthread *__self; \
  3385. + __asm__ ("rur %0, threadptr" : "=r" (__self)); \
  3386. + __self - 1; })
  3387. +
  3388. +/* Magic for libthread_db to know how to do THREAD_SELF. */
  3389. +# define DB_THREAD_SELF \
  3390. + CONST_THREAD_AREA (32, sizeof (struct pthread))
  3391. +
  3392. +/* Access to data in the thread descriptor is easy. */
  3393. +#define THREAD_GETMEM(descr, member) \
  3394. + descr->member
  3395. +#define THREAD_GETMEM_NC(descr, member, idx) \
  3396. + descr->member[idx]
  3397. +#define THREAD_SETMEM(descr, member, value) \
  3398. + descr->member = (value)
  3399. +#define THREAD_SETMEM_NC(descr, member, idx, value) \
  3400. + descr->member[idx] = (value)
  3401. +
  3402. +/* Get and set the global scope generation counter in struct pthread. */
  3403. +#define THREAD_GSCOPE_FLAG_UNUSED 0
  3404. +#define THREAD_GSCOPE_FLAG_USED 1
  3405. +#define THREAD_GSCOPE_FLAG_WAIT 2
  3406. +#define THREAD_GSCOPE_RESET_FLAG() \
  3407. + do \
  3408. + { int __res \
  3409. + = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag, \
  3410. + THREAD_GSCOPE_FLAG_UNUSED); \
  3411. + if (__res == THREAD_GSCOPE_FLAG_WAIT) \
  3412. + lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, LLL_PRIVATE); \
  3413. + } \
  3414. + while (0)
  3415. +#define THREAD_GSCOPE_SET_FLAG() \
  3416. + do \
  3417. + { \
  3418. + THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \
  3419. + atomic_write_barrier (); \
  3420. + } \
  3421. + while (0)
  3422. +
  3423. +#define THREAD_GSCOPE_WAIT() \
  3424. + GL(dl_wait_lookup_done) ()
  3425. +
  3426. +#endif /* __ASSEMBLER__ */
  3427. +
  3428. +#endif /* tls.h */