elf32.em 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504
  1. # This shell script emits a C file. -*- C -*-
  2. # It does some substitutions.
  3. # This file is now misnamed, because it supports both 32 bit and 64 bit
  4. # ELF emulations.
  5. test -z "${ELFSIZE}" && ELFSIZE=32
  6. if [ -z "$MACHINE" ]; then
  7. OUTPUT_ARCH=${ARCH}
  8. else
  9. OUTPUT_ARCH=${ARCH}:${MACHINE}
  10. fi
  11. fragment <<EOF
  12. /* This file is is generated by a shell script. DO NOT EDIT! */
  13. /* ${ELFSIZE} bit ELF emulation code for ${EMULATION_NAME}
  14. Copyright (C) 1991-2015 Free Software Foundation, Inc.
  15. Written by Steve Chamberlain <sac@cygnus.com>
  16. ELF support by Ian Lance Taylor <ian@cygnus.com>
  17. This file is part of the GNU Binutils.
  18. This program is free software; you can redistribute it and/or modify
  19. it under the terms of the GNU General Public License as published by
  20. the Free Software Foundation; either version 3 of the License, or
  21. (at your option) any later version.
  22. This program is distributed in the hope that it will be useful,
  23. but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. GNU General Public License for more details.
  26. You should have received a copy of the GNU General Public License
  27. along with this program; if not, write to the Free Software
  28. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  29. MA 02110-1301, USA. */
  30. #define TARGET_IS_${EMULATION_NAME}
  31. #include "sysdep.h"
  32. #include "bfd.h"
  33. #include "libiberty.h"
  34. #include "safe-ctype.h"
  35. #include "filenames.h"
  36. #include "getopt.h"
  37. #include <fcntl.h>
  38. #include "bfdlink.h"
  39. #include "ld.h"
  40. #include "ldmain.h"
  41. #include "ldmisc.h"
  42. #include "ldexp.h"
  43. #include "ldlang.h"
  44. #include "ldfile.h"
  45. #include "ldemul.h"
  46. #include "ldbuildid.h"
  47. #include <ldgram.h>
  48. #include "elf/common.h"
  49. #include "elf-bfd.h"
  50. #include "filenames.h"
  51. /* Declare functions used by various EXTRA_EM_FILEs. */
  52. static void gld${EMULATION_NAME}_before_parse (void);
  53. static void gld${EMULATION_NAME}_after_parse (void);
  54. static void gld${EMULATION_NAME}_after_open (void);
  55. static void gld${EMULATION_NAME}_before_allocation (void);
  56. static void gld${EMULATION_NAME}_after_allocation (void);
  57. static lang_output_section_statement_type *gld${EMULATION_NAME}_place_orphan
  58. (asection *, const char *, int);
  59. EOF
  60. if [ "x${USE_LIBPATH}" = xyes ] ; then
  61. case ${target} in
  62. *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
  63. fragment <<EOF
  64. #ifdef HAVE_GLOB
  65. #include <glob.h>
  66. #endif
  67. EOF
  68. ;;
  69. esac
  70. fi
  71. # Import any needed special functions and/or overrides.
  72. #
  73. source_em ${srcdir}/emultempl/elf-generic.em
  74. if test -n "$EXTRA_EM_FILE" ; then
  75. source_em ${srcdir}/emultempl/${EXTRA_EM_FILE}.em
  76. fi
  77. # Functions in this file can be overridden by setting the LDEMUL_* shell
  78. # variables. If the name of the overriding function is the same as is
  79. # defined in this file, then don't output this file's version.
  80. # If a different overriding name is given then output the standard function
  81. # as presumably it is called from the overriding function.
  82. #
  83. if test x"$LDEMUL_BEFORE_PARSE" != xgld"$EMULATION_NAME"_before_parse; then
  84. fragment <<EOF
  85. static void
  86. gld${EMULATION_NAME}_before_parse (void)
  87. {
  88. ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
  89. input_flags.dynamic = ${DYNAMIC_LINK-TRUE};
  90. config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`;
  91. config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`;
  92. }
  93. EOF
  94. fi
  95. if test x"$LDEMUL_AFTER_PARSE" != xgld"$EMULATION_NAME"_after_parse; then
  96. fragment <<EOF
  97. static void
  98. gld${EMULATION_NAME}_after_parse (void)
  99. {
  100. if (bfd_link_pie (&link_info))
  101. link_info.flags_1 |= (bfd_vma) DF_1_PIE;
  102. after_parse_default ();
  103. }
  104. EOF
  105. fi
  106. if test x"$LDEMUL_RECOGNIZED_FILE" != xgld"${EMULATION_NAME}"_load_symbols; then
  107. fragment <<EOF
  108. /* Handle the generation of DT_NEEDED tags. */
  109. static bfd_boolean
  110. gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *entry)
  111. {
  112. int link_class = 0;
  113. /* Tell the ELF linker that we don't want the output file to have a
  114. DT_NEEDED entry for this file, unless it is used to resolve
  115. references in a regular object. */
  116. if (entry->flags.add_DT_NEEDED_for_regular)
  117. link_class = DYN_AS_NEEDED;
  118. /* Tell the ELF linker that we don't want the output file to have a
  119. DT_NEEDED entry for any dynamic library in DT_NEEDED tags from
  120. this file at all. */
  121. if (!entry->flags.add_DT_NEEDED_for_dynamic)
  122. link_class |= DYN_NO_ADD_NEEDED;
  123. if (entry->flags.just_syms
  124. && (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) != 0)
  125. einfo (_("%P%F: --just-symbols may not be used on DSO: %B\n"),
  126. entry->the_bfd);
  127. if (link_class == 0
  128. || (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) == 0)
  129. return FALSE;
  130. bfd_elf_set_dyn_lib_class (entry->the_bfd,
  131. (enum dynamic_lib_link_class) link_class);
  132. /* Continue on with normal load_symbols processing. */
  133. return FALSE;
  134. }
  135. EOF
  136. fi
  137. fragment <<EOF
  138. /* These variables are required to pass information back and forth
  139. between after_open and check_needed and stat_needed and vercheck. */
  140. static struct bfd_link_needed_list *global_needed;
  141. static struct stat global_stat;
  142. static lang_input_statement_type *global_found;
  143. static struct bfd_link_needed_list *global_vercheck_needed;
  144. static bfd_boolean global_vercheck_failed;
  145. /* These variables are used to implement target options */
  146. static char *audit; /* colon (typically) separated list of libs */
  147. static char *depaudit; /* colon (typically) separated list of libs */
  148. /* Style of .note.gnu.build-id section. */
  149. static const char *emit_note_gnu_build_id;
  150. /* On Linux, it's possible to have different versions of the same
  151. shared library linked against different versions of libc. The
  152. dynamic linker somehow tags which libc version to use in
  153. /etc/ld.so.cache, and, based on the libc that it sees in the
  154. executable, chooses which version of the shared library to use.
  155. We try to do a similar check here by checking whether this shared
  156. library needs any other shared libraries which may conflict with
  157. libraries we have already included in the link. If it does, we
  158. skip it, and try to find another shared library farther on down the
  159. link path.
  160. This is called via lang_for_each_input_file.
  161. GLOBAL_VERCHECK_NEEDED is the list of objects needed by the object
  162. which we are checking. This sets GLOBAL_VERCHECK_FAILED if we find
  163. a conflicting version. */
  164. static void
  165. gld${EMULATION_NAME}_vercheck (lang_input_statement_type *s)
  166. {
  167. const char *soname;
  168. struct bfd_link_needed_list *l;
  169. if (global_vercheck_failed)
  170. return;
  171. if (s->the_bfd == NULL
  172. || (bfd_get_file_flags (s->the_bfd) & DYNAMIC) == 0)
  173. return;
  174. soname = bfd_elf_get_dt_soname (s->the_bfd);
  175. if (soname == NULL)
  176. soname = lbasename (bfd_get_filename (s->the_bfd));
  177. for (l = global_vercheck_needed; l != NULL; l = l->next)
  178. {
  179. const char *suffix;
  180. if (filename_cmp (soname, l->name) == 0)
  181. {
  182. /* Probably can't happen, but it's an easy check. */
  183. continue;
  184. }
  185. if (strchr (l->name, '/') != NULL)
  186. continue;
  187. suffix = strstr (l->name, ".so.");
  188. if (suffix == NULL)
  189. continue;
  190. suffix += sizeof ".so." - 1;
  191. if (filename_ncmp (soname, l->name, suffix - l->name) == 0)
  192. {
  193. /* Here we know that S is a dynamic object FOO.SO.VER1, and
  194. the object we are considering needs a dynamic object
  195. FOO.SO.VER2, and VER1 and VER2 are different. This
  196. appears to be a version mismatch, so we tell the caller
  197. to try a different version of this library. */
  198. global_vercheck_failed = TRUE;
  199. return;
  200. }
  201. }
  202. }
  203. /* See if an input file matches a DT_NEEDED entry by running stat on
  204. the file. */
  205. static void
  206. gld${EMULATION_NAME}_stat_needed (lang_input_statement_type *s)
  207. {
  208. struct stat st;
  209. const char *suffix;
  210. const char *soname;
  211. if (global_found != NULL)
  212. return;
  213. if (s->the_bfd == NULL)
  214. return;
  215. /* If this input file was an as-needed entry, and wasn't found to be
  216. needed at the stage it was linked, then don't say we have loaded it. */
  217. if ((bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0)
  218. return;
  219. if (bfd_stat (s->the_bfd, &st) != 0)
  220. {
  221. einfo ("%P:%B: bfd_stat failed: %E\n", s->the_bfd);
  222. return;
  223. }
  224. /* Some operating systems, e.g. Windows, do not provide a meaningful
  225. st_ino; they always set it to zero. (Windows does provide a
  226. meaningful st_dev.) Do not indicate a duplicate library in that
  227. case. While there is no guarantee that a system that provides
  228. meaningful inode numbers will never set st_ino to zero, this is
  229. merely an optimization, so we do not need to worry about false
  230. negatives. */
  231. if (st.st_dev == global_stat.st_dev
  232. && st.st_ino == global_stat.st_ino
  233. && st.st_ino != 0)
  234. {
  235. global_found = s;
  236. return;
  237. }
  238. /* We issue a warning if it looks like we are including two
  239. different versions of the same shared library. For example,
  240. there may be a problem if -lc picks up libc.so.6 but some other
  241. shared library has a DT_NEEDED entry of libc.so.5. This is a
  242. heuristic test, and it will only work if the name looks like
  243. NAME.so.VERSION. FIXME: Depending on file names is error-prone.
  244. If we really want to issue warnings about mixing version numbers
  245. of shared libraries, we need to find a better way. */
  246. if (strchr (global_needed->name, '/') != NULL)
  247. return;
  248. suffix = strstr (global_needed->name, ".so.");
  249. if (suffix == NULL)
  250. return;
  251. suffix += sizeof ".so." - 1;
  252. soname = bfd_elf_get_dt_soname (s->the_bfd);
  253. if (soname == NULL)
  254. soname = lbasename (s->filename);
  255. if (filename_ncmp (soname, global_needed->name, suffix - global_needed->name) == 0)
  256. einfo ("%P: warning: %s, needed by %B, may conflict with %s\n",
  257. global_needed->name, global_needed->by, soname);
  258. }
  259. struct dt_needed
  260. {
  261. bfd *by;
  262. const char *name;
  263. };
  264. /* This function is called for each possible name for a dynamic object
  265. named by a DT_NEEDED entry. The FORCE parameter indicates whether
  266. to skip the check for a conflicting version. */
  267. static bfd_boolean
  268. gld${EMULATION_NAME}_try_needed (struct dt_needed *needed,
  269. int force)
  270. {
  271. bfd *abfd;
  272. const char *name = needed->name;
  273. const char *soname;
  274. int link_class;
  275. abfd = bfd_openr (name, bfd_get_target (link_info.output_bfd));
  276. if (abfd == NULL)
  277. return FALSE;
  278. /* Linker needs to decompress sections. */
  279. abfd->flags |= BFD_DECOMPRESS;
  280. if (! bfd_check_format (abfd, bfd_object))
  281. {
  282. bfd_close (abfd);
  283. return FALSE;
  284. }
  285. if ((bfd_get_file_flags (abfd) & DYNAMIC) == 0)
  286. {
  287. bfd_close (abfd);
  288. return FALSE;
  289. }
  290. /* For DT_NEEDED, they have to match. */
  291. if (abfd->xvec != link_info.output_bfd->xvec)
  292. {
  293. bfd_close (abfd);
  294. return FALSE;
  295. }
  296. /* Check whether this object would include any conflicting library
  297. versions. If FORCE is set, then we skip this check; we use this
  298. the second time around, if we couldn't find any compatible
  299. instance of the shared library. */
  300. if (! force)
  301. {
  302. struct bfd_link_needed_list *needs;
  303. if (! bfd_elf_get_bfd_needed_list (abfd, &needs))
  304. einfo ("%F%P:%B: bfd_elf_get_bfd_needed_list failed: %E\n", abfd);
  305. if (needs != NULL)
  306. {
  307. global_vercheck_needed = needs;
  308. global_vercheck_failed = FALSE;
  309. lang_for_each_input_file (gld${EMULATION_NAME}_vercheck);
  310. if (global_vercheck_failed)
  311. {
  312. bfd_close (abfd);
  313. /* Return FALSE to force the caller to move on to try
  314. another file on the search path. */
  315. return FALSE;
  316. }
  317. /* But wait! It gets much worse. On Linux, if a shared
  318. library does not use libc at all, we are supposed to skip
  319. it the first time around in case we encounter a shared
  320. library later on with the same name which does use the
  321. version of libc that we want. This is much too horrible
  322. to use on any system other than Linux. */
  323. EOF
  324. case ${target} in
  325. *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
  326. fragment <<EOF
  327. {
  328. struct bfd_link_needed_list *l;
  329. for (l = needs; l != NULL; l = l->next)
  330. if (CONST_STRNEQ (l->name, "libc.so"))
  331. break;
  332. if (l == NULL)
  333. {
  334. bfd_close (abfd);
  335. return FALSE;
  336. }
  337. }
  338. EOF
  339. ;;
  340. esac
  341. fragment <<EOF
  342. }
  343. }
  344. /* We've found a dynamic object matching the DT_NEEDED entry. */
  345. /* We have already checked that there is no other input file of the
  346. same name. We must now check again that we are not including the
  347. same file twice. We need to do this because on many systems
  348. libc.so is a symlink to, e.g., libc.so.1. The SONAME entry will
  349. reference libc.so.1. If we have already included libc.so, we
  350. don't want to include libc.so.1 if they are the same file, and we
  351. can only check that using stat. */
  352. if (bfd_stat (abfd, &global_stat) != 0)
  353. einfo ("%F%P:%B: bfd_stat failed: %E\n", abfd);
  354. /* First strip off everything before the last '/'. */
  355. soname = lbasename (abfd->filename);
  356. if (verbose)
  357. info_msg (_("found %s at %s\n"), soname, name);
  358. global_found = NULL;
  359. lang_for_each_input_file (gld${EMULATION_NAME}_stat_needed);
  360. if (global_found != NULL)
  361. {
  362. /* Return TRUE to indicate that we found the file, even though
  363. we aren't going to do anything with it. */
  364. return TRUE;
  365. }
  366. /* Specify the soname to use. */
  367. bfd_elf_set_dt_needed_name (abfd, soname);
  368. /* Tell the ELF linker that we don't want the output file to have a
  369. DT_NEEDED entry for this file, unless it is used to resolve
  370. references in a regular object. */
  371. link_class = DYN_DT_NEEDED;
  372. /* Tell the ELF linker that we don't want the output file to have a
  373. DT_NEEDED entry for this file at all if the entry is from a file
  374. with DYN_NO_ADD_NEEDED. */
  375. if (needed->by != NULL
  376. && (bfd_elf_get_dyn_lib_class (needed->by) & DYN_NO_ADD_NEEDED) != 0)
  377. link_class |= DYN_NO_NEEDED | DYN_NO_ADD_NEEDED;
  378. bfd_elf_set_dyn_lib_class (abfd, (enum dynamic_lib_link_class) link_class);
  379. /* Add this file into the symbol table. */
  380. if (! bfd_link_add_symbols (abfd, &link_info))
  381. einfo ("%F%B: error adding symbols: %E\n", abfd);
  382. return TRUE;
  383. }
  384. /* Search for a needed file in a path. */
  385. static bfd_boolean
  386. gld${EMULATION_NAME}_search_needed (const char *path,
  387. struct dt_needed *n, int force)
  388. {
  389. const char *s;
  390. const char *name = n->name;
  391. size_t len;
  392. struct dt_needed needed;
  393. if (name[0] == '/')
  394. return gld${EMULATION_NAME}_try_needed (n, force);
  395. if (path == NULL || *path == '\0')
  396. return FALSE;
  397. needed.by = n->by;
  398. needed.name = n->name;
  399. len = strlen (name);
  400. while (1)
  401. {
  402. char *filename, *sset;
  403. s = strchr (path, config.rpath_separator);
  404. if (s == NULL)
  405. s = path + strlen (path);
  406. #if HAVE_DOS_BASED_FILE_SYSTEM
  407. /* Assume a match on the second char is part of drive specifier. */
  408. else if (config.rpath_separator == ':'
  409. && s == path + 1
  410. && ISALPHA (*path))
  411. {
  412. s = strchr (s + 1, config.rpath_separator);
  413. if (s == NULL)
  414. s = path + strlen (path);
  415. }
  416. #endif
  417. filename = (char *) xmalloc (s - path + len + 2);
  418. if (s == path)
  419. sset = filename;
  420. else
  421. {
  422. memcpy (filename, path, s - path);
  423. filename[s - path] = '/';
  424. sset = filename + (s - path) + 1;
  425. }
  426. strcpy (sset, name);
  427. needed.name = filename;
  428. if (gld${EMULATION_NAME}_try_needed (&needed, force))
  429. return TRUE;
  430. free (filename);
  431. if (*s == '\0')
  432. break;
  433. path = s + 1;
  434. }
  435. return FALSE;
  436. }
  437. EOF
  438. if [ "x${USE_LIBPATH}" = xyes ] ; then
  439. fragment <<EOF
  440. /* Add the sysroot to every entry in a path separated by
  441. config.rpath_separator. */
  442. static char *
  443. gld${EMULATION_NAME}_add_sysroot (const char *path)
  444. {
  445. int len, colons, i;
  446. char *ret, *p;
  447. len = strlen (path);
  448. colons = 0;
  449. i = 0;
  450. while (path[i])
  451. if (path[i++] == config.rpath_separator)
  452. colons++;
  453. if (path[i])
  454. colons++;
  455. len = len + (colons + 1) * strlen (ld_sysroot);
  456. ret = xmalloc (len + 1);
  457. strcpy (ret, ld_sysroot);
  458. p = ret + strlen (ret);
  459. i = 0;
  460. while (path[i])
  461. if (path[i] == config.rpath_separator)
  462. {
  463. *p++ = path[i++];
  464. strcpy (p, ld_sysroot);
  465. p = p + strlen (p);
  466. }
  467. else
  468. *p++ = path[i++];
  469. *p = 0;
  470. return ret;
  471. }
  472. EOF
  473. case ${target} in
  474. *-*-freebsd* | *-*-dragonfly*)
  475. fragment <<EOF
  476. /* Read the system search path the FreeBSD way rather than the Linux way. */
  477. #ifdef HAVE_ELF_HINTS_H
  478. #include <elf-hints.h>
  479. #else
  480. #include "elf-hints-local.h"
  481. #endif
  482. static bfd_boolean
  483. gld${EMULATION_NAME}_check_ld_elf_hints (const struct bfd_link_needed_list *l,
  484. int force)
  485. {
  486. static bfd_boolean initialized;
  487. static char *ld_elf_hints;
  488. struct dt_needed needed;
  489. if (!initialized)
  490. {
  491. FILE *f;
  492. char *tmppath;
  493. tmppath = concat (ld_sysroot, _PATH_ELF_HINTS, (const char *) NULL);
  494. f = fopen (tmppath, FOPEN_RB);
  495. free (tmppath);
  496. if (f != NULL)
  497. {
  498. struct elfhints_hdr hdr;
  499. if (fread (&hdr, 1, sizeof (hdr), f) == sizeof (hdr)
  500. && hdr.magic == ELFHINTS_MAGIC
  501. && hdr.version == 1)
  502. {
  503. if (fseek (f, hdr.strtab + hdr.dirlist, SEEK_SET) != -1)
  504. {
  505. char *b;
  506. b = xmalloc (hdr.dirlistlen + 1);
  507. if (fread (b, 1, hdr.dirlistlen + 1, f) ==
  508. hdr.dirlistlen + 1)
  509. ld_elf_hints = gld${EMULATION_NAME}_add_sysroot (b);
  510. free (b);
  511. }
  512. }
  513. fclose (f);
  514. }
  515. initialized = TRUE;
  516. }
  517. if (ld_elf_hints == NULL)
  518. return FALSE;
  519. needed.by = l->by;
  520. needed.name = l->name;
  521. return gld${EMULATION_NAME}_search_needed (ld_elf_hints, &needed, force);
  522. }
  523. EOF
  524. # FreeBSD
  525. ;;
  526. *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
  527. fragment <<EOF
  528. /* For a native linker, check the file /etc/ld.so.conf for directories
  529. in which we may find shared libraries. /etc/ld.so.conf is really
  530. only meaningful on Linux. */
  531. struct gld${EMULATION_NAME}_ld_so_conf
  532. {
  533. char *path;
  534. size_t len, alloc;
  535. };
  536. static bfd_boolean
  537. gld${EMULATION_NAME}_parse_ld_so_conf
  538. (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename);
  539. static void
  540. gld${EMULATION_NAME}_parse_ld_so_conf_include
  541. (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename,
  542. const char *pattern)
  543. {
  544. char *newp = NULL;
  545. #ifdef HAVE_GLOB
  546. glob_t gl;
  547. #endif
  548. if (pattern[0] != '/')
  549. {
  550. char *p = strrchr (filename, '/');
  551. size_t patlen = strlen (pattern) + 1;
  552. newp = xmalloc (p - filename + 1 + patlen);
  553. memcpy (newp, filename, p - filename + 1);
  554. memcpy (newp + (p - filename + 1), pattern, patlen);
  555. pattern = newp;
  556. }
  557. #ifdef HAVE_GLOB
  558. if (glob (pattern, 0, NULL, &gl) == 0)
  559. {
  560. size_t i;
  561. for (i = 0; i < gl.gl_pathc; ++i)
  562. gld${EMULATION_NAME}_parse_ld_so_conf (info, gl.gl_pathv[i]);
  563. globfree (&gl);
  564. }
  565. #else
  566. /* If we do not have glob, treat the pattern as a literal filename. */
  567. gld${EMULATION_NAME}_parse_ld_so_conf (info, pattern);
  568. #endif
  569. if (newp)
  570. free (newp);
  571. }
  572. static bfd_boolean
  573. gld${EMULATION_NAME}_parse_ld_so_conf
  574. (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename)
  575. {
  576. FILE *f = fopen (filename, FOPEN_RT);
  577. char *line;
  578. size_t linelen;
  579. if (f == NULL)
  580. return FALSE;
  581. linelen = 256;
  582. line = xmalloc (linelen);
  583. do
  584. {
  585. char *p = line, *q;
  586. /* Normally this would use getline(3), but we need to be portable. */
  587. while ((q = fgets (p, linelen - (p - line), f)) != NULL
  588. && strlen (q) == linelen - (p - line) - 1
  589. && line[linelen - 2] != '\n')
  590. {
  591. line = xrealloc (line, 2 * linelen);
  592. p = line + linelen - 1;
  593. linelen += linelen;
  594. }
  595. if (q == NULL && p == line)
  596. break;
  597. p = strchr (line, '\n');
  598. if (p)
  599. *p = '\0';
  600. /* Because the file format does not know any form of quoting we
  601. can search forward for the next '#' character and if found
  602. make it terminating the line. */
  603. p = strchr (line, '#');
  604. if (p)
  605. *p = '\0';
  606. /* Remove leading whitespace. NUL is no whitespace character. */
  607. p = line;
  608. while (*p == ' ' || *p == '\f' || *p == '\r' || *p == '\t' || *p == '\v')
  609. ++p;
  610. /* If the line is blank it is ignored. */
  611. if (p[0] == '\0')
  612. continue;
  613. if (CONST_STRNEQ (p, "include") && (p[7] == ' ' || p[7] == '\t'))
  614. {
  615. char *dir, c;
  616. p += 8;
  617. do
  618. {
  619. while (*p == ' ' || *p == '\t')
  620. ++p;
  621. if (*p == '\0')
  622. break;
  623. dir = p;
  624. while (*p != ' ' && *p != '\t' && *p)
  625. ++p;
  626. c = *p;
  627. *p++ = '\0';
  628. if (dir[0] != '\0')
  629. gld${EMULATION_NAME}_parse_ld_so_conf_include (info, filename,
  630. dir);
  631. }
  632. while (c != '\0');
  633. }
  634. else
  635. {
  636. char *dir = p;
  637. while (*p && *p != '=' && *p != ' ' && *p != '\t' && *p != '\f'
  638. && *p != '\r' && *p != '\v')
  639. ++p;
  640. while (p != dir && p[-1] == '/')
  641. --p;
  642. if (info->path == NULL)
  643. {
  644. info->alloc = p - dir + 1 + 256;
  645. info->path = xmalloc (info->alloc);
  646. info->len = 0;
  647. }
  648. else
  649. {
  650. if (info->len + 1 + (p - dir) >= info->alloc)
  651. {
  652. info->alloc += p - dir + 256;
  653. info->path = xrealloc (info->path, info->alloc);
  654. }
  655. info->path[info->len++] = config.rpath_separator;
  656. }
  657. memcpy (info->path + info->len, dir, p - dir);
  658. info->len += p - dir;
  659. info->path[info->len] = '\0';
  660. }
  661. }
  662. while (! feof (f));
  663. free (line);
  664. fclose (f);
  665. return TRUE;
  666. }
  667. static bfd_boolean
  668. gld${EMULATION_NAME}_check_ld_so_conf (const struct bfd_link_needed_list *l,
  669. int force)
  670. {
  671. static bfd_boolean initialized;
  672. static char *ld_so_conf;
  673. struct dt_needed needed;
  674. if (! initialized)
  675. {
  676. char *tmppath;
  677. struct gld${EMULATION_NAME}_ld_so_conf info;
  678. info.path = NULL;
  679. info.len = info.alloc = 0;
  680. tmppath = concat (ld_sysroot, "${prefix}/etc/ld.so.conf",
  681. (const char *) NULL);
  682. if (!gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath))
  683. {
  684. free (tmppath);
  685. tmppath = concat (ld_sysroot, "/etc/ld.so.conf",
  686. (const char *) NULL);
  687. gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath);
  688. }
  689. free (tmppath);
  690. if (info.path)
  691. {
  692. char *d = gld${EMULATION_NAME}_add_sysroot (info.path);
  693. free (info.path);
  694. ld_so_conf = d;
  695. }
  696. initialized = TRUE;
  697. }
  698. if (ld_so_conf == NULL)
  699. return FALSE;
  700. needed.by = l->by;
  701. needed.name = l->name;
  702. return gld${EMULATION_NAME}_search_needed (ld_so_conf, &needed, force);
  703. }
  704. EOF
  705. # Linux
  706. ;;
  707. esac
  708. fi
  709. fragment <<EOF
  710. /* See if an input file matches a DT_NEEDED entry by name. */
  711. static void
  712. gld${EMULATION_NAME}_check_needed (lang_input_statement_type *s)
  713. {
  714. const char *soname;
  715. /* Stop looking if we've found a loaded lib. */
  716. if (global_found != NULL
  717. && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
  718. & DYN_AS_NEEDED) == 0)
  719. return;
  720. if (s->filename == NULL || s->the_bfd == NULL)
  721. return;
  722. /* Don't look for a second non-loaded as-needed lib. */
  723. if (global_found != NULL
  724. && (bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0)
  725. return;
  726. if (filename_cmp (s->filename, global_needed->name) == 0)
  727. {
  728. global_found = s;
  729. return;
  730. }
  731. if (s->flags.search_dirs)
  732. {
  733. const char *f = strrchr (s->filename, '/');
  734. if (f != NULL
  735. && filename_cmp (f + 1, global_needed->name) == 0)
  736. {
  737. global_found = s;
  738. return;
  739. }
  740. }
  741. soname = bfd_elf_get_dt_soname (s->the_bfd);
  742. if (soname != NULL
  743. && filename_cmp (soname, global_needed->name) == 0)
  744. {
  745. global_found = s;
  746. return;
  747. }
  748. }
  749. EOF
  750. if test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; then
  751. fragment <<EOF
  752. static bfd_size_type
  753. id_note_section_size (bfd *abfd ATTRIBUTE_UNUSED)
  754. {
  755. const char *style = emit_note_gnu_build_id;
  756. bfd_size_type size;
  757. bfd_size_type build_id_size;
  758. size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
  759. size = (size + 3) & -(bfd_size_type) 4;
  760. build_id_size = compute_build_id_size (style);
  761. if (build_id_size)
  762. size += build_id_size;
  763. else
  764. size = 0;
  765. return size;
  766. }
  767. static bfd_boolean
  768. write_build_id (bfd *abfd)
  769. {
  770. const struct elf_backend_data *bed = get_elf_backend_data (abfd);
  771. struct elf_obj_tdata *t = elf_tdata (abfd);
  772. const char *style;
  773. asection *asec;
  774. Elf_Internal_Shdr *i_shdr;
  775. unsigned char *contents, *id_bits;
  776. bfd_size_type size;
  777. file_ptr position;
  778. Elf_External_Note *e_note;
  779. style = t->o->build_id.style;
  780. asec = t->o->build_id.sec;
  781. if (bfd_is_abs_section (asec->output_section))
  782. {
  783. einfo (_("%P: warning: .note.gnu.build-id section discarded,"
  784. " --build-id ignored.\n"));
  785. return TRUE;
  786. }
  787. i_shdr = &elf_section_data (asec->output_section)->this_hdr;
  788. if (i_shdr->contents == NULL)
  789. {
  790. if (asec->contents == NULL)
  791. asec->contents = (unsigned char *) xmalloc (asec->size);
  792. contents = asec->contents;
  793. }
  794. else
  795. contents = i_shdr->contents + asec->output_offset;
  796. e_note = (Elf_External_Note *) contents;
  797. size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
  798. size = (size + 3) & -(bfd_size_type) 4;
  799. id_bits = contents + size;
  800. size = asec->size - size;
  801. bfd_h_put_32 (abfd, sizeof "GNU", &e_note->namesz);
  802. bfd_h_put_32 (abfd, size, &e_note->descsz);
  803. bfd_h_put_32 (abfd, NT_GNU_BUILD_ID, &e_note->type);
  804. memcpy (e_note->name, "GNU", sizeof "GNU");
  805. generate_build_id (abfd, style, bed->s->checksum_contents, id_bits, size);
  806. position = i_shdr->sh_offset + asec->output_offset;
  807. size = asec->size;
  808. return (bfd_seek (abfd, position, SEEK_SET) == 0
  809. && bfd_bwrite (contents, size, abfd) == size);
  810. }
  811. /* Make .note.gnu.build-id section, and set up elf_tdata->build_id. */
  812. static bfd_boolean
  813. setup_build_id (bfd *ibfd)
  814. {
  815. asection *s;
  816. bfd_size_type size;
  817. flagword flags;
  818. size = id_note_section_size (ibfd);
  819. if (size == 0)
  820. {
  821. einfo ("%P: warning: unrecognized --build-id style ignored.\n");
  822. return FALSE;
  823. }
  824. flags = (SEC_ALLOC | SEC_LOAD | SEC_IN_MEMORY
  825. | SEC_LINKER_CREATED | SEC_READONLY | SEC_DATA);
  826. s = bfd_make_section_with_flags (ibfd, ".note.gnu.build-id", flags);
  827. if (s != NULL && bfd_set_section_alignment (ibfd, s, 2))
  828. {
  829. struct elf_obj_tdata *t = elf_tdata (link_info.output_bfd);
  830. t->o->build_id.after_write_object_contents = &write_build_id;
  831. t->o->build_id.style = emit_note_gnu_build_id;
  832. t->o->build_id.sec = s;
  833. elf_section_type (s) = SHT_NOTE;
  834. s->size = size;
  835. return TRUE;
  836. }
  837. einfo ("%P: warning: Cannot create .note.gnu.build-id section,"
  838. " --build-id ignored.\n");
  839. return FALSE;
  840. }
  841. /* This is called after all the input files have been opened. */
  842. static void
  843. gld${EMULATION_NAME}_after_open (void)
  844. {
  845. struct bfd_link_needed_list *needed, *l;
  846. struct elf_link_hash_table *htab;
  847. after_open_default ();
  848. htab = elf_hash_table (&link_info);
  849. if (!is_elf_hash_table (htab))
  850. return;
  851. if (emit_note_gnu_build_id != NULL)
  852. {
  853. bfd *abfd;
  854. /* Find an ELF input. */
  855. for (abfd = link_info.input_bfds;
  856. abfd != (bfd *) NULL; abfd = abfd->link.next)
  857. if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
  858. && bfd_count_sections (abfd) != 0)
  859. break;
  860. /* PR 10555: If there are no ELF input files do not try to
  861. create a .note.gnu-build-id section. */
  862. if (abfd == NULL
  863. || !setup_build_id (abfd))
  864. {
  865. free ((char *) emit_note_gnu_build_id);
  866. emit_note_gnu_build_id = NULL;
  867. }
  868. }
  869. if (bfd_link_relocatable (&link_info))
  870. {
  871. if (link_info.execstack == ! link_info.noexecstack)
  872. /* PR ld/16744: If "-z [no]execstack" has been specified on the
  873. command line and we are perfoming a relocatable link then no
  874. PT_GNU_STACK segment will be created and so the
  875. linkinfo.[no]execstack values set in _handle_option() will have no
  876. effect. Instead we create a .note.GNU-stack section in much the
  877. same way as the assembler does with its --[no]execstack option. */
  878. (void) bfd_make_section_with_flags (link_info.input_bfds,
  879. ".note.GNU-stack",
  880. SEC_READONLY | (link_info.execstack ? SEC_CODE : 0));
  881. return;
  882. }
  883. if (!link_info.traditional_format)
  884. {
  885. bfd *abfd, *elfbfd = NULL;
  886. bfd_boolean warn_eh_frame = FALSE;
  887. asection *s;
  888. int seen_type = 0;
  889. for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next)
  890. {
  891. int type = 0;
  892. for (s = abfd->sections; s && type < COMPACT_EH_HDR; s = s->next)
  893. {
  894. const char *name = bfd_get_section_name (abfd, s);
  895. if (bfd_is_abs_section (s->output_section))
  896. continue;
  897. if (CONST_STRNEQ (name, ".eh_frame_entry"))
  898. type = COMPACT_EH_HDR;
  899. else if (strcmp (name, ".eh_frame") == 0 && s->size > 8)
  900. type = DWARF2_EH_HDR;
  901. }
  902. if (type != 0)
  903. {
  904. if (seen_type == 0)
  905. {
  906. seen_type = type;
  907. }
  908. else if (seen_type != type)
  909. {
  910. einfo (_("%P%F: compact frame descriptions incompatible with"
  911. " DWARF2 .eh_frame from %B\n"),
  912. type == DWARF2_EH_HDR ? abfd : elfbfd);
  913. break;
  914. }
  915. if (!elfbfd
  916. && (type == COMPACT_EH_HDR || link_info.eh_frame_hdr_type != 0))
  917. {
  918. if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
  919. elfbfd = abfd;
  920. warn_eh_frame = TRUE;
  921. }
  922. }
  923. if (seen_type == COMPACT_EH_HDR)
  924. link_info.eh_frame_hdr_type = COMPACT_EH_HDR;
  925. if (bfd_count_sections (abfd) == 0)
  926. continue;
  927. }
  928. if (elfbfd)
  929. {
  930. const struct elf_backend_data *bed;
  931. bed = get_elf_backend_data (elfbfd);
  932. s = bfd_make_section_with_flags (elfbfd, ".eh_frame_hdr",
  933. bed->dynamic_sec_flags
  934. | SEC_READONLY);
  935. if (s != NULL
  936. && bfd_set_section_alignment (elfbfd, s, 2))
  937. {
  938. htab->eh_info.hdr_sec = s;
  939. warn_eh_frame = FALSE;
  940. }
  941. }
  942. if (warn_eh_frame)
  943. einfo ("%P: warning: Cannot create .eh_frame_hdr section,"
  944. " --eh-frame-hdr ignored.\n");
  945. }
  946. /* Get the list of files which appear in DT_NEEDED entries in
  947. dynamic objects included in the link (often there will be none).
  948. For each such file, we want to track down the corresponding
  949. library, and include the symbol table in the link. This is what
  950. the runtime dynamic linker will do. Tracking the files down here
  951. permits one dynamic object to include another without requiring
  952. special action by the person doing the link. Note that the
  953. needed list can actually grow while we are stepping through this
  954. loop. */
  955. needed = bfd_elf_get_needed_list (link_info.output_bfd, &link_info);
  956. for (l = needed; l != NULL; l = l->next)
  957. {
  958. struct bfd_link_needed_list *ll;
  959. struct dt_needed n, nn;
  960. int force;
  961. /* If the lib that needs this one was --as-needed and wasn't
  962. found to be needed, then this lib isn't needed either. */
  963. if (l->by != NULL
  964. && (bfd_elf_get_dyn_lib_class (l->by) & DYN_AS_NEEDED) != 0)
  965. continue;
  966. /* Skip the lib if --no-copy-dt-needed-entries and
  967. --allow-shlib-undefined is in effect. */
  968. if (l->by != NULL
  969. && link_info.unresolved_syms_in_shared_libs == RM_IGNORE
  970. && (bfd_elf_get_dyn_lib_class (l->by) & DYN_NO_ADD_NEEDED) != 0)
  971. continue;
  972. /* If we've already seen this file, skip it. */
  973. for (ll = needed; ll != l; ll = ll->next)
  974. if ((ll->by == NULL
  975. || (bfd_elf_get_dyn_lib_class (ll->by) & DYN_AS_NEEDED) == 0)
  976. && strcmp (ll->name, l->name) == 0)
  977. break;
  978. if (ll != l)
  979. continue;
  980. /* See if this file was included in the link explicitly. */
  981. global_needed = l;
  982. global_found = NULL;
  983. lang_for_each_input_file (gld${EMULATION_NAME}_check_needed);
  984. if (global_found != NULL
  985. && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
  986. & DYN_AS_NEEDED) == 0)
  987. continue;
  988. n.by = l->by;
  989. n.name = l->name;
  990. nn.by = l->by;
  991. if (verbose)
  992. info_msg (_("%s needed by %B\n"), l->name, l->by);
  993. /* As-needed libs specified on the command line (or linker script)
  994. take priority over libs found in search dirs. */
  995. if (global_found != NULL)
  996. {
  997. nn.name = global_found->filename;
  998. if (gld${EMULATION_NAME}_try_needed (&nn, TRUE))
  999. continue;
  1000. }
  1001. /* We need to find this file and include the symbol table. We
  1002. want to search for the file in the same way that the dynamic
  1003. linker will search. That means that we want to use
  1004. rpath_link, rpath, then the environment variable
  1005. LD_LIBRARY_PATH (native only), then the DT_RPATH/DT_RUNPATH
  1006. entries (native only), then the linker script LIB_SEARCH_DIRS.
  1007. We do not search using the -L arguments.
  1008. We search twice. The first time, we skip objects which may
  1009. introduce version mismatches. The second time, we force
  1010. their use. See gld${EMULATION_NAME}_vercheck comment. */
  1011. for (force = 0; force < 2; force++)
  1012. {
  1013. size_t len;
  1014. search_dirs_type *search;
  1015. EOF
  1016. if [ "x${NATIVE}" = xyes ] ; then
  1017. fragment <<EOF
  1018. const char *lib_path;
  1019. EOF
  1020. fi
  1021. if [ "x${USE_LIBPATH}" = xyes ] ; then
  1022. fragment <<EOF
  1023. struct bfd_link_needed_list *rp;
  1024. int found;
  1025. EOF
  1026. fi
  1027. fragment <<EOF
  1028. if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link,
  1029. &n, force))
  1030. break;
  1031. EOF
  1032. if [ "x${USE_LIBPATH}" = xyes ] ; then
  1033. fragment <<EOF
  1034. if (gld${EMULATION_NAME}_search_needed (command_line.rpath,
  1035. &n, force))
  1036. break;
  1037. EOF
  1038. fi
  1039. if [ "x${NATIVE}" = xyes ] ; then
  1040. fragment <<EOF
  1041. if (command_line.rpath_link == NULL
  1042. && command_line.rpath == NULL)
  1043. {
  1044. lib_path = (const char *) getenv ("LD_RUN_PATH");
  1045. if (gld${EMULATION_NAME}_search_needed (lib_path, &n,
  1046. force))
  1047. break;
  1048. }
  1049. lib_path = (const char *) getenv ("LD_LIBRARY_PATH");
  1050. if (gld${EMULATION_NAME}_search_needed (lib_path, &n, force))
  1051. break;
  1052. EOF
  1053. fi
  1054. if [ "x${USE_LIBPATH}" = xyes ] ; then
  1055. fragment <<EOF
  1056. found = 0;
  1057. rp = bfd_elf_get_runpath_list (link_info.output_bfd, &link_info);
  1058. for (; !found && rp != NULL; rp = rp->next)
  1059. {
  1060. const char *tmpname = rp->name;
  1061. if (IS_ABSOLUTE_PATH (tmpname))
  1062. tmpname = gld${EMULATION_NAME}_add_sysroot (tmpname);
  1063. found = (rp->by == l->by
  1064. && gld${EMULATION_NAME}_search_needed (tmpname,
  1065. &n,
  1066. force));
  1067. if (tmpname != rp->name)
  1068. free ((char *) tmpname);
  1069. }
  1070. if (found)
  1071. break;
  1072. EOF
  1073. fi
  1074. if [ "x${USE_LIBPATH}" = xyes ] ; then
  1075. case ${target} in
  1076. *-*-freebsd* | *-*-dragonfly*)
  1077. fragment <<EOF
  1078. if (gld${EMULATION_NAME}_check_ld_elf_hints (l, force))
  1079. break;
  1080. EOF
  1081. # FreeBSD
  1082. ;;
  1083. *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
  1084. fragment <<EOF
  1085. if (gld${EMULATION_NAME}_check_ld_so_conf (l, force))
  1086. break;
  1087. EOF
  1088. # Linux
  1089. ;;
  1090. esac
  1091. fi
  1092. fragment <<EOF
  1093. len = strlen (l->name);
  1094. for (search = search_head; search != NULL; search = search->next)
  1095. {
  1096. char *filename;
  1097. if (search->cmdline)
  1098. continue;
  1099. filename = (char *) xmalloc (strlen (search->name) + len + 2);
  1100. sprintf (filename, "%s/%s", search->name, l->name);
  1101. nn.name = filename;
  1102. if (gld${EMULATION_NAME}_try_needed (&nn, force))
  1103. break;
  1104. free (filename);
  1105. }
  1106. if (search != NULL)
  1107. break;
  1108. EOF
  1109. fragment <<EOF
  1110. }
  1111. if (force < 2)
  1112. continue;
  1113. einfo ("%P: warning: %s, needed by %B, not found (try using -rpath or -rpath-link)\n",
  1114. l->name, l->by);
  1115. }
  1116. if (link_info.eh_frame_hdr_type == COMPACT_EH_HDR)
  1117. if (bfd_elf_parse_eh_frame_entries (NULL, &link_info) == FALSE)
  1118. einfo (_("%P%F: Failed to parse EH frame entries.\n"));
  1119. }
  1120. EOF
  1121. fi
  1122. fragment <<EOF
  1123. /* Look through an expression for an assignment statement. */
  1124. static void
  1125. gld${EMULATION_NAME}_find_exp_assignment (etree_type *exp)
  1126. {
  1127. bfd_boolean provide = FALSE;
  1128. switch (exp->type.node_class)
  1129. {
  1130. case etree_provide:
  1131. case etree_provided:
  1132. provide = TRUE;
  1133. /* Fall thru */
  1134. case etree_assign:
  1135. /* We call record_link_assignment even if the symbol is defined.
  1136. This is because if it is defined by a dynamic object, we
  1137. actually want to use the value defined by the linker script,
  1138. not the value from the dynamic object (because we are setting
  1139. symbols like etext). If the symbol is defined by a regular
  1140. object, then, as it happens, calling record_link_assignment
  1141. will do no harm. */
  1142. if (strcmp (exp->assign.dst, ".") != 0)
  1143. {
  1144. if (!bfd_elf_record_link_assignment (link_info.output_bfd,
  1145. &link_info,
  1146. exp->assign.dst, provide,
  1147. exp->assign.hidden))
  1148. einfo ("%P%F: failed to record assignment to %s: %E\n",
  1149. exp->assign.dst);
  1150. }
  1151. gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
  1152. break;
  1153. case etree_binary:
  1154. gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
  1155. gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
  1156. break;
  1157. case etree_trinary:
  1158. gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
  1159. gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
  1160. gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
  1161. break;
  1162. case etree_unary:
  1163. gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
  1164. break;
  1165. default:
  1166. break;
  1167. }
  1168. }
  1169. /* This is called by the before_allocation routine via
  1170. lang_for_each_statement. It locates any assignment statements, and
  1171. tells the ELF backend about them, in case they are assignments to
  1172. symbols which are referred to by dynamic objects. */
  1173. static void
  1174. gld${EMULATION_NAME}_find_statement_assignment (lang_statement_union_type *s)
  1175. {
  1176. if (s->header.type == lang_assignment_statement_enum)
  1177. gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
  1178. }
  1179. EOF
  1180. if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then
  1181. if test x"${ELF_INTERPRETER_NAME+set}" = xset; then
  1182. ELF_INTERPRETER_SET_DEFAULT="
  1183. if (sinterp != NULL)
  1184. {
  1185. sinterp->contents = (unsigned char *) ${ELF_INTERPRETER_NAME};
  1186. sinterp->size = strlen ((char *) sinterp->contents) + 1;
  1187. }
  1188. "
  1189. else
  1190. ELF_INTERPRETER_SET_DEFAULT=
  1191. fi
  1192. fragment <<EOF
  1193. /* used by before_allocation and handle_option. */
  1194. static void
  1195. gld${EMULATION_NAME}_append_to_separated_string (char **to, char *op_arg)
  1196. {
  1197. if (*to == NULL)
  1198. *to = xstrdup (op_arg);
  1199. else
  1200. {
  1201. size_t to_len = strlen (*to);
  1202. size_t op_arg_len = strlen (op_arg);
  1203. char *buf;
  1204. char *cp = *to;
  1205. /* First see whether OPTARG is already in the path. */
  1206. do
  1207. {
  1208. if (strncmp (op_arg, cp, op_arg_len) == 0
  1209. && (cp[op_arg_len] == 0
  1210. || cp[op_arg_len] == config.rpath_separator))
  1211. /* We found it. */
  1212. break;
  1213. /* Not yet found. */
  1214. cp = strchr (cp, config.rpath_separator);
  1215. if (cp != NULL)
  1216. ++cp;
  1217. }
  1218. while (cp != NULL);
  1219. if (cp == NULL)
  1220. {
  1221. buf = xmalloc (to_len + op_arg_len + 2);
  1222. sprintf (buf, "%s%c%s", *to,
  1223. config.rpath_separator, op_arg);
  1224. free (*to);
  1225. *to = buf;
  1226. }
  1227. }
  1228. }
  1229. #if defined(__GNUC__) && GCC_VERSION < 4006
  1230. /* Work around a GCC uninitialized warning bug fixed in GCC 4.6. */
  1231. static struct bfd_link_hash_entry ehdr_start_empty;
  1232. #endif
  1233. /* This is called after the sections have been attached to output
  1234. sections, but before any sizes or addresses have been set. */
  1235. static void
  1236. gld${EMULATION_NAME}_before_allocation (void)
  1237. {
  1238. const char *rpath;
  1239. asection *sinterp;
  1240. bfd *abfd;
  1241. struct elf_link_hash_entry *ehdr_start = NULL;
  1242. #if defined(__GNUC__) && GCC_VERSION < 4006
  1243. /* Work around a GCC uninitialized warning bug fixed in GCC 4.6. */
  1244. struct bfd_link_hash_entry ehdr_start_save = ehdr_start_empty;
  1245. #else
  1246. struct bfd_link_hash_entry ehdr_start_save;
  1247. #endif
  1248. if (is_elf_hash_table (link_info.hash))
  1249. {
  1250. _bfd_elf_tls_setup (link_info.output_bfd, &link_info);
  1251. /* Make __ehdr_start hidden if it has been referenced, to
  1252. prevent the symbol from being dynamic. */
  1253. if (!bfd_link_relocatable (&link_info))
  1254. {
  1255. struct elf_link_hash_entry *h
  1256. = elf_link_hash_lookup (elf_hash_table (&link_info), "__ehdr_start",
  1257. FALSE, FALSE, TRUE);
  1258. /* Only adjust the export class if the symbol was referenced
  1259. and not defined, otherwise leave it alone. */
  1260. if (h != NULL
  1261. && (h->root.type == bfd_link_hash_new
  1262. || h->root.type == bfd_link_hash_undefined
  1263. || h->root.type == bfd_link_hash_undefweak
  1264. || h->root.type == bfd_link_hash_common))
  1265. {
  1266. _bfd_elf_link_hash_hide_symbol (&link_info, h, TRUE);
  1267. if (ELF_ST_VISIBILITY (h->other) != STV_INTERNAL)
  1268. h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN;
  1269. /* Don't leave the symbol undefined. Undefined hidden
  1270. symbols typically won't have dynamic relocations, but
  1271. we most likely will need dynamic relocations for
  1272. __ehdr_start if we are building a PIE or shared
  1273. library. */
  1274. ehdr_start = h;
  1275. ehdr_start_save = h->root;
  1276. h->root.type = bfd_link_hash_defined;
  1277. h->root.u.def.section = bfd_abs_section_ptr;
  1278. h->root.u.def.value = 0;
  1279. }
  1280. }
  1281. /* If we are going to make any variable assignments, we need to
  1282. let the ELF backend know about them in case the variables are
  1283. referred to by dynamic objects. */
  1284. lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
  1285. }
  1286. /* Let the ELF backend work out the sizes of any sections required
  1287. by dynamic linking. */
  1288. rpath = command_line.rpath;
  1289. if (rpath == NULL)
  1290. rpath = (const char *) getenv ("LD_RUN_PATH");
  1291. for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next)
  1292. if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
  1293. {
  1294. const char *audit_libs = elf_dt_audit (abfd);
  1295. /* If the input bfd contains an audit entry, we need to add it as
  1296. a dep audit entry. */
  1297. if (audit_libs && *audit_libs != '\0')
  1298. {
  1299. char *cp = xstrdup (audit_libs);
  1300. do
  1301. {
  1302. int more = 0;
  1303. char *cp2 = strchr (cp, config.rpath_separator);
  1304. if (cp2)
  1305. {
  1306. *cp2 = '\0';
  1307. more = 1;
  1308. }
  1309. if (cp != NULL && *cp != '\0')
  1310. gld${EMULATION_NAME}_append_to_separated_string (&depaudit, cp);
  1311. cp = more ? ++cp2 : NULL;
  1312. }
  1313. while (cp != NULL);
  1314. }
  1315. }
  1316. if (! (bfd_elf_size_dynamic_sections
  1317. (link_info.output_bfd, command_line.soname, rpath,
  1318. command_line.filter_shlib, audit, depaudit,
  1319. (const char * const *) command_line.auxiliary_filters,
  1320. &link_info, &sinterp)))
  1321. einfo ("%P%F: failed to set dynamic section sizes: %E\n");
  1322. ${ELF_INTERPRETER_SET_DEFAULT}
  1323. /* Let the user override the dynamic linker we are using. */
  1324. if (command_line.interpreter != NULL
  1325. && sinterp != NULL)
  1326. {
  1327. sinterp->contents = (bfd_byte *) command_line.interpreter;
  1328. sinterp->size = strlen (command_line.interpreter) + 1;
  1329. }
  1330. /* Look for any sections named .gnu.warning. As a GNU extensions,
  1331. we treat such sections as containing warning messages. We print
  1332. out the warning message, and then zero out the section size so
  1333. that it does not get copied into the output file. */
  1334. {
  1335. LANG_FOR_EACH_INPUT_STATEMENT (is)
  1336. {
  1337. asection *s;
  1338. bfd_size_type sz;
  1339. char *msg;
  1340. bfd_boolean ret;
  1341. if (is->flags.just_syms)
  1342. continue;
  1343. s = bfd_get_section_by_name (is->the_bfd, ".gnu.warning");
  1344. if (s == NULL)
  1345. continue;
  1346. sz = s->size;
  1347. msg = (char *) xmalloc ((size_t) (sz + 1));
  1348. if (! bfd_get_section_contents (is->the_bfd, s, msg,
  1349. (file_ptr) 0, sz))
  1350. einfo ("%F%B: Can't read contents of section .gnu.warning: %E\n",
  1351. is->the_bfd);
  1352. msg[sz] = '\0';
  1353. ret = link_info.callbacks->warning (&link_info, msg,
  1354. (const char *) NULL,
  1355. is->the_bfd, (asection *) NULL,
  1356. (bfd_vma) 0);
  1357. ASSERT (ret);
  1358. free (msg);
  1359. /* Clobber the section size, so that we don't waste space
  1360. copying the warning into the output file. If we've already
  1361. sized the output section, adjust its size. The adjustment
  1362. is on rawsize because targets that size sections early will
  1363. have called lang_reset_memory_regions after sizing. */
  1364. if (s->output_section != NULL
  1365. && s->output_section->rawsize >= s->size)
  1366. s->output_section->rawsize -= s->size;
  1367. s->size = 0;
  1368. /* Also set SEC_EXCLUDE, so that local symbols defined in the
  1369. warning section don't get copied to the output. */
  1370. s->flags |= SEC_EXCLUDE | SEC_KEEP;
  1371. }
  1372. }
  1373. before_allocation_default ();
  1374. if (!bfd_elf_size_dynsym_hash_dynstr (link_info.output_bfd, &link_info))
  1375. einfo ("%P%F: failed to set dynamic section sizes: %E\n");
  1376. if (ehdr_start != NULL)
  1377. {
  1378. /* If we twiddled __ehdr_start to defined earlier, put it back
  1379. as it was. */
  1380. ehdr_start->root.type = ehdr_start_save.type;
  1381. ehdr_start->root.u = ehdr_start_save.u;
  1382. }
  1383. }
  1384. EOF
  1385. fi
  1386. if test x"$LDEMUL_OPEN_DYNAMIC_ARCHIVE" != xgld"$EMULATION_NAME"_open_dynamic_archive; then
  1387. fragment <<EOF
  1388. /* Try to open a dynamic archive. This is where we know that ELF
  1389. dynamic libraries have an extension of .so (or .sl on oddball systems
  1390. like hpux). */
  1391. static bfd_boolean
  1392. gld${EMULATION_NAME}_open_dynamic_archive
  1393. (const char *arch, search_dirs_type *search, lang_input_statement_type *entry)
  1394. {
  1395. const char *filename;
  1396. char *string;
  1397. size_t len;
  1398. bfd_boolean opened = FALSE;
  1399. if (! entry->flags.maybe_archive)
  1400. return FALSE;
  1401. filename = entry->filename;
  1402. len = strlen (search->name) + strlen (filename);
  1403. if (entry->flags.full_name_provided)
  1404. {
  1405. len += sizeof "/";
  1406. string = (char *) xmalloc (len);
  1407. sprintf (string, "%s/%s", search->name, filename);
  1408. }
  1409. else
  1410. {
  1411. size_t xlen = 0;
  1412. len += strlen (arch) + sizeof "/lib.so";
  1413. #ifdef EXTRA_SHLIB_EXTENSION
  1414. xlen = (strlen (EXTRA_SHLIB_EXTENSION) > 3
  1415. ? strlen (EXTRA_SHLIB_EXTENSION) - 3
  1416. : 0);
  1417. #endif
  1418. string = (char *) xmalloc (len + xlen);
  1419. sprintf (string, "%s/lib%s%s.so", search->name, filename, arch);
  1420. #ifdef EXTRA_SHLIB_EXTENSION
  1421. /* Try the .so extension first. If that fails build a new filename
  1422. using EXTRA_SHLIB_EXTENSION. */
  1423. opened = ldfile_try_open_bfd (string, entry);
  1424. if (!opened)
  1425. strcpy (string + len - 4, EXTRA_SHLIB_EXTENSION);
  1426. #endif
  1427. }
  1428. if (!opened && !ldfile_try_open_bfd (string, entry))
  1429. {
  1430. free (string);
  1431. return FALSE;
  1432. }
  1433. entry->filename = string;
  1434. /* We have found a dynamic object to include in the link. The ELF
  1435. backend linker will create a DT_NEEDED entry in the .dynamic
  1436. section naming this file. If this file includes a DT_SONAME
  1437. entry, it will be used. Otherwise, the ELF linker will just use
  1438. the name of the file. For an archive found by searching, like
  1439. this one, the DT_NEEDED entry should consist of just the name of
  1440. the file, without the path information used to find it. Note
  1441. that we only need to do this if we have a dynamic object; an
  1442. archive will never be referenced by a DT_NEEDED entry.
  1443. FIXME: This approach--using bfd_elf_set_dt_needed_name--is not
  1444. very pretty. I haven't been able to think of anything that is
  1445. pretty, though. */
  1446. if (bfd_check_format (entry->the_bfd, bfd_object)
  1447. && (entry->the_bfd->flags & DYNAMIC) != 0)
  1448. {
  1449. ASSERT (entry->flags.maybe_archive && entry->flags.search_dirs);
  1450. /* Rather than duplicating the logic above. Just use the
  1451. filename we recorded earlier. */
  1452. if (!entry->flags.full_name_provided)
  1453. filename = lbasename (entry->filename);
  1454. bfd_elf_set_dt_needed_name (entry->the_bfd, filename);
  1455. }
  1456. return TRUE;
  1457. }
  1458. EOF
  1459. fi
  1460. if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then
  1461. fragment <<EOF
  1462. /* A variant of lang_output_section_find used by place_orphan. */
  1463. static lang_output_section_statement_type *
  1464. output_rel_find (asection *sec, int isdyn)
  1465. {
  1466. lang_output_section_statement_type *lookup;
  1467. lang_output_section_statement_type *last = NULL;
  1468. lang_output_section_statement_type *last_alloc = NULL;
  1469. lang_output_section_statement_type *last_ro_alloc = NULL;
  1470. lang_output_section_statement_type *last_rel = NULL;
  1471. lang_output_section_statement_type *last_rel_alloc = NULL;
  1472. int rela = sec->name[4] == 'a';
  1473. for (lookup = &lang_output_section_statement.head->output_section_statement;
  1474. lookup != NULL;
  1475. lookup = lookup->next)
  1476. {
  1477. if (lookup->constraint >= 0
  1478. && CONST_STRNEQ (lookup->name, ".rel"))
  1479. {
  1480. int lookrela = lookup->name[4] == 'a';
  1481. /* .rel.dyn must come before all other reloc sections, to suit
  1482. GNU ld.so. */
  1483. if (isdyn)
  1484. break;
  1485. /* Don't place after .rel.plt as doing so results in wrong
  1486. dynamic tags. */
  1487. if (strcmp (".plt", lookup->name + 4 + lookrela) == 0)
  1488. break;
  1489. if (rela == lookrela || last_rel == NULL)
  1490. last_rel = lookup;
  1491. if ((rela == lookrela || last_rel_alloc == NULL)
  1492. && lookup->bfd_section != NULL
  1493. && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
  1494. last_rel_alloc = lookup;
  1495. }
  1496. last = lookup;
  1497. if (lookup->bfd_section != NULL
  1498. && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
  1499. {
  1500. last_alloc = lookup;
  1501. if ((lookup->bfd_section->flags & SEC_READONLY) != 0)
  1502. last_ro_alloc = lookup;
  1503. }
  1504. }
  1505. if (last_rel_alloc)
  1506. return last_rel_alloc;
  1507. if (last_rel)
  1508. return last_rel;
  1509. if (last_ro_alloc)
  1510. return last_ro_alloc;
  1511. if (last_alloc)
  1512. return last_alloc;
  1513. return last;
  1514. }
  1515. /* Place an orphan section. We use this to put random SHF_ALLOC
  1516. sections in the right segment. */
  1517. static lang_output_section_statement_type *
  1518. gld${EMULATION_NAME}_place_orphan (asection *s,
  1519. const char *secname,
  1520. int constraint)
  1521. {
  1522. static struct orphan_save hold[] =
  1523. {
  1524. { ".text",
  1525. SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
  1526. 0, 0, 0, 0 },
  1527. { ".rodata",
  1528. SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
  1529. 0, 0, 0, 0 },
  1530. { ".tdata",
  1531. SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_THREAD_LOCAL,
  1532. 0, 0, 0, 0 },
  1533. { ".data",
  1534. SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
  1535. 0, 0, 0, 0 },
  1536. { ".bss",
  1537. SEC_ALLOC,
  1538. 0, 0, 0, 0 },
  1539. { 0,
  1540. SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
  1541. 0, 0, 0, 0 },
  1542. { ".interp",
  1543. SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
  1544. 0, 0, 0, 0 },
  1545. { ".sdata",
  1546. SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_SMALL_DATA,
  1547. 0, 0, 0, 0 },
  1548. { ".comment",
  1549. SEC_HAS_CONTENTS,
  1550. 0, 0, 0, 0 },
  1551. };
  1552. enum orphan_save_index
  1553. {
  1554. orphan_text = 0,
  1555. orphan_rodata,
  1556. orphan_tdata,
  1557. orphan_data,
  1558. orphan_bss,
  1559. orphan_rel,
  1560. orphan_interp,
  1561. orphan_sdata,
  1562. orphan_nonalloc
  1563. };
  1564. static int orphan_init_done = 0;
  1565. struct orphan_save *place;
  1566. lang_output_section_statement_type *after;
  1567. lang_output_section_statement_type *os;
  1568. lang_output_section_statement_type *match_by_name = NULL;
  1569. int isdyn = 0;
  1570. int iself = s->owner->xvec->flavour == bfd_target_elf_flavour;
  1571. unsigned int sh_type = iself ? elf_section_type (s) : SHT_NULL;
  1572. if (!bfd_link_relocatable (&link_info)
  1573. && link_info.combreloc
  1574. && (s->flags & SEC_ALLOC))
  1575. {
  1576. if (iself)
  1577. switch (sh_type)
  1578. {
  1579. case SHT_RELA:
  1580. secname = ".rela.dyn";
  1581. isdyn = 1;
  1582. break;
  1583. case SHT_REL:
  1584. secname = ".rel.dyn";
  1585. isdyn = 1;
  1586. break;
  1587. default:
  1588. break;
  1589. }
  1590. else if (CONST_STRNEQ (secname, ".rel"))
  1591. {
  1592. secname = secname[4] == 'a' ? ".rela.dyn" : ".rel.dyn";
  1593. isdyn = 1;
  1594. }
  1595. }
  1596. /* Look through the script to see where to place this section. */
  1597. if (constraint == 0)
  1598. for (os = lang_output_section_find (secname);
  1599. os != NULL;
  1600. os = next_matching_output_section_statement (os, 0))
  1601. {
  1602. /* If we don't match an existing output section, tell
  1603. lang_insert_orphan to create a new output section. */
  1604. constraint = SPECIAL;
  1605. if (os->bfd_section != NULL
  1606. && (os->bfd_section->flags == 0
  1607. || (_bfd_elf_match_sections_by_type (link_info.output_bfd,
  1608. os->bfd_section,
  1609. s->owner, s)
  1610. && ((s->flags ^ os->bfd_section->flags)
  1611. & (SEC_LOAD | SEC_ALLOC)) == 0)))
  1612. {
  1613. /* We already have an output section statement with this
  1614. name, and its bfd section has compatible flags.
  1615. If the section already exists but does not have any flags
  1616. set, then it has been created by the linker, probably as a
  1617. result of a --section-start command line switch. */
  1618. lang_add_section (&os->children, s, NULL, os);
  1619. return os;
  1620. }
  1621. /* Save unused output sections in case we can match them
  1622. against orphans later. */
  1623. if (os->bfd_section == NULL)
  1624. match_by_name = os;
  1625. }
  1626. /* If we didn't match an active output section, see if we matched an
  1627. unused one and use that. */
  1628. if (match_by_name)
  1629. {
  1630. lang_add_section (&match_by_name->children, s, NULL, match_by_name);
  1631. return match_by_name;
  1632. }
  1633. if (!orphan_init_done)
  1634. {
  1635. struct orphan_save *ho;
  1636. for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
  1637. if (ho->name != NULL)
  1638. {
  1639. ho->os = lang_output_section_find (ho->name);
  1640. if (ho->os != NULL && ho->os->flags == 0)
  1641. ho->os->flags = ho->flags;
  1642. }
  1643. orphan_init_done = 1;
  1644. }
  1645. /* If this is a final link, then always put .gnu.warning.SYMBOL
  1646. sections into the .text section to get them out of the way. */
  1647. if (bfd_link_executable (&link_info)
  1648. && CONST_STRNEQ (s->name, ".gnu.warning.")
  1649. && hold[orphan_text].os != NULL)
  1650. {
  1651. os = hold[orphan_text].os;
  1652. lang_add_section (&os->children, s, NULL, os);
  1653. return os;
  1654. }
  1655. /* Decide which segment the section should go in based on the
  1656. section name and section flags. We put loadable .note sections
  1657. right after the .interp section, so that the PT_NOTE segment is
  1658. stored right after the program headers where the OS can read it
  1659. in the first page. */
  1660. place = NULL;
  1661. if ((s->flags & (SEC_ALLOC | SEC_DEBUGGING)) == 0)
  1662. place = &hold[orphan_nonalloc];
  1663. else if ((s->flags & SEC_ALLOC) == 0)
  1664. ;
  1665. else if ((s->flags & SEC_LOAD) != 0
  1666. && ((iself && sh_type == SHT_NOTE)
  1667. || (!iself && CONST_STRNEQ (secname, ".note"))))
  1668. place = &hold[orphan_interp];
  1669. else if ((s->flags & (SEC_LOAD | SEC_HAS_CONTENTS | SEC_THREAD_LOCAL)) == 0)
  1670. place = &hold[orphan_bss];
  1671. else if ((s->flags & SEC_SMALL_DATA) != 0)
  1672. place = &hold[orphan_sdata];
  1673. else if ((s->flags & SEC_THREAD_LOCAL) != 0)
  1674. place = &hold[orphan_tdata];
  1675. else if ((s->flags & SEC_READONLY) == 0)
  1676. place = &hold[orphan_data];
  1677. else if (((iself && (sh_type == SHT_RELA || sh_type == SHT_REL))
  1678. || (!iself && CONST_STRNEQ (secname, ".rel")))
  1679. && (s->flags & SEC_LOAD) != 0)
  1680. place = &hold[orphan_rel];
  1681. else if ((s->flags & SEC_CODE) == 0)
  1682. place = &hold[orphan_rodata];
  1683. else
  1684. place = &hold[orphan_text];
  1685. after = NULL;
  1686. if (place != NULL)
  1687. {
  1688. if (place->os == NULL)
  1689. {
  1690. if (place->name != NULL)
  1691. place->os = lang_output_section_find (place->name);
  1692. else
  1693. place->os = output_rel_find (s, isdyn);
  1694. }
  1695. after = place->os;
  1696. if (after == NULL)
  1697. after = lang_output_section_find_by_flags
  1698. (s, &place->os, _bfd_elf_match_sections_by_type);
  1699. if (after == NULL)
  1700. /* *ABS* is always the first output section statement. */
  1701. after = &lang_output_section_statement.head->output_section_statement;
  1702. }
  1703. return lang_insert_orphan (s, secname, constraint, after, place, NULL, NULL);
  1704. }
  1705. EOF
  1706. fi
  1707. if test x"$LDEMUL_AFTER_ALLOCATION" != xgld"$EMULATION_NAME"_after_allocation; then
  1708. fragment <<EOF
  1709. static void
  1710. gld${EMULATION_NAME}_after_allocation (void)
  1711. {
  1712. int need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info);
  1713. if (need_layout < 0)
  1714. einfo ("%X%P: .eh_frame/.stab edit: %E\n");
  1715. else
  1716. gld${EMULATION_NAME}_map_segments (need_layout);
  1717. }
  1718. EOF
  1719. fi
  1720. if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then
  1721. fragment <<EOF
  1722. static char *
  1723. gld${EMULATION_NAME}_get_script (int *isfile)
  1724. EOF
  1725. if test x"$COMPILE_IN" = xyes
  1726. then
  1727. # Scripts compiled in.
  1728. # sed commands to quote an ld script as a C string.
  1729. sc="-f stringify.sed"
  1730. fragment <<EOF
  1731. {
  1732. *isfile = 0;
  1733. if (bfd_link_relocatable (&link_info) && config.build_constructors)
  1734. return
  1735. EOF
  1736. sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
  1737. echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
  1738. sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
  1739. echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
  1740. sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
  1741. if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then : ; else
  1742. echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
  1743. sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
  1744. fi
  1745. if test -n "$GENERATE_PIE_SCRIPT" ; then
  1746. if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
  1747. echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
  1748. echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
  1749. echo ' && link_info.relro' >> e${EMULATION_NAME}.c
  1750. echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
  1751. sed $sc ldscripts/${EMULATION_NAME}.xdw >> e${EMULATION_NAME}.c
  1752. echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
  1753. echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
  1754. sed $sc ldscripts/${EMULATION_NAME}.xdc >> e${EMULATION_NAME}.c
  1755. fi
  1756. echo ' ; else if (bfd_link_pie (&link_info)) return' >> e${EMULATION_NAME}.c
  1757. sed $sc ldscripts/${EMULATION_NAME}.xd >> e${EMULATION_NAME}.c
  1758. fi
  1759. if test -n "$GENERATE_SHLIB_SCRIPT" ; then
  1760. if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
  1761. echo ' ; else if (bfd_link_dll (&link_info) && link_info.combreloc' >> e${EMULATION_NAME}.c
  1762. echo ' && link_info.relro' >> e${EMULATION_NAME}.c
  1763. echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
  1764. sed $sc ldscripts/${EMULATION_NAME}.xsw >> e${EMULATION_NAME}.c
  1765. echo ' ; else if (bfd_link_dll (&link_info) && link_info.combreloc) return' >> e${EMULATION_NAME}.c
  1766. sed $sc ldscripts/${EMULATION_NAME}.xsc >> e${EMULATION_NAME}.c
  1767. fi
  1768. echo ' ; else if (bfd_link_dll (&link_info)) return' >> e${EMULATION_NAME}.c
  1769. sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c
  1770. fi
  1771. if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
  1772. echo ' ; else if (link_info.combreloc && link_info.relro' >> e${EMULATION_NAME}.c
  1773. echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
  1774. sed $sc ldscripts/${EMULATION_NAME}.xw >> e${EMULATION_NAME}.c
  1775. echo ' ; else if (link_info.combreloc) return' >> e${EMULATION_NAME}.c
  1776. sed $sc ldscripts/${EMULATION_NAME}.xc >> e${EMULATION_NAME}.c
  1777. fi
  1778. echo ' ; else return' >> e${EMULATION_NAME}.c
  1779. sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
  1780. echo '; }' >> e${EMULATION_NAME}.c
  1781. else
  1782. # Scripts read from the filesystem.
  1783. fragment <<EOF
  1784. {
  1785. *isfile = 1;
  1786. if (bfd_link_relocatable (&link_info) && config.build_constructors)
  1787. return "ldscripts/${EMULATION_NAME}.xu";
  1788. else if (bfd_link_relocatable (&link_info))
  1789. return "ldscripts/${EMULATION_NAME}.xr";
  1790. else if (!config.text_read_only)
  1791. return "ldscripts/${EMULATION_NAME}.xbn";
  1792. EOF
  1793. if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then :
  1794. else
  1795. fragment <<EOF
  1796. else if (!config.magic_demand_paged)
  1797. return "ldscripts/${EMULATION_NAME}.xn";
  1798. EOF
  1799. fi
  1800. if test -n "$GENERATE_PIE_SCRIPT" ; then
  1801. if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
  1802. fragment <<EOF
  1803. else if (bfd_link_pie (&link_info)
  1804. && link_info.combreloc
  1805. && link_info.relro
  1806. && (link_info.flags & DF_BIND_NOW))
  1807. return "ldscripts/${EMULATION_NAME}.xdw";
  1808. else if (bfd_link_pie (&link_info)
  1809. && link_info.combreloc)
  1810. return "ldscripts/${EMULATION_NAME}.xdc";
  1811. EOF
  1812. fi
  1813. fragment <<EOF
  1814. else if (bfd_link_pie (&link_info))
  1815. return "ldscripts/${EMULATION_NAME}.xd";
  1816. EOF
  1817. fi
  1818. if test -n "$GENERATE_SHLIB_SCRIPT" ; then
  1819. if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
  1820. fragment <<EOF
  1821. else if (bfd_link_dll (&link_info) && link_info.combreloc
  1822. && link_info.relro && (link_info.flags & DF_BIND_NOW))
  1823. return "ldscripts/${EMULATION_NAME}.xsw";
  1824. else if (bfd_link_dll (&link_info) && link_info.combreloc)
  1825. return "ldscripts/${EMULATION_NAME}.xsc";
  1826. EOF
  1827. fi
  1828. fragment <<EOF
  1829. else if (bfd_link_dll (&link_info))
  1830. return "ldscripts/${EMULATION_NAME}.xs";
  1831. EOF
  1832. fi
  1833. if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
  1834. fragment <<EOF
  1835. else if (link_info.combreloc && link_info.relro
  1836. && (link_info.flags & DF_BIND_NOW))
  1837. return "ldscripts/${EMULATION_NAME}.xw";
  1838. else if (link_info.combreloc)
  1839. return "ldscripts/${EMULATION_NAME}.xc";
  1840. EOF
  1841. fi
  1842. fragment <<EOF
  1843. else
  1844. return "ldscripts/${EMULATION_NAME}.x";
  1845. }
  1846. EOF
  1847. fi
  1848. fi
  1849. if test -n "$PARSE_AND_LIST_PROLOGUE" ; then
  1850. fragment <<EOF
  1851. $PARSE_AND_LIST_PROLOGUE
  1852. EOF
  1853. fi
  1854. fragment <<EOF
  1855. #define OPTION_DISABLE_NEW_DTAGS (400)
  1856. #define OPTION_ENABLE_NEW_DTAGS (OPTION_DISABLE_NEW_DTAGS + 1)
  1857. #define OPTION_GROUP (OPTION_ENABLE_NEW_DTAGS + 1)
  1858. #define OPTION_EH_FRAME_HDR (OPTION_GROUP + 1)
  1859. #define OPTION_EXCLUDE_LIBS (OPTION_EH_FRAME_HDR + 1)
  1860. #define OPTION_HASH_STYLE (OPTION_EXCLUDE_LIBS + 1)
  1861. #define OPTION_BUILD_ID (OPTION_HASH_STYLE + 1)
  1862. #define OPTION_AUDIT (OPTION_BUILD_ID + 1)
  1863. #define OPTION_COMPRESS_DEBUG (OPTION_AUDIT + 1)
  1864. static void
  1865. gld${EMULATION_NAME}_add_options
  1866. (int ns, char **shortopts, int nl, struct option **longopts,
  1867. int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
  1868. {
  1869. EOF
  1870. if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
  1871. fragment <<EOF
  1872. static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:P:";
  1873. EOF
  1874. else
  1875. fragment <<EOF
  1876. static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:";
  1877. EOF
  1878. fi
  1879. fragment <<EOF
  1880. static const struct option xtra_long[] = {
  1881. EOF
  1882. if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
  1883. fragment <<EOF
  1884. {"audit", required_argument, NULL, OPTION_AUDIT},
  1885. {"Bgroup", no_argument, NULL, OPTION_GROUP},
  1886. EOF
  1887. fi
  1888. fragment <<EOF
  1889. {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
  1890. {"compress-debug-sections", required_argument, NULL, OPTION_COMPRESS_DEBUG},
  1891. EOF
  1892. if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
  1893. fragment <<EOF
  1894. {"depaudit", required_argument, NULL, 'P'},
  1895. {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
  1896. {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
  1897. {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR},
  1898. {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
  1899. {"hash-style", required_argument, NULL, OPTION_HASH_STYLE},
  1900. EOF
  1901. fi
  1902. if test -n "$PARSE_AND_LIST_LONGOPTS" ; then
  1903. fragment <<EOF
  1904. $PARSE_AND_LIST_LONGOPTS
  1905. EOF
  1906. fi
  1907. fragment <<EOF
  1908. {NULL, no_argument, NULL, 0}
  1909. };
  1910. *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
  1911. memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
  1912. *longopts = (struct option *)
  1913. xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
  1914. memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
  1915. }
  1916. #define DEFAULT_BUILD_ID_STYLE "sha1"
  1917. static bfd_boolean
  1918. gld${EMULATION_NAME}_handle_option (int optc)
  1919. {
  1920. switch (optc)
  1921. {
  1922. default:
  1923. return FALSE;
  1924. case OPTION_BUILD_ID:
  1925. if (emit_note_gnu_build_id != NULL)
  1926. {
  1927. free ((char *) emit_note_gnu_build_id);
  1928. emit_note_gnu_build_id = NULL;
  1929. }
  1930. if (optarg == NULL)
  1931. optarg = DEFAULT_BUILD_ID_STYLE;
  1932. if (strcmp (optarg, "none"))
  1933. emit_note_gnu_build_id = xstrdup (optarg);
  1934. break;
  1935. case OPTION_COMPRESS_DEBUG:
  1936. if (strcasecmp (optarg, "none") == 0)
  1937. link_info.compress_debug = COMPRESS_DEBUG_NONE;
  1938. else if (strcasecmp (optarg, "zlib") == 0)
  1939. link_info.compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
  1940. else if (strcasecmp (optarg, "zlib-gnu") == 0)
  1941. link_info.compress_debug = COMPRESS_DEBUG_GNU_ZLIB;
  1942. else if (strcasecmp (optarg, "zlib-gabi") == 0)
  1943. link_info.compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
  1944. else
  1945. einfo (_("%P%F: invalid --compress-debug-sections option: \`%s'\n"),
  1946. optarg);
  1947. break;
  1948. EOF
  1949. if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
  1950. fragment <<EOF
  1951. case OPTION_AUDIT:
  1952. gld${EMULATION_NAME}_append_to_separated_string (&audit, optarg);
  1953. break;
  1954. case 'P':
  1955. gld${EMULATION_NAME}_append_to_separated_string (&depaudit, optarg);
  1956. break;
  1957. case OPTION_DISABLE_NEW_DTAGS:
  1958. link_info.new_dtags = FALSE;
  1959. break;
  1960. case OPTION_ENABLE_NEW_DTAGS:
  1961. link_info.new_dtags = TRUE;
  1962. break;
  1963. case OPTION_EH_FRAME_HDR:
  1964. link_info.eh_frame_hdr_type = DWARF2_EH_HDR;
  1965. break;
  1966. case OPTION_GROUP:
  1967. link_info.flags_1 |= (bfd_vma) DF_1_GROUP;
  1968. /* Groups must be self-contained. */
  1969. link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
  1970. link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
  1971. break;
  1972. case OPTION_EXCLUDE_LIBS:
  1973. add_excluded_libs (optarg);
  1974. break;
  1975. case OPTION_HASH_STYLE:
  1976. link_info.emit_hash = FALSE;
  1977. link_info.emit_gnu_hash = FALSE;
  1978. if (strcmp (optarg, "sysv") == 0)
  1979. link_info.emit_hash = TRUE;
  1980. else if (strcmp (optarg, "gnu") == 0)
  1981. link_info.emit_gnu_hash = TRUE;
  1982. else if (strcmp (optarg, "both") == 0)
  1983. {
  1984. link_info.emit_hash = TRUE;
  1985. link_info.emit_gnu_hash = TRUE;
  1986. }
  1987. else
  1988. einfo (_("%P%F: invalid hash style \`%s'\n"), optarg);
  1989. break;
  1990. EOF
  1991. fi
  1992. fragment <<EOF
  1993. case 'z':
  1994. if (strcmp (optarg, "defs") == 0)
  1995. link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
  1996. else if (strcmp (optarg, "muldefs") == 0)
  1997. link_info.allow_multiple_definition = TRUE;
  1998. else if (CONST_STRNEQ (optarg, "max-page-size="))
  1999. {
  2000. char *end;
  2001. config.maxpagesize = strtoul (optarg + 14, &end, 0);
  2002. if (*end || (config.maxpagesize & (config.maxpagesize - 1)) != 0)
  2003. einfo (_("%P%F: invalid maxium page size \`%s'\n"),
  2004. optarg + 14);
  2005. }
  2006. else if (CONST_STRNEQ (optarg, "common-page-size="))
  2007. {
  2008. char *end;
  2009. config.commonpagesize = strtoul (optarg + 17, &end, 0);
  2010. if (*end
  2011. || (config.commonpagesize & (config.commonpagesize - 1)) != 0)
  2012. einfo (_("%P%F: invalid common page size \`%s'\n"),
  2013. optarg + 17);
  2014. }
  2015. else if (CONST_STRNEQ (optarg, "stack-size="))
  2016. {
  2017. char *end;
  2018. link_info.stacksize = strtoul (optarg + 11, &end, 0);
  2019. if (*end || link_info.stacksize < 0)
  2020. einfo (_("%P%F: invalid stack size \`%s'\n"), optarg + 11);
  2021. if (!link_info.stacksize)
  2022. /* Use -1 for explicit no-stack, because zero means
  2023. 'default'. */
  2024. link_info.stacksize = -1;
  2025. }
  2026. else if (strcmp (optarg, "execstack") == 0)
  2027. {
  2028. link_info.execstack = TRUE;
  2029. link_info.noexecstack = FALSE;
  2030. }
  2031. else if (strcmp (optarg, "noexecstack") == 0)
  2032. {
  2033. link_info.noexecstack = TRUE;
  2034. link_info.execstack = FALSE;
  2035. }
  2036. EOF
  2037. if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
  2038. fragment <<EOF
  2039. else if (strcmp (optarg, "global") == 0)
  2040. link_info.flags_1 |= (bfd_vma) DF_1_GLOBAL;
  2041. else if (strcmp (optarg, "initfirst") == 0)
  2042. link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST;
  2043. else if (strcmp (optarg, "interpose") == 0)
  2044. link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE;
  2045. else if (strcmp (optarg, "loadfltr") == 0)
  2046. link_info.flags_1 |= (bfd_vma) DF_1_LOADFLTR;
  2047. else if (strcmp (optarg, "nodefaultlib") == 0)
  2048. link_info.flags_1 |= (bfd_vma) DF_1_NODEFLIB;
  2049. else if (strcmp (optarg, "nodelete") == 0)
  2050. link_info.flags_1 |= (bfd_vma) DF_1_NODELETE;
  2051. else if (strcmp (optarg, "nodlopen") == 0)
  2052. link_info.flags_1 |= (bfd_vma) DF_1_NOOPEN;
  2053. else if (strcmp (optarg, "nodump") == 0)
  2054. link_info.flags_1 |= (bfd_vma) DF_1_NODUMP;
  2055. else if (strcmp (optarg, "now") == 0)
  2056. {
  2057. link_info.flags |= (bfd_vma) DF_BIND_NOW;
  2058. link_info.flags_1 |= (bfd_vma) DF_1_NOW;
  2059. }
  2060. else if (strcmp (optarg, "lazy") == 0)
  2061. {
  2062. link_info.flags &= ~(bfd_vma) DF_BIND_NOW;
  2063. link_info.flags_1 &= ~(bfd_vma) DF_1_NOW;
  2064. }
  2065. else if (strcmp (optarg, "origin") == 0)
  2066. {
  2067. link_info.flags |= (bfd_vma) DF_ORIGIN;
  2068. link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN;
  2069. }
  2070. else if (strcmp (optarg, "combreloc") == 0)
  2071. link_info.combreloc = TRUE;
  2072. else if (strcmp (optarg, "nocombreloc") == 0)
  2073. link_info.combreloc = FALSE;
  2074. else if (strcmp (optarg, "nocopyreloc") == 0)
  2075. link_info.nocopyreloc = TRUE;
  2076. else if (strcmp (optarg, "relro") == 0)
  2077. link_info.relro = TRUE;
  2078. else if (strcmp (optarg, "norelro") == 0)
  2079. link_info.relro = FALSE;
  2080. else if (strcmp (optarg, "text") == 0)
  2081. link_info.error_textrel = TRUE;
  2082. else if (strcmp (optarg, "notext") == 0)
  2083. link_info.error_textrel = FALSE;
  2084. else if (strcmp (optarg, "textoff") == 0)
  2085. link_info.error_textrel = FALSE;
  2086. EOF
  2087. fi
  2088. if test -n "$PARSE_AND_LIST_ARGS_CASE_Z" ; then
  2089. fragment <<EOF
  2090. $PARSE_AND_LIST_ARGS_CASE_Z
  2091. EOF
  2092. fi
  2093. fragment <<EOF
  2094. else
  2095. einfo (_("%P: warning: -z %s ignored.\n"), optarg);
  2096. break;
  2097. EOF
  2098. if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then
  2099. fragment <<EOF
  2100. $PARSE_AND_LIST_ARGS_CASES
  2101. EOF
  2102. fi
  2103. fragment <<EOF
  2104. }
  2105. return TRUE;
  2106. }
  2107. EOF
  2108. if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
  2109. gld_list_options="gld${EMULATION_NAME}_list_options"
  2110. if test -n "$PARSE_AND_LIST_OPTIONS"; then
  2111. fragment <<EOF
  2112. static void
  2113. gld${EMULATION_NAME}_list_options (FILE * file)
  2114. {
  2115. EOF
  2116. if test -n "$PARSE_AND_LIST_OPTIONS" ; then
  2117. fragment <<EOF
  2118. $PARSE_AND_LIST_OPTIONS
  2119. EOF
  2120. fi
  2121. fragment <<EOF
  2122. }
  2123. EOF
  2124. else
  2125. gld_list_options="NULL"
  2126. fi
  2127. if test -n "$PARSE_AND_LIST_EPILOGUE" ; then
  2128. fragment <<EOF
  2129. $PARSE_AND_LIST_EPILOGUE
  2130. EOF
  2131. fi
  2132. fi
  2133. fragment <<EOF
  2134. struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
  2135. {
  2136. ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse},
  2137. ${LDEMUL_SYSLIB-syslib_default},
  2138. ${LDEMUL_HLL-hll_default},
  2139. ${LDEMUL_AFTER_PARSE-gld${EMULATION_NAME}_after_parse},
  2140. ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open},
  2141. ${LDEMUL_AFTER_ALLOCATION-gld${EMULATION_NAME}_after_allocation},
  2142. ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default},
  2143. ${LDEMUL_CHOOSE_TARGET-ldemul_default_target},
  2144. ${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation},
  2145. ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script},
  2146. "${EMULATION_NAME}",
  2147. "${OUTPUT_FORMAT}",
  2148. ${LDEMUL_FINISH-finish_default},
  2149. ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL},
  2150. ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive},
  2151. ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan},
  2152. ${LDEMUL_SET_SYMBOLS-NULL},
  2153. ${LDEMUL_PARSE_ARGS-NULL},
  2154. gld${EMULATION_NAME}_add_options,
  2155. gld${EMULATION_NAME}_handle_option,
  2156. ${LDEMUL_UNRECOGNIZED_FILE-NULL},
  2157. ${LDEMUL_LIST_OPTIONS-${gld_list_options}},
  2158. ${LDEMUL_RECOGNIZED_FILE-gld${EMULATION_NAME}_load_symbols},
  2159. ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL},
  2160. ${LDEMUL_NEW_VERS_PATTERN-NULL},
  2161. ${LDEMUL_EXTRA_MAP_FILE_TEXT-NULL}
  2162. };
  2163. EOF