coff-arm.c 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561
  1. /* BFD back-end for ARM COFF files.
  2. Copyright (C) 1990-2015 Free Software Foundation, Inc.
  3. Written by Cygnus Support.
  4. This file is part of BFD, the Binary File Descriptor library.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. MA 02110-1301, USA. */
  17. #include "sysdep.h"
  18. #include "bfd.h"
  19. #include "libbfd.h"
  20. #include "coff/arm.h"
  21. #include "coff/internal.h"
  22. #ifdef COFF_WITH_PE
  23. #include "coff/pe.h"
  24. #endif
  25. #include "libcoff.h"
  26. /* Macros for manipulation the bits in the flags field of the coff data
  27. structure. */
  28. #define APCS_26_FLAG(abfd) \
  29. (coff_data (abfd)->flags & F_APCS_26)
  30. #define APCS_FLOAT_FLAG(abfd) \
  31. (coff_data (abfd)->flags & F_APCS_FLOAT)
  32. #define PIC_FLAG(abfd) \
  33. (coff_data (abfd)->flags & F_PIC)
  34. #define APCS_SET(abfd) \
  35. (coff_data (abfd)->flags & F_APCS_SET)
  36. #define SET_APCS_FLAGS(abfd, flgs) \
  37. do \
  38. { \
  39. coff_data (abfd)->flags &= ~(F_APCS_26 | F_APCS_FLOAT | F_PIC); \
  40. coff_data (abfd)->flags |= (flgs) | F_APCS_SET; \
  41. } \
  42. while (0)
  43. #define INTERWORK_FLAG(abfd) \
  44. (coff_data (abfd)->flags & F_INTERWORK)
  45. #define INTERWORK_SET(abfd) \
  46. (coff_data (abfd)->flags & F_INTERWORK_SET)
  47. #define SET_INTERWORK_FLAG(abfd, flg) \
  48. do \
  49. { \
  50. coff_data (abfd)->flags &= ~F_INTERWORK; \
  51. coff_data (abfd)->flags |= (flg) | F_INTERWORK_SET; \
  52. } \
  53. while (0)
  54. #ifndef NUM_ELEM
  55. #define NUM_ELEM(a) ((sizeof (a)) / sizeof ((a)[0]))
  56. #endif
  57. typedef enum {bunknown, b9, b12, b23} thumb_pcrel_branchtype;
  58. /* Some typedefs for holding instructions. */
  59. typedef unsigned long int insn32;
  60. typedef unsigned short int insn16;
  61. /* The linker script knows the section names for placement.
  62. The entry_names are used to do simple name mangling on the stubs.
  63. Given a function name, and its type, the stub can be found. The
  64. name can be changed. The only requirement is the %s be present. */
  65. #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
  66. #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
  67. #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
  68. #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
  69. /* Used by the assembler. */
  70. static bfd_reloc_status_type
  71. coff_arm_reloc (bfd *abfd,
  72. arelent *reloc_entry,
  73. asymbol *symbol ATTRIBUTE_UNUSED,
  74. void * data,
  75. asection *input_section ATTRIBUTE_UNUSED,
  76. bfd *output_bfd,
  77. char **error_message ATTRIBUTE_UNUSED)
  78. {
  79. symvalue diff;
  80. if (output_bfd == NULL)
  81. return bfd_reloc_continue;
  82. diff = reloc_entry->addend;
  83. #define DOIT(x) \
  84. x = ((x & ~howto->dst_mask) \
  85. | (((x & howto->src_mask) + diff) & howto->dst_mask))
  86. if (diff != 0)
  87. {
  88. reloc_howto_type *howto = reloc_entry->howto;
  89. unsigned char *addr = (unsigned char *) data + reloc_entry->address;
  90. switch (howto->size)
  91. {
  92. case 0:
  93. {
  94. char x = bfd_get_8 (abfd, addr);
  95. DOIT (x);
  96. bfd_put_8 (abfd, x, addr);
  97. }
  98. break;
  99. case 1:
  100. {
  101. short x = bfd_get_16 (abfd, addr);
  102. DOIT (x);
  103. bfd_put_16 (abfd, (bfd_vma) x, addr);
  104. }
  105. break;
  106. case 2:
  107. {
  108. long x = bfd_get_32 (abfd, addr);
  109. DOIT (x);
  110. bfd_put_32 (abfd, (bfd_vma) x, addr);
  111. }
  112. break;
  113. default:
  114. abort ();
  115. }
  116. }
  117. /* Now let bfd_perform_relocation finish everything up. */
  118. return bfd_reloc_continue;
  119. }
  120. /* If USER_LABEL_PREFIX is defined as "_" (see coff_arm_is_local_label_name()
  121. in this file), then TARGET_UNDERSCORE should be defined, otherwise it
  122. should not. */
  123. #ifndef TARGET_UNDERSCORE
  124. #define TARGET_UNDERSCORE '_'
  125. #endif
  126. #ifndef PCRELOFFSET
  127. #define PCRELOFFSET TRUE
  128. #endif
  129. /* These most certainly belong somewhere else. Just had to get rid of
  130. the manifest constants in the code. */
  131. #ifdef ARM_WINCE
  132. #define ARM_26D 0
  133. #define ARM_32 1
  134. #define ARM_RVA32 2
  135. #define ARM_26 3
  136. #define ARM_THUMB12 4
  137. #define ARM_SECTION 14
  138. #define ARM_SECREL 15
  139. #else
  140. #define ARM_8 0
  141. #define ARM_16 1
  142. #define ARM_32 2
  143. #define ARM_26 3
  144. #define ARM_DISP8 4
  145. #define ARM_DISP16 5
  146. #define ARM_DISP32 6
  147. #define ARM_26D 7
  148. /* 8 is unused. */
  149. #define ARM_NEG16 9
  150. #define ARM_NEG32 10
  151. #define ARM_RVA32 11
  152. #define ARM_THUMB9 12
  153. #define ARM_THUMB12 13
  154. #define ARM_THUMB23 14
  155. #endif
  156. static bfd_reloc_status_type aoutarm_fix_pcrel_26_done
  157. (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  158. static bfd_reloc_status_type aoutarm_fix_pcrel_26
  159. (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  160. static bfd_reloc_status_type coff_thumb_pcrel_12
  161. (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  162. #ifndef ARM_WINCE
  163. static bfd_reloc_status_type coff_thumb_pcrel_9
  164. (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  165. static bfd_reloc_status_type coff_thumb_pcrel_23
  166. (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  167. #endif
  168. static reloc_howto_type aoutarm_std_reloc_howto[] =
  169. {
  170. #ifdef ARM_WINCE
  171. HOWTO (ARM_26D,
  172. 2,
  173. 2,
  174. 24,
  175. TRUE,
  176. 0,
  177. complain_overflow_dont,
  178. aoutarm_fix_pcrel_26_done,
  179. "ARM_26D",
  180. TRUE, /* partial_inplace. */
  181. 0x00ffffff,
  182. 0x0,
  183. PCRELOFFSET),
  184. HOWTO (ARM_32,
  185. 0,
  186. 2,
  187. 32,
  188. FALSE,
  189. 0,
  190. complain_overflow_bitfield,
  191. coff_arm_reloc,
  192. "ARM_32",
  193. TRUE, /* partial_inplace. */
  194. 0xffffffff,
  195. 0xffffffff,
  196. PCRELOFFSET),
  197. HOWTO (ARM_RVA32,
  198. 0,
  199. 2,
  200. 32,
  201. FALSE,
  202. 0,
  203. complain_overflow_bitfield,
  204. coff_arm_reloc,
  205. "ARM_RVA32",
  206. TRUE, /* partial_inplace. */
  207. 0xffffffff,
  208. 0xffffffff,
  209. PCRELOFFSET),
  210. HOWTO (ARM_26,
  211. 2,
  212. 2,
  213. 24,
  214. TRUE,
  215. 0,
  216. complain_overflow_signed,
  217. aoutarm_fix_pcrel_26 ,
  218. "ARM_26",
  219. FALSE,
  220. 0x00ffffff,
  221. 0x00ffffff,
  222. PCRELOFFSET),
  223. HOWTO (ARM_THUMB12,
  224. 1,
  225. 1,
  226. 11,
  227. TRUE,
  228. 0,
  229. complain_overflow_signed,
  230. coff_thumb_pcrel_12 ,
  231. "ARM_THUMB12",
  232. FALSE,
  233. 0x000007ff,
  234. 0x000007ff,
  235. PCRELOFFSET),
  236. EMPTY_HOWTO (-1),
  237. EMPTY_HOWTO (-1),
  238. EMPTY_HOWTO (-1),
  239. EMPTY_HOWTO (-1),
  240. EMPTY_HOWTO (-1),
  241. EMPTY_HOWTO (-1),
  242. EMPTY_HOWTO (-1),
  243. EMPTY_HOWTO (-1),
  244. EMPTY_HOWTO (-1),
  245. HOWTO (ARM_SECTION,
  246. 0,
  247. 1,
  248. 16,
  249. FALSE,
  250. 0,
  251. complain_overflow_bitfield,
  252. coff_arm_reloc,
  253. "ARM_SECTION",
  254. TRUE, /* partial_inplace. */
  255. 0x0000ffff,
  256. 0x0000ffff,
  257. PCRELOFFSET),
  258. HOWTO (ARM_SECREL,
  259. 0,
  260. 2,
  261. 32,
  262. FALSE,
  263. 0,
  264. complain_overflow_bitfield,
  265. coff_arm_reloc,
  266. "ARM_SECREL",
  267. TRUE, /* partial_inplace. */
  268. 0xffffffff,
  269. 0xffffffff,
  270. PCRELOFFSET),
  271. #else /* not ARM_WINCE */
  272. HOWTO (ARM_8,
  273. 0,
  274. 0,
  275. 8,
  276. FALSE,
  277. 0,
  278. complain_overflow_bitfield,
  279. coff_arm_reloc,
  280. "ARM_8",
  281. TRUE,
  282. 0x000000ff,
  283. 0x000000ff,
  284. PCRELOFFSET),
  285. HOWTO (ARM_16,
  286. 0,
  287. 1,
  288. 16,
  289. FALSE,
  290. 0,
  291. complain_overflow_bitfield,
  292. coff_arm_reloc,
  293. "ARM_16",
  294. TRUE,
  295. 0x0000ffff,
  296. 0x0000ffff,
  297. PCRELOFFSET),
  298. HOWTO (ARM_32,
  299. 0,
  300. 2,
  301. 32,
  302. FALSE,
  303. 0,
  304. complain_overflow_bitfield,
  305. coff_arm_reloc,
  306. "ARM_32",
  307. TRUE,
  308. 0xffffffff,
  309. 0xffffffff,
  310. PCRELOFFSET),
  311. HOWTO (ARM_26,
  312. 2,
  313. 2,
  314. 24,
  315. TRUE,
  316. 0,
  317. complain_overflow_signed,
  318. aoutarm_fix_pcrel_26 ,
  319. "ARM_26",
  320. FALSE,
  321. 0x00ffffff,
  322. 0x00ffffff,
  323. PCRELOFFSET),
  324. HOWTO (ARM_DISP8,
  325. 0,
  326. 0,
  327. 8,
  328. TRUE,
  329. 0,
  330. complain_overflow_signed,
  331. coff_arm_reloc,
  332. "ARM_DISP8",
  333. TRUE,
  334. 0x000000ff,
  335. 0x000000ff,
  336. TRUE),
  337. HOWTO (ARM_DISP16,
  338. 0,
  339. 1,
  340. 16,
  341. TRUE,
  342. 0,
  343. complain_overflow_signed,
  344. coff_arm_reloc,
  345. "ARM_DISP16",
  346. TRUE,
  347. 0x0000ffff,
  348. 0x0000ffff,
  349. TRUE),
  350. HOWTO (ARM_DISP32,
  351. 0,
  352. 2,
  353. 32,
  354. TRUE,
  355. 0,
  356. complain_overflow_signed,
  357. coff_arm_reloc,
  358. "ARM_DISP32",
  359. TRUE,
  360. 0xffffffff,
  361. 0xffffffff,
  362. TRUE),
  363. HOWTO (ARM_26D,
  364. 2,
  365. 2,
  366. 24,
  367. FALSE,
  368. 0,
  369. complain_overflow_dont,
  370. aoutarm_fix_pcrel_26_done,
  371. "ARM_26D",
  372. TRUE,
  373. 0x00ffffff,
  374. 0x0,
  375. FALSE),
  376. /* 8 is unused */
  377. EMPTY_HOWTO (-1),
  378. HOWTO (ARM_NEG16,
  379. 0,
  380. -1,
  381. 16,
  382. FALSE,
  383. 0,
  384. complain_overflow_bitfield,
  385. coff_arm_reloc,
  386. "ARM_NEG16",
  387. TRUE,
  388. 0x0000ffff,
  389. 0x0000ffff,
  390. FALSE),
  391. HOWTO (ARM_NEG32,
  392. 0,
  393. -2,
  394. 32,
  395. FALSE,
  396. 0,
  397. complain_overflow_bitfield,
  398. coff_arm_reloc,
  399. "ARM_NEG32",
  400. TRUE,
  401. 0xffffffff,
  402. 0xffffffff,
  403. FALSE),
  404. HOWTO (ARM_RVA32,
  405. 0,
  406. 2,
  407. 32,
  408. FALSE,
  409. 0,
  410. complain_overflow_bitfield,
  411. coff_arm_reloc,
  412. "ARM_RVA32",
  413. TRUE,
  414. 0xffffffff,
  415. 0xffffffff,
  416. PCRELOFFSET),
  417. HOWTO (ARM_THUMB9,
  418. 1,
  419. 1,
  420. 8,
  421. TRUE,
  422. 0,
  423. complain_overflow_signed,
  424. coff_thumb_pcrel_9 ,
  425. "ARM_THUMB9",
  426. FALSE,
  427. 0x000000ff,
  428. 0x000000ff,
  429. PCRELOFFSET),
  430. HOWTO (ARM_THUMB12,
  431. 1,
  432. 1,
  433. 11,
  434. TRUE,
  435. 0,
  436. complain_overflow_signed,
  437. coff_thumb_pcrel_12 ,
  438. "ARM_THUMB12",
  439. FALSE,
  440. 0x000007ff,
  441. 0x000007ff,
  442. PCRELOFFSET),
  443. HOWTO (ARM_THUMB23,
  444. 1,
  445. 2,
  446. 22,
  447. TRUE,
  448. 0,
  449. complain_overflow_signed,
  450. coff_thumb_pcrel_23 ,
  451. "ARM_THUMB23",
  452. FALSE,
  453. 0x07ff07ff,
  454. 0x07ff07ff,
  455. PCRELOFFSET)
  456. #endif /* not ARM_WINCE */
  457. };
  458. #define NUM_RELOCS NUM_ELEM (aoutarm_std_reloc_howto)
  459. #ifdef COFF_WITH_PE
  460. /* Return TRUE if this relocation should
  461. appear in the output .reloc section. */
  462. static bfd_boolean
  463. in_reloc_p (bfd * abfd ATTRIBUTE_UNUSED,
  464. reloc_howto_type * howto)
  465. {
  466. return !howto->pc_relative && howto->type != ARM_RVA32;
  467. }
  468. #endif
  469. #define RTYPE2HOWTO(cache_ptr, dst) \
  470. (cache_ptr)->howto = \
  471. (dst)->r_type < NUM_RELOCS \
  472. ? aoutarm_std_reloc_howto + (dst)->r_type \
  473. : NULL
  474. #define coff_rtype_to_howto coff_arm_rtype_to_howto
  475. static reloc_howto_type *
  476. coff_arm_rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
  477. asection *sec,
  478. struct internal_reloc *rel,
  479. struct coff_link_hash_entry *h ATTRIBUTE_UNUSED,
  480. struct internal_syment *sym ATTRIBUTE_UNUSED,
  481. bfd_vma *addendp)
  482. {
  483. reloc_howto_type * howto;
  484. if (rel->r_type >= NUM_RELOCS)
  485. return NULL;
  486. howto = aoutarm_std_reloc_howto + rel->r_type;
  487. if (rel->r_type == ARM_RVA32)
  488. *addendp -= pe_data (sec->output_section->owner)->pe_opthdr.ImageBase;
  489. #if defined COFF_WITH_PE && defined ARM_WINCE
  490. if (rel->r_type == ARM_SECREL)
  491. {
  492. bfd_vma osect_vma;
  493. if (h && (h->type == bfd_link_hash_defined
  494. || h->type == bfd_link_hash_defweak))
  495. osect_vma = h->root.u.def.section->output_section->vma;
  496. else
  497. {
  498. int i;
  499. /* Sigh, the only way to get the section to offset against
  500. is to find it the hard way. */
  501. for (sec = abfd->sections, i = 1; i < sym->n_scnum; i++)
  502. sec = sec->next;
  503. osect_vma = sec->output_section->vma;
  504. }
  505. *addendp -= osect_vma;
  506. }
  507. #endif
  508. return howto;
  509. }
  510. /* Used by the assembler. */
  511. static bfd_reloc_status_type
  512. aoutarm_fix_pcrel_26_done (bfd *abfd ATTRIBUTE_UNUSED,
  513. arelent *reloc_entry ATTRIBUTE_UNUSED,
  514. asymbol *symbol ATTRIBUTE_UNUSED,
  515. void * data ATTRIBUTE_UNUSED,
  516. asection *input_section ATTRIBUTE_UNUSED,
  517. bfd *output_bfd ATTRIBUTE_UNUSED,
  518. char **error_message ATTRIBUTE_UNUSED)
  519. {
  520. /* This is dead simple at present. */
  521. return bfd_reloc_ok;
  522. }
  523. /* Used by the assembler. */
  524. static bfd_reloc_status_type
  525. aoutarm_fix_pcrel_26 (bfd *abfd,
  526. arelent *reloc_entry,
  527. asymbol *symbol,
  528. void * data,
  529. asection *input_section,
  530. bfd *output_bfd,
  531. char **error_message ATTRIBUTE_UNUSED)
  532. {
  533. bfd_vma relocation;
  534. bfd_size_type addr = reloc_entry->address;
  535. long target = bfd_get_32 (abfd, (bfd_byte *) data + addr);
  536. bfd_reloc_status_type flag = bfd_reloc_ok;
  537. /* If this is an undefined symbol, return error. */
  538. if (bfd_is_und_section (symbol->section)
  539. && (symbol->flags & BSF_WEAK) == 0)
  540. return output_bfd ? bfd_reloc_continue : bfd_reloc_undefined;
  541. /* If the sections are different, and we are doing a partial relocation,
  542. just ignore it for now. */
  543. if (symbol->section->name != input_section->name
  544. && output_bfd != (bfd *)NULL)
  545. return bfd_reloc_continue;
  546. relocation = (target & 0x00ffffff) << 2;
  547. relocation = (relocation ^ 0x02000000) - 0x02000000; /* Sign extend. */
  548. relocation += symbol->value;
  549. relocation += symbol->section->output_section->vma;
  550. relocation += symbol->section->output_offset;
  551. relocation += reloc_entry->addend;
  552. relocation -= input_section->output_section->vma;
  553. relocation -= input_section->output_offset;
  554. relocation -= addr;
  555. if (relocation & 3)
  556. return bfd_reloc_overflow;
  557. /* Check for overflow. */
  558. if (relocation & 0x02000000)
  559. {
  560. if ((relocation & ~ (bfd_vma) 0x03ffffff) != ~ (bfd_vma) 0x03ffffff)
  561. flag = bfd_reloc_overflow;
  562. }
  563. else if (relocation & ~(bfd_vma) 0x03ffffff)
  564. flag = bfd_reloc_overflow;
  565. target &= ~0x00ffffff;
  566. target |= (relocation >> 2) & 0x00ffffff;
  567. bfd_put_32 (abfd, (bfd_vma) target, (bfd_byte *) data + addr);
  568. /* Now the ARM magic... Change the reloc type so that it is marked as done.
  569. Strictly this is only necessary if we are doing a partial relocation. */
  570. reloc_entry->howto = &aoutarm_std_reloc_howto[ARM_26D];
  571. return flag;
  572. }
  573. static bfd_reloc_status_type
  574. coff_thumb_pcrel_common (bfd *abfd,
  575. arelent *reloc_entry,
  576. asymbol *symbol,
  577. void * data,
  578. asection *input_section,
  579. bfd *output_bfd,
  580. char **error_message ATTRIBUTE_UNUSED,
  581. thumb_pcrel_branchtype btype)
  582. {
  583. bfd_vma relocation = 0;
  584. bfd_size_type addr = reloc_entry->address;
  585. long target = bfd_get_32 (abfd, (bfd_byte *) data + addr);
  586. bfd_reloc_status_type flag = bfd_reloc_ok;
  587. bfd_vma dstmsk;
  588. bfd_vma offmsk;
  589. bfd_vma signbit;
  590. /* NOTE: This routine is currently used by GAS, but not by the link
  591. phase. */
  592. switch (btype)
  593. {
  594. case b9:
  595. dstmsk = 0x000000ff;
  596. offmsk = 0x000001fe;
  597. signbit = 0x00000100;
  598. break;
  599. case b12:
  600. dstmsk = 0x000007ff;
  601. offmsk = 0x00000ffe;
  602. signbit = 0x00000800;
  603. break;
  604. case b23:
  605. dstmsk = 0x07ff07ff;
  606. offmsk = 0x007fffff;
  607. signbit = 0x00400000;
  608. break;
  609. default:
  610. abort ();
  611. }
  612. /* If this is an undefined symbol, return error. */
  613. if (bfd_is_und_section (symbol->section)
  614. && (symbol->flags & BSF_WEAK) == 0)
  615. return output_bfd ? bfd_reloc_continue : bfd_reloc_undefined;
  616. /* If the sections are different, and we are doing a partial relocation,
  617. just ignore it for now. */
  618. if (symbol->section->name != input_section->name
  619. && output_bfd != (bfd *)NULL)
  620. return bfd_reloc_continue;
  621. switch (btype)
  622. {
  623. case b9:
  624. case b12:
  625. relocation = ((target & dstmsk) << 1);
  626. break;
  627. case b23:
  628. if (bfd_big_endian (abfd))
  629. relocation = ((target & 0x7ff) << 1) | ((target & 0x07ff0000) >> 4);
  630. else
  631. relocation = ((target & 0x7ff) << 12) | ((target & 0x07ff0000) >> 15);
  632. break;
  633. default:
  634. abort ();
  635. }
  636. relocation = (relocation ^ signbit) - signbit; /* Sign extend. */
  637. relocation += symbol->value;
  638. relocation += symbol->section->output_section->vma;
  639. relocation += symbol->section->output_offset;
  640. relocation += reloc_entry->addend;
  641. relocation -= input_section->output_section->vma;
  642. relocation -= input_section->output_offset;
  643. relocation -= addr;
  644. if (relocation & 1)
  645. return bfd_reloc_overflow;
  646. /* Check for overflow. */
  647. if (relocation & signbit)
  648. {
  649. if ((relocation & ~offmsk) != ~offmsk)
  650. flag = bfd_reloc_overflow;
  651. }
  652. else if (relocation & ~offmsk)
  653. flag = bfd_reloc_overflow;
  654. target &= ~dstmsk;
  655. switch (btype)
  656. {
  657. case b9:
  658. case b12:
  659. target |= (relocation >> 1);
  660. break;
  661. case b23:
  662. if (bfd_big_endian (abfd))
  663. target |= (((relocation & 0xfff) >> 1)
  664. | ((relocation << 4) & 0x07ff0000));
  665. else
  666. target |= (((relocation & 0xffe) << 15)
  667. | ((relocation >> 12) & 0x7ff));
  668. break;
  669. default:
  670. abort ();
  671. }
  672. bfd_put_32 (abfd, (bfd_vma) target, (bfd_byte *) data + addr);
  673. /* Now the ARM magic... Change the reloc type so that it is marked as done.
  674. Strictly this is only necessary if we are doing a partial relocation. */
  675. reloc_entry->howto = & aoutarm_std_reloc_howto [ARM_26D];
  676. /* TODO: We should possibly have DONE entries for the THUMB PCREL relocations. */
  677. return flag;
  678. }
  679. #ifndef ARM_WINCE
  680. static bfd_reloc_status_type
  681. coff_thumb_pcrel_23 (bfd *abfd,
  682. arelent *reloc_entry,
  683. asymbol *symbol,
  684. void * data,
  685. asection *input_section,
  686. bfd *output_bfd,
  687. char **error_message)
  688. {
  689. return coff_thumb_pcrel_common (abfd, reloc_entry, symbol, data,
  690. input_section, output_bfd, error_message,
  691. b23);
  692. }
  693. static bfd_reloc_status_type
  694. coff_thumb_pcrel_9 (bfd *abfd,
  695. arelent *reloc_entry,
  696. asymbol *symbol,
  697. void * data,
  698. asection *input_section,
  699. bfd *output_bfd,
  700. char **error_message)
  701. {
  702. return coff_thumb_pcrel_common (abfd, reloc_entry, symbol, data,
  703. input_section, output_bfd, error_message,
  704. b9);
  705. }
  706. #endif /* not ARM_WINCE */
  707. static bfd_reloc_status_type
  708. coff_thumb_pcrel_12 (bfd *abfd,
  709. arelent *reloc_entry,
  710. asymbol *symbol,
  711. void * data,
  712. asection *input_section,
  713. bfd *output_bfd,
  714. char **error_message)
  715. {
  716. return coff_thumb_pcrel_common (abfd, reloc_entry, symbol, data,
  717. input_section, output_bfd, error_message,
  718. b12);
  719. }
  720. static const struct reloc_howto_struct *
  721. coff_arm_reloc_type_lookup (bfd * abfd, bfd_reloc_code_real_type code)
  722. {
  723. #define ASTD(i,j) case i: return aoutarm_std_reloc_howto + j
  724. if (code == BFD_RELOC_CTOR)
  725. switch (bfd_arch_bits_per_address (abfd))
  726. {
  727. case 32:
  728. code = BFD_RELOC_32;
  729. break;
  730. default:
  731. return NULL;
  732. }
  733. switch (code)
  734. {
  735. #ifdef ARM_WINCE
  736. ASTD (BFD_RELOC_32, ARM_32);
  737. ASTD (BFD_RELOC_RVA, ARM_RVA32);
  738. ASTD (BFD_RELOC_ARM_PCREL_BRANCH, ARM_26);
  739. ASTD (BFD_RELOC_THUMB_PCREL_BRANCH12, ARM_THUMB12);
  740. ASTD (BFD_RELOC_32_SECREL, ARM_SECREL);
  741. #else
  742. ASTD (BFD_RELOC_8, ARM_8);
  743. ASTD (BFD_RELOC_16, ARM_16);
  744. ASTD (BFD_RELOC_32, ARM_32);
  745. ASTD (BFD_RELOC_ARM_PCREL_BRANCH, ARM_26);
  746. ASTD (BFD_RELOC_ARM_PCREL_BLX, ARM_26);
  747. ASTD (BFD_RELOC_8_PCREL, ARM_DISP8);
  748. ASTD (BFD_RELOC_16_PCREL, ARM_DISP16);
  749. ASTD (BFD_RELOC_32_PCREL, ARM_DISP32);
  750. ASTD (BFD_RELOC_RVA, ARM_RVA32);
  751. ASTD (BFD_RELOC_THUMB_PCREL_BRANCH9, ARM_THUMB9);
  752. ASTD (BFD_RELOC_THUMB_PCREL_BRANCH12, ARM_THUMB12);
  753. ASTD (BFD_RELOC_THUMB_PCREL_BRANCH23, ARM_THUMB23);
  754. ASTD (BFD_RELOC_THUMB_PCREL_BLX, ARM_THUMB23);
  755. #endif
  756. default: return NULL;
  757. }
  758. }
  759. static reloc_howto_type *
  760. coff_arm_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  761. const char *r_name)
  762. {
  763. unsigned int i;
  764. for (i = 0;
  765. i < (sizeof (aoutarm_std_reloc_howto)
  766. / sizeof (aoutarm_std_reloc_howto[0]));
  767. i++)
  768. if (aoutarm_std_reloc_howto[i].name != NULL
  769. && strcasecmp (aoutarm_std_reloc_howto[i].name, r_name) == 0)
  770. return &aoutarm_std_reloc_howto[i];
  771. return NULL;
  772. }
  773. #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 2
  774. #define COFF_PAGE_SIZE 0x1000
  775. /* Turn a howto into a reloc nunmber. */
  776. #define SELECT_RELOC(x,howto) { x.r_type = howto->type; }
  777. #define BADMAG(x) ARMBADMAG(x)
  778. #define ARM 1 /* Customize coffcode.h. */
  779. #ifndef ARM_WINCE
  780. /* Make sure that the 'r_offset' field is copied properly
  781. so that identical binaries will compare the same. */
  782. #define SWAP_IN_RELOC_OFFSET H_GET_32
  783. #define SWAP_OUT_RELOC_OFFSET H_PUT_32
  784. #endif
  785. /* Extend the coff_link_hash_table structure with a few ARM specific fields.
  786. This allows us to store global data here without actually creating any
  787. global variables, which is a no-no in the BFD world. */
  788. struct coff_arm_link_hash_table
  789. {
  790. /* The original coff_link_hash_table structure. MUST be first field. */
  791. struct coff_link_hash_table root;
  792. /* The size in bytes of the section containing the Thumb-to-ARM glue. */
  793. bfd_size_type thumb_glue_size;
  794. /* The size in bytes of the section containing the ARM-to-Thumb glue. */
  795. bfd_size_type arm_glue_size;
  796. /* An arbitrary input BFD chosen to hold the glue sections. */
  797. bfd * bfd_of_glue_owner;
  798. /* Support interworking with old, non-interworking aware ARM code. */
  799. int support_old_code;
  800. };
  801. /* Get the ARM coff linker hash table from a link_info structure. */
  802. #define coff_arm_hash_table(info) \
  803. ((struct coff_arm_link_hash_table *) ((info)->hash))
  804. /* Create an ARM coff linker hash table. */
  805. static struct bfd_link_hash_table *
  806. coff_arm_link_hash_table_create (bfd * abfd)
  807. {
  808. struct coff_arm_link_hash_table * ret;
  809. bfd_size_type amt = sizeof (struct coff_arm_link_hash_table);
  810. ret = bfd_zmalloc (amt);
  811. if (ret == NULL)
  812. return NULL;
  813. if (!_bfd_coff_link_hash_table_init (&ret->root,
  814. abfd,
  815. _bfd_coff_link_hash_newfunc,
  816. sizeof (struct coff_link_hash_entry)))
  817. {
  818. free (ret);
  819. return NULL;
  820. }
  821. return & ret->root.root;
  822. }
  823. static bfd_boolean
  824. arm_emit_base_file_entry (struct bfd_link_info *info,
  825. bfd *output_bfd,
  826. asection *input_section,
  827. bfd_vma reloc_offset)
  828. {
  829. bfd_vma addr = (reloc_offset
  830. - input_section->vma
  831. + input_section->output_offset
  832. + input_section->output_section->vma);
  833. if (coff_data (output_bfd)->pe)
  834. addr -= pe_data (output_bfd)->pe_opthdr.ImageBase;
  835. if (fwrite (&addr, sizeof (addr), 1, (FILE *) info->base_file) == 1)
  836. return TRUE;
  837. bfd_set_error (bfd_error_system_call);
  838. return FALSE;
  839. }
  840. #ifndef ARM_WINCE
  841. /* The thumb form of a long branch is a bit finicky, because the offset
  842. encoding is split over two fields, each in it's own instruction. They
  843. can occur in any order. So given a thumb form of long branch, and an
  844. offset, insert the offset into the thumb branch and return finished
  845. instruction.
  846. It takes two thumb instructions to encode the target address. Each has
  847. 11 bits to invest. The upper 11 bits are stored in one (identified by
  848. H-0.. see below), the lower 11 bits are stored in the other (identified
  849. by H-1).
  850. Combine together and shifted left by 1 (it's a half word address) and
  851. there you have it.
  852. Op: 1111 = F,
  853. H-0, upper address-0 = 000
  854. Op: 1111 = F,
  855. H-1, lower address-0 = 800
  856. They can be ordered either way, but the arm tools I've seen always put
  857. the lower one first. It probably doesn't matter. krk@cygnus.com
  858. XXX: Actually the order does matter. The second instruction (H-1)
  859. moves the computed address into the PC, so it must be the second one
  860. in the sequence. The problem, however is that whilst little endian code
  861. stores the instructions in HI then LOW order, big endian code does the
  862. reverse. nickc@cygnus.com. */
  863. #define LOW_HI_ORDER 0xF800F000
  864. #define HI_LOW_ORDER 0xF000F800
  865. static insn32
  866. insert_thumb_branch (insn32 br_insn, int rel_off)
  867. {
  868. unsigned int low_bits;
  869. unsigned int high_bits;
  870. BFD_ASSERT ((rel_off & 1) != 1);
  871. rel_off >>= 1; /* Half word aligned address. */
  872. low_bits = rel_off & 0x000007FF; /* The bottom 11 bits. */
  873. high_bits = (rel_off >> 11) & 0x000007FF; /* The top 11 bits. */
  874. if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER)
  875. br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits;
  876. else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER)
  877. br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits;
  878. else
  879. /* FIXME: the BFD library should never abort except for internal errors
  880. - it should return an error status. */
  881. abort (); /* Error - not a valid branch instruction form. */
  882. return br_insn;
  883. }
  884. static struct coff_link_hash_entry *
  885. find_thumb_glue (struct bfd_link_info *info,
  886. const char *name,
  887. bfd *input_bfd)
  888. {
  889. char *tmp_name;
  890. struct coff_link_hash_entry *myh;
  891. bfd_size_type amt = strlen (name) + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1;
  892. tmp_name = bfd_malloc (amt);
  893. BFD_ASSERT (tmp_name);
  894. sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
  895. myh = coff_link_hash_lookup
  896. (coff_hash_table (info), tmp_name, FALSE, FALSE, TRUE);
  897. if (myh == NULL)
  898. /* xgettext:c-format */
  899. _bfd_error_handler (_("%B: unable to find THUMB glue '%s' for `%s'"),
  900. input_bfd, tmp_name, name);
  901. free (tmp_name);
  902. return myh;
  903. }
  904. #endif /* not ARM_WINCE */
  905. static struct coff_link_hash_entry *
  906. find_arm_glue (struct bfd_link_info *info,
  907. const char *name,
  908. bfd *input_bfd)
  909. {
  910. char *tmp_name;
  911. struct coff_link_hash_entry * myh;
  912. bfd_size_type amt = strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1;
  913. tmp_name = bfd_malloc (amt);
  914. BFD_ASSERT (tmp_name);
  915. sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
  916. myh = coff_link_hash_lookup
  917. (coff_hash_table (info), tmp_name, FALSE, FALSE, TRUE);
  918. if (myh == NULL)
  919. /* xgettext:c-format */
  920. _bfd_error_handler (_("%B: unable to find ARM glue '%s' for `%s'"),
  921. input_bfd, tmp_name, name);
  922. free (tmp_name);
  923. return myh;
  924. }
  925. /*
  926. ARM->Thumb glue:
  927. .arm
  928. __func_from_arm:
  929. ldr r12, __func_addr
  930. bx r12
  931. __func_addr:
  932. .word func @ behave as if you saw a ARM_32 reloc
  933. */
  934. #define ARM2THUMB_GLUE_SIZE 12
  935. static const insn32 a2t1_ldr_insn = 0xe59fc000;
  936. static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
  937. static const insn32 a2t3_func_addr_insn = 0x00000001;
  938. /*
  939. Thumb->ARM: Thumb->(non-interworking aware) ARM
  940. .thumb .thumb
  941. .align 2 .align 2
  942. __func_from_thumb: __func_from_thumb:
  943. bx pc push {r6, lr}
  944. nop ldr r6, __func_addr
  945. .arm mov lr, pc
  946. __func_change_to_arm: bx r6
  947. b func .arm
  948. __func_back_to_thumb:
  949. ldmia r13! {r6, lr}
  950. bx lr
  951. __func_addr:
  952. .word func
  953. */
  954. #define THUMB2ARM_GLUE_SIZE (globals->support_old_code ? 20 : 8)
  955. #ifndef ARM_WINCE
  956. static const insn16 t2a1_bx_pc_insn = 0x4778;
  957. static const insn16 t2a2_noop_insn = 0x46c0;
  958. static const insn32 t2a3_b_insn = 0xea000000;
  959. static const insn16 t2a1_push_insn = 0xb540;
  960. static const insn16 t2a2_ldr_insn = 0x4e03;
  961. static const insn16 t2a3_mov_insn = 0x46fe;
  962. static const insn16 t2a4_bx_insn = 0x4730;
  963. static const insn32 t2a5_pop_insn = 0xe8bd4040;
  964. static const insn32 t2a6_bx_insn = 0xe12fff1e;
  965. #endif
  966. /* TODO:
  967. We should really create new local (static) symbols in destination
  968. object for each stub we create. We should also create local
  969. (static) symbols within the stubs when switching between ARM and
  970. Thumb code. This will ensure that the debugger and disassembler
  971. can present a better view of stubs.
  972. We can treat stubs like literal sections, and for the THUMB9 ones
  973. (short addressing range) we should be able to insert the stubs
  974. between sections. i.e. the simplest approach (since relocations
  975. are done on a section basis) is to dump the stubs at the end of
  976. processing a section. That way we can always try and minimise the
  977. offset to and from a stub. However, this does not map well onto
  978. the way that the linker/BFD does its work: mapping all input
  979. sections to output sections via the linker script before doing
  980. all the processing.
  981. Unfortunately it may be easier to just to disallow short range
  982. Thumb->ARM stubs (i.e. no conditional inter-working branches,
  983. only branch-and-link (BL) calls. This will simplify the processing
  984. since we can then put all of the stubs into their own section.
  985. TODO:
  986. On a different subject, rather than complaining when a
  987. branch cannot fit in the number of bits available for the
  988. instruction we should generate a trampoline stub (needed to
  989. address the complete 32bit address space). */
  990. /* The standard COFF backend linker does not cope with the special
  991. Thumb BRANCH23 relocation. The alternative would be to split the
  992. BRANCH23 into seperate HI23 and LO23 relocations. However, it is a
  993. bit simpler simply providing our own relocation driver. */
  994. /* The reloc processing routine for the ARM/Thumb COFF linker. NOTE:
  995. This code is a very slightly modified copy of
  996. _bfd_coff_generic_relocate_section. It would be a much more
  997. maintainable solution to have a MACRO that could be expanded within
  998. _bfd_coff_generic_relocate_section that would only be provided for
  999. ARM/Thumb builds. It is only the code marked THUMBEXTENSION that
  1000. is different from the original. */
  1001. static bfd_boolean
  1002. coff_arm_relocate_section (bfd *output_bfd,
  1003. struct bfd_link_info *info,
  1004. bfd *input_bfd,
  1005. asection *input_section,
  1006. bfd_byte *contents,
  1007. struct internal_reloc *relocs,
  1008. struct internal_syment *syms,
  1009. asection **sections)
  1010. {
  1011. struct internal_reloc * rel;
  1012. struct internal_reloc * relend;
  1013. #ifndef ARM_WINCE
  1014. bfd_vma high_address = bfd_get_section_limit (input_bfd, input_section);
  1015. #endif
  1016. rel = relocs;
  1017. relend = rel + input_section->reloc_count;
  1018. for (; rel < relend; rel++)
  1019. {
  1020. int done = 0;
  1021. long symndx;
  1022. struct coff_link_hash_entry * h;
  1023. struct internal_syment * sym;
  1024. bfd_vma addend;
  1025. bfd_vma val;
  1026. reloc_howto_type * howto;
  1027. bfd_reloc_status_type rstat;
  1028. bfd_vma h_val;
  1029. symndx = rel->r_symndx;
  1030. if (symndx == -1)
  1031. {
  1032. h = NULL;
  1033. sym = NULL;
  1034. }
  1035. else
  1036. {
  1037. h = obj_coff_sym_hashes (input_bfd)[symndx];
  1038. sym = syms + symndx;
  1039. }
  1040. /* COFF treats common symbols in one of two ways. Either the
  1041. size of the symbol is included in the section contents, or it
  1042. is not. We assume that the size is not included, and force
  1043. the rtype_to_howto function to adjust the addend as needed. */
  1044. if (sym != NULL && sym->n_scnum != 0)
  1045. addend = - sym->n_value;
  1046. else
  1047. addend = 0;
  1048. howto = coff_rtype_to_howto (input_bfd, input_section, rel, h,
  1049. sym, &addend);
  1050. if (howto == NULL)
  1051. return FALSE;
  1052. /* The relocation_section function will skip pcrel_offset relocs
  1053. when doing a relocatable link. However, we want to convert
  1054. ARM_26 to ARM_26D relocs if possible. We return a fake howto in
  1055. this case without pcrel_offset set, and adjust the addend to
  1056. compensate. 'partial_inplace' is also set, since we want 'done'
  1057. relocations to be reflected in section's data. */
  1058. if (rel->r_type == ARM_26
  1059. && h != NULL
  1060. && bfd_link_relocatable (info)
  1061. && (h->root.type == bfd_link_hash_defined
  1062. || h->root.type == bfd_link_hash_defweak)
  1063. && (h->root.u.def.section->output_section
  1064. == input_section->output_section))
  1065. {
  1066. static reloc_howto_type fake_arm26_reloc =
  1067. HOWTO (ARM_26,
  1068. 2,
  1069. 2,
  1070. 24,
  1071. TRUE,
  1072. 0,
  1073. complain_overflow_signed,
  1074. aoutarm_fix_pcrel_26 ,
  1075. "ARM_26",
  1076. TRUE,
  1077. 0x00ffffff,
  1078. 0x00ffffff,
  1079. FALSE);
  1080. addend -= rel->r_vaddr - input_section->vma;
  1081. #ifdef ARM_WINCE
  1082. /* FIXME: I don't know why, but the hack is necessary for correct
  1083. generation of bl's instruction offset. */
  1084. addend -= 8;
  1085. #endif
  1086. howto = & fake_arm26_reloc;
  1087. }
  1088. #ifdef ARM_WINCE
  1089. /* MS ARM-CE makes the reloc relative to the opcode's pc, not
  1090. the next opcode's pc, so is off by one. */
  1091. if (howto->pc_relative && !bfd_link_relocatable (info))
  1092. addend -= 8;
  1093. #endif
  1094. /* If we are doing a relocatable link, then we can just ignore
  1095. a PC relative reloc that is pcrel_offset. It will already
  1096. have the correct value. If this is not a relocatable link,
  1097. then we should ignore the symbol value. */
  1098. if (howto->pc_relative && howto->pcrel_offset)
  1099. {
  1100. if (bfd_link_relocatable (info))
  1101. continue;
  1102. /* FIXME - it is not clear which targets need this next test
  1103. and which do not. It is known that it is needed for the
  1104. VxWorks and EPOC-PE targets, but it is also known that it
  1105. was suppressed for other ARM targets. This ought to be
  1106. sorted out one day. */
  1107. #ifdef ARM_COFF_BUGFIX
  1108. /* We must not ignore the symbol value. If the symbol is
  1109. within the same section, the relocation should have already
  1110. been fixed, but if it is not, we'll be handed a reloc into
  1111. the beginning of the symbol's section, so we must not cancel
  1112. out the symbol's value, otherwise we'll be adding it in
  1113. twice. */
  1114. if (sym != NULL && sym->n_scnum != 0)
  1115. addend += sym->n_value;
  1116. #endif
  1117. }
  1118. val = 0;
  1119. if (h == NULL)
  1120. {
  1121. asection *sec;
  1122. if (symndx == -1)
  1123. {
  1124. sec = bfd_abs_section_ptr;
  1125. val = 0;
  1126. }
  1127. else
  1128. {
  1129. sec = sections[symndx];
  1130. val = (sec->output_section->vma
  1131. + sec->output_offset
  1132. + sym->n_value
  1133. - sec->vma);
  1134. }
  1135. }
  1136. else
  1137. {
  1138. /* We don't output the stubs if we are generating a
  1139. relocatable output file, since we may as well leave the
  1140. stub generation to the final linker pass. If we fail to
  1141. verify that the name is defined, we'll try to build stubs
  1142. for an undefined name... */
  1143. if (! bfd_link_relocatable (info)
  1144. && ( h->root.type == bfd_link_hash_defined
  1145. || h->root.type == bfd_link_hash_defweak))
  1146. {
  1147. asection * h_sec = h->root.u.def.section;
  1148. const char * name = h->root.root.string;
  1149. /* h locates the symbol referenced in the reloc. */
  1150. h_val = (h->root.u.def.value
  1151. + h_sec->output_section->vma
  1152. + h_sec->output_offset);
  1153. if (howto->type == ARM_26)
  1154. {
  1155. if ( h->symbol_class == C_THUMBSTATFUNC
  1156. || h->symbol_class == C_THUMBEXTFUNC)
  1157. {
  1158. /* Arm code calling a Thumb function. */
  1159. unsigned long int tmp;
  1160. bfd_vma my_offset;
  1161. asection * s;
  1162. long int ret_offset;
  1163. struct coff_link_hash_entry * myh;
  1164. struct coff_arm_link_hash_table * globals;
  1165. myh = find_arm_glue (info, name, input_bfd);
  1166. if (myh == NULL)
  1167. return FALSE;
  1168. globals = coff_arm_hash_table (info);
  1169. BFD_ASSERT (globals != NULL);
  1170. BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
  1171. my_offset = myh->root.u.def.value;
  1172. s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
  1173. ARM2THUMB_GLUE_SECTION_NAME);
  1174. BFD_ASSERT (s != NULL);
  1175. BFD_ASSERT (s->contents != NULL);
  1176. BFD_ASSERT (s->output_section != NULL);
  1177. if ((my_offset & 0x01) == 0x01)
  1178. {
  1179. if (h_sec->owner != NULL
  1180. && INTERWORK_SET (h_sec->owner)
  1181. && ! INTERWORK_FLAG (h_sec->owner))
  1182. _bfd_error_handler
  1183. /* xgettext:c-format */
  1184. (_("%B(%s): warning: interworking not enabled.\n"
  1185. " first occurrence: %B: arm call to thumb"),
  1186. h_sec->owner, input_bfd, name);
  1187. --my_offset;
  1188. myh->root.u.def.value = my_offset;
  1189. bfd_put_32 (output_bfd, (bfd_vma) a2t1_ldr_insn,
  1190. s->contents + my_offset);
  1191. bfd_put_32 (output_bfd, (bfd_vma) a2t2_bx_r12_insn,
  1192. s->contents + my_offset + 4);
  1193. /* It's a thumb address. Add the low order bit. */
  1194. bfd_put_32 (output_bfd, h_val | a2t3_func_addr_insn,
  1195. s->contents + my_offset + 8);
  1196. if (info->base_file
  1197. && !arm_emit_base_file_entry (info, output_bfd,
  1198. s, my_offset + 8))
  1199. return FALSE;
  1200. }
  1201. BFD_ASSERT (my_offset <= globals->arm_glue_size);
  1202. tmp = bfd_get_32 (input_bfd, contents + rel->r_vaddr
  1203. - input_section->vma);
  1204. tmp = tmp & 0xFF000000;
  1205. /* Somehow these are both 4 too far, so subtract 8. */
  1206. ret_offset =
  1207. s->output_offset
  1208. + my_offset
  1209. + s->output_section->vma
  1210. - (input_section->output_offset
  1211. + input_section->output_section->vma
  1212. + rel->r_vaddr)
  1213. - 8;
  1214. tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
  1215. bfd_put_32 (output_bfd, (bfd_vma) tmp,
  1216. contents + rel->r_vaddr - input_section->vma);
  1217. done = 1;
  1218. }
  1219. }
  1220. #ifndef ARM_WINCE
  1221. /* Note: We used to check for ARM_THUMB9 and ARM_THUMB12. */
  1222. else if (howto->type == ARM_THUMB23)
  1223. {
  1224. if ( h->symbol_class == C_EXT
  1225. || h->symbol_class == C_STAT
  1226. || h->symbol_class == C_LABEL)
  1227. {
  1228. /* Thumb code calling an ARM function. */
  1229. asection * s = 0;
  1230. bfd_vma my_offset;
  1231. unsigned long int tmp;
  1232. long int ret_offset;
  1233. struct coff_link_hash_entry * myh;
  1234. struct coff_arm_link_hash_table * globals;
  1235. myh = find_thumb_glue (info, name, input_bfd);
  1236. if (myh == NULL)
  1237. return FALSE;
  1238. globals = coff_arm_hash_table (info);
  1239. BFD_ASSERT (globals != NULL);
  1240. BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
  1241. my_offset = myh->root.u.def.value;
  1242. s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
  1243. THUMB2ARM_GLUE_SECTION_NAME);
  1244. BFD_ASSERT (s != NULL);
  1245. BFD_ASSERT (s->contents != NULL);
  1246. BFD_ASSERT (s->output_section != NULL);
  1247. if ((my_offset & 0x01) == 0x01)
  1248. {
  1249. if (h_sec->owner != NULL
  1250. && INTERWORK_SET (h_sec->owner)
  1251. && ! INTERWORK_FLAG (h_sec->owner)
  1252. && ! globals->support_old_code)
  1253. _bfd_error_handler
  1254. /* xgettext:c-format */
  1255. (_("%B(%s): warning: interworking not enabled.\n"
  1256. " first occurrence: %B: thumb call to arm\n"
  1257. " consider relinking with --support-old-code enabled"),
  1258. h_sec->owner, input_bfd, name);
  1259. -- my_offset;
  1260. myh->root.u.def.value = my_offset;
  1261. if (globals->support_old_code)
  1262. {
  1263. bfd_put_16 (output_bfd, (bfd_vma) t2a1_push_insn,
  1264. s->contents + my_offset);
  1265. bfd_put_16 (output_bfd, (bfd_vma) t2a2_ldr_insn,
  1266. s->contents + my_offset + 2);
  1267. bfd_put_16 (output_bfd, (bfd_vma) t2a3_mov_insn,
  1268. s->contents + my_offset + 4);
  1269. bfd_put_16 (output_bfd, (bfd_vma) t2a4_bx_insn,
  1270. s->contents + my_offset + 6);
  1271. bfd_put_32 (output_bfd, (bfd_vma) t2a5_pop_insn,
  1272. s->contents + my_offset + 8);
  1273. bfd_put_32 (output_bfd, (bfd_vma) t2a6_bx_insn,
  1274. s->contents + my_offset + 12);
  1275. /* Store the address of the function in the last word of the stub. */
  1276. bfd_put_32 (output_bfd, h_val,
  1277. s->contents + my_offset + 16);
  1278. if (info->base_file
  1279. && !arm_emit_base_file_entry (info,
  1280. output_bfd, s,
  1281. my_offset + 16))
  1282. return FALSE;
  1283. }
  1284. else
  1285. {
  1286. bfd_put_16 (output_bfd, (bfd_vma) t2a1_bx_pc_insn,
  1287. s->contents + my_offset);
  1288. bfd_put_16 (output_bfd, (bfd_vma) t2a2_noop_insn,
  1289. s->contents + my_offset + 2);
  1290. ret_offset =
  1291. /* Address of destination of the stub. */
  1292. ((bfd_signed_vma) h_val)
  1293. - ((bfd_signed_vma)
  1294. /* Offset from the start of the current section to the start of the stubs. */
  1295. (s->output_offset
  1296. /* Offset of the start of this stub from the start of the stubs. */
  1297. + my_offset
  1298. /* Address of the start of the current section. */
  1299. + s->output_section->vma)
  1300. /* The branch instruction is 4 bytes into the stub. */
  1301. + 4
  1302. /* ARM branches work from the pc of the instruction + 8. */
  1303. + 8);
  1304. bfd_put_32 (output_bfd,
  1305. (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
  1306. s->contents + my_offset + 4);
  1307. }
  1308. }
  1309. BFD_ASSERT (my_offset <= globals->thumb_glue_size);
  1310. /* Now go back and fix up the original BL insn to point
  1311. to here. */
  1312. ret_offset =
  1313. s->output_offset
  1314. + my_offset
  1315. - (input_section->output_offset
  1316. + rel->r_vaddr)
  1317. -4;
  1318. tmp = bfd_get_32 (input_bfd, contents + rel->r_vaddr
  1319. - input_section->vma);
  1320. bfd_put_32 (output_bfd,
  1321. (bfd_vma) insert_thumb_branch (tmp,
  1322. ret_offset),
  1323. contents + rel->r_vaddr - input_section->vma);
  1324. done = 1;
  1325. }
  1326. }
  1327. #endif
  1328. }
  1329. /* If the relocation type and destination symbol does not
  1330. fall into one of the above categories, then we can just
  1331. perform a direct link. */
  1332. if (done)
  1333. rstat = bfd_reloc_ok;
  1334. else
  1335. if ( h->root.type == bfd_link_hash_defined
  1336. || h->root.type == bfd_link_hash_defweak)
  1337. {
  1338. asection *sec;
  1339. sec = h->root.u.def.section;
  1340. val = (h->root.u.def.value
  1341. + sec->output_section->vma
  1342. + sec->output_offset);
  1343. }
  1344. else if (! bfd_link_relocatable (info))
  1345. {
  1346. if (! ((*info->callbacks->undefined_symbol)
  1347. (info, h->root.root.string, input_bfd, input_section,
  1348. rel->r_vaddr - input_section->vma, TRUE)))
  1349. return FALSE;
  1350. }
  1351. }
  1352. /* Emit a reloc if the backend thinks it needs it. */
  1353. if (info->base_file
  1354. && sym
  1355. && pe_data(output_bfd)->in_reloc_p(output_bfd, howto)
  1356. && !arm_emit_base_file_entry (info, output_bfd, input_section,
  1357. rel->r_vaddr))
  1358. return FALSE;
  1359. if (done)
  1360. rstat = bfd_reloc_ok;
  1361. #ifndef ARM_WINCE
  1362. /* Only perform this fix during the final link, not a relocatable link. */
  1363. else if (! bfd_link_relocatable (info)
  1364. && howto->type == ARM_THUMB23)
  1365. {
  1366. /* This is pretty much a copy of what the default
  1367. _bfd_final_link_relocate and _bfd_relocate_contents
  1368. routines do to perform a relocation, with special
  1369. processing for the split addressing of the Thumb BL
  1370. instruction. Again, it would probably be simpler adding a
  1371. ThumbBRANCH23 specific macro expansion into the default
  1372. code. */
  1373. bfd_vma address = rel->r_vaddr - input_section->vma;
  1374. if (address > high_address)
  1375. rstat = bfd_reloc_outofrange;
  1376. else
  1377. {
  1378. bfd_vma relocation = val + addend;
  1379. int size = bfd_get_reloc_size (howto);
  1380. bfd_boolean overflow = FALSE;
  1381. bfd_byte *location = contents + address;
  1382. bfd_vma x = bfd_get_32 (input_bfd, location);
  1383. bfd_vma src_mask = 0x007FFFFE;
  1384. bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
  1385. bfd_signed_vma reloc_signed_min = ~reloc_signed_max;
  1386. bfd_vma check;
  1387. bfd_signed_vma signed_check;
  1388. bfd_vma add;
  1389. bfd_signed_vma signed_add;
  1390. BFD_ASSERT (size == 4);
  1391. /* howto->pc_relative should be TRUE for type 14 BRANCH23. */
  1392. relocation -= (input_section->output_section->vma
  1393. + input_section->output_offset);
  1394. /* howto->pcrel_offset should be TRUE for type 14 BRANCH23. */
  1395. relocation -= address;
  1396. /* No need to negate the relocation with BRANCH23. */
  1397. /* howto->complain_on_overflow == complain_overflow_signed for BRANCH23. */
  1398. /* howto->rightshift == 1 */
  1399. /* Drop unwanted bits from the value we are relocating to. */
  1400. check = relocation >> howto->rightshift;
  1401. /* If this is a signed value, the rightshift just dropped
  1402. leading 1 bits (assuming twos complement). */
  1403. if ((bfd_signed_vma) relocation >= 0)
  1404. signed_check = check;
  1405. else
  1406. signed_check = (check
  1407. | ((bfd_vma) - 1
  1408. & ~((bfd_vma) - 1 >> howto->rightshift)));
  1409. /* Get the value from the object file. */
  1410. if (bfd_big_endian (input_bfd))
  1411. add = (((x) & 0x07ff0000) >> 4) | (((x) & 0x7ff) << 1);
  1412. else
  1413. add = ((((x) & 0x7ff) << 12) | (((x) & 0x07ff0000) >> 15));
  1414. /* Get the value from the object file with an appropriate sign.
  1415. The expression involving howto->src_mask isolates the upper
  1416. bit of src_mask. If that bit is set in the value we are
  1417. adding, it is negative, and we subtract out that number times
  1418. two. If src_mask includes the highest possible bit, then we
  1419. can not get the upper bit, but that does not matter since
  1420. signed_add needs no adjustment to become negative in that
  1421. case. */
  1422. signed_add = add;
  1423. if ((add & (((~ src_mask) >> 1) & src_mask)) != 0)
  1424. signed_add -= (((~ src_mask) >> 1) & src_mask) << 1;
  1425. /* howto->bitpos == 0 */
  1426. /* Add the value from the object file, shifted so that it is a
  1427. straight number. */
  1428. signed_check += signed_add;
  1429. relocation += signed_add;
  1430. BFD_ASSERT (howto->complain_on_overflow == complain_overflow_signed);
  1431. /* Assumes two's complement. */
  1432. if ( signed_check > reloc_signed_max
  1433. || signed_check < reloc_signed_min)
  1434. overflow = TRUE;
  1435. /* Put the relocation into the correct bits.
  1436. For a BLX instruction, make sure that the relocation is rounded up
  1437. to a word boundary. This follows the semantics of the instruction
  1438. which specifies that bit 1 of the target address will come from bit
  1439. 1 of the base address. */
  1440. if (bfd_big_endian (input_bfd))
  1441. {
  1442. if ((x & 0x1800) == 0x0800 && (relocation & 0x02))
  1443. relocation += 2;
  1444. relocation = (((relocation & 0xffe) >> 1) | ((relocation << 4) & 0x07ff0000));
  1445. }
  1446. else
  1447. {
  1448. if ((x & 0x18000000) == 0x08000000 && (relocation & 0x02))
  1449. relocation += 2;
  1450. relocation = (((relocation & 0xffe) << 15) | ((relocation >> 12) & 0x7ff));
  1451. }
  1452. /* Add the relocation to the correct bits of X. */
  1453. x = ((x & ~howto->dst_mask) | relocation);
  1454. /* Put the relocated value back in the object file. */
  1455. bfd_put_32 (input_bfd, x, location);
  1456. rstat = overflow ? bfd_reloc_overflow : bfd_reloc_ok;
  1457. }
  1458. }
  1459. #endif
  1460. else
  1461. if (bfd_link_relocatable (info) && ! howto->partial_inplace)
  1462. rstat = bfd_reloc_ok;
  1463. else
  1464. rstat = _bfd_final_link_relocate (howto, input_bfd, input_section,
  1465. contents,
  1466. rel->r_vaddr - input_section->vma,
  1467. val, addend);
  1468. /* Only perform this fix during the final link, not a relocatable link. */
  1469. if (! bfd_link_relocatable (info)
  1470. && (rel->r_type == ARM_32 || rel->r_type == ARM_RVA32))
  1471. {
  1472. /* Determine if we need to set the bottom bit of a relocated address
  1473. because the address is the address of a Thumb code symbol. */
  1474. int patchit = FALSE;
  1475. if (h != NULL
  1476. && ( h->symbol_class == C_THUMBSTATFUNC
  1477. || h->symbol_class == C_THUMBEXTFUNC))
  1478. {
  1479. patchit = TRUE;
  1480. }
  1481. else if (sym != NULL
  1482. && sym->n_scnum > N_UNDEF)
  1483. {
  1484. /* No hash entry - use the symbol instead. */
  1485. if ( sym->n_sclass == C_THUMBSTATFUNC
  1486. || sym->n_sclass == C_THUMBEXTFUNC)
  1487. patchit = TRUE;
  1488. }
  1489. if (patchit)
  1490. {
  1491. bfd_byte * location = contents + rel->r_vaddr - input_section->vma;
  1492. bfd_vma x = bfd_get_32 (input_bfd, location);
  1493. bfd_put_32 (input_bfd, x | 1, location);
  1494. }
  1495. }
  1496. switch (rstat)
  1497. {
  1498. default:
  1499. abort ();
  1500. case bfd_reloc_ok:
  1501. break;
  1502. case bfd_reloc_outofrange:
  1503. (*_bfd_error_handler)
  1504. (_("%B: bad reloc address 0x%lx in section `%A'"),
  1505. input_bfd, input_section, (unsigned long) rel->r_vaddr);
  1506. return FALSE;
  1507. case bfd_reloc_overflow:
  1508. {
  1509. const char *name;
  1510. char buf[SYMNMLEN + 1];
  1511. if (symndx == -1)
  1512. name = "*ABS*";
  1513. else if (h != NULL)
  1514. name = NULL;
  1515. else
  1516. {
  1517. name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
  1518. if (name == NULL)
  1519. return FALSE;
  1520. }
  1521. if (! ((*info->callbacks->reloc_overflow)
  1522. (info, (h ? &h->root : NULL), name, howto->name,
  1523. (bfd_vma) 0, input_bfd, input_section,
  1524. rel->r_vaddr - input_section->vma)))
  1525. return FALSE;
  1526. }
  1527. }
  1528. }
  1529. return TRUE;
  1530. }
  1531. #ifndef COFF_IMAGE_WITH_PE
  1532. bfd_boolean
  1533. bfd_arm_allocate_interworking_sections (struct bfd_link_info * info)
  1534. {
  1535. asection * s;
  1536. bfd_byte * foo;
  1537. struct coff_arm_link_hash_table * globals;
  1538. globals = coff_arm_hash_table (info);
  1539. BFD_ASSERT (globals != NULL);
  1540. if (globals->arm_glue_size != 0)
  1541. {
  1542. BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
  1543. s = bfd_get_section_by_name
  1544. (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
  1545. BFD_ASSERT (s != NULL);
  1546. foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size);
  1547. s->size = globals->arm_glue_size;
  1548. s->contents = foo;
  1549. }
  1550. if (globals->thumb_glue_size != 0)
  1551. {
  1552. BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
  1553. s = bfd_get_section_by_name
  1554. (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
  1555. BFD_ASSERT (s != NULL);
  1556. foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size);
  1557. s->size = globals->thumb_glue_size;
  1558. s->contents = foo;
  1559. }
  1560. return TRUE;
  1561. }
  1562. static void
  1563. record_arm_to_thumb_glue (struct bfd_link_info * info,
  1564. struct coff_link_hash_entry * h)
  1565. {
  1566. const char * name = h->root.root.string;
  1567. register asection * s;
  1568. char * tmp_name;
  1569. struct coff_link_hash_entry * myh;
  1570. struct bfd_link_hash_entry * bh;
  1571. struct coff_arm_link_hash_table * globals;
  1572. bfd_vma val;
  1573. bfd_size_type amt;
  1574. globals = coff_arm_hash_table (info);
  1575. BFD_ASSERT (globals != NULL);
  1576. BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
  1577. s = bfd_get_section_by_name
  1578. (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
  1579. BFD_ASSERT (s != NULL);
  1580. amt = strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1;
  1581. tmp_name = bfd_malloc (amt);
  1582. BFD_ASSERT (tmp_name);
  1583. sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
  1584. myh = coff_link_hash_lookup
  1585. (coff_hash_table (info), tmp_name, FALSE, FALSE, TRUE);
  1586. if (myh != NULL)
  1587. {
  1588. free (tmp_name);
  1589. /* We've already seen this guy. */
  1590. return;
  1591. }
  1592. /* The only trick here is using globals->arm_glue_size as the value. Even
  1593. though the section isn't allocated yet, this is where we will be putting
  1594. it. */
  1595. bh = NULL;
  1596. val = globals->arm_glue_size + 1;
  1597. bfd_coff_link_add_one_symbol (info, globals->bfd_of_glue_owner, tmp_name,
  1598. BSF_GLOBAL, s, val, NULL, TRUE, FALSE, &bh);
  1599. free (tmp_name);
  1600. globals->arm_glue_size += ARM2THUMB_GLUE_SIZE;
  1601. return;
  1602. }
  1603. #ifndef ARM_WINCE
  1604. static void
  1605. record_thumb_to_arm_glue (struct bfd_link_info * info,
  1606. struct coff_link_hash_entry * h)
  1607. {
  1608. const char * name = h->root.root.string;
  1609. asection * s;
  1610. char * tmp_name;
  1611. struct coff_link_hash_entry * myh;
  1612. struct bfd_link_hash_entry * bh;
  1613. struct coff_arm_link_hash_table * globals;
  1614. bfd_vma val;
  1615. bfd_size_type amt;
  1616. globals = coff_arm_hash_table (info);
  1617. BFD_ASSERT (globals != NULL);
  1618. BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
  1619. s = bfd_get_section_by_name
  1620. (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
  1621. BFD_ASSERT (s != NULL);
  1622. amt = strlen (name) + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1;
  1623. tmp_name = bfd_malloc (amt);
  1624. BFD_ASSERT (tmp_name);
  1625. sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
  1626. myh = coff_link_hash_lookup
  1627. (coff_hash_table (info), tmp_name, FALSE, FALSE, TRUE);
  1628. if (myh != NULL)
  1629. {
  1630. free (tmp_name);
  1631. /* We've already seen this guy. */
  1632. return;
  1633. }
  1634. bh = NULL;
  1635. val = globals->thumb_glue_size + 1;
  1636. bfd_coff_link_add_one_symbol (info, globals->bfd_of_glue_owner, tmp_name,
  1637. BSF_GLOBAL, s, val, NULL, TRUE, FALSE, &bh);
  1638. /* If we mark it 'thumb', the disassembler will do a better job. */
  1639. myh = (struct coff_link_hash_entry *) bh;
  1640. myh->symbol_class = C_THUMBEXTFUNC;
  1641. free (tmp_name);
  1642. /* Allocate another symbol to mark where we switch to arm mode. */
  1643. #define CHANGE_TO_ARM "__%s_change_to_arm"
  1644. #define BACK_FROM_ARM "__%s_back_from_arm"
  1645. amt = strlen (name) + strlen (CHANGE_TO_ARM) + 1;
  1646. tmp_name = bfd_malloc (amt);
  1647. BFD_ASSERT (tmp_name);
  1648. sprintf (tmp_name, globals->support_old_code ? BACK_FROM_ARM : CHANGE_TO_ARM, name);
  1649. bh = NULL;
  1650. val = globals->thumb_glue_size + (globals->support_old_code ? 8 : 4);
  1651. bfd_coff_link_add_one_symbol (info, globals->bfd_of_glue_owner, tmp_name,
  1652. BSF_LOCAL, s, val, NULL, TRUE, FALSE, &bh);
  1653. free (tmp_name);
  1654. globals->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
  1655. return;
  1656. }
  1657. #endif /* not ARM_WINCE */
  1658. /* Select a BFD to be used to hold the sections used by the glue code.
  1659. This function is called from the linker scripts in ld/emultempl/
  1660. {armcoff/pe}.em */
  1661. bfd_boolean
  1662. bfd_arm_get_bfd_for_interworking (bfd * abfd,
  1663. struct bfd_link_info * info)
  1664. {
  1665. struct coff_arm_link_hash_table * globals;
  1666. flagword flags;
  1667. asection * sec;
  1668. /* If we are only performing a partial link do not bother
  1669. getting a bfd to hold the glue. */
  1670. if (bfd_link_relocatable (info))
  1671. return TRUE;
  1672. globals = coff_arm_hash_table (info);
  1673. BFD_ASSERT (globals != NULL);
  1674. if (globals->bfd_of_glue_owner != NULL)
  1675. return TRUE;
  1676. sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME);
  1677. if (sec == NULL)
  1678. {
  1679. flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
  1680. | SEC_CODE | SEC_READONLY);
  1681. sec = bfd_make_section_with_flags (abfd, ARM2THUMB_GLUE_SECTION_NAME,
  1682. flags);
  1683. if (sec == NULL
  1684. || ! bfd_set_section_alignment (abfd, sec, 2))
  1685. return FALSE;
  1686. }
  1687. sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME);
  1688. if (sec == NULL)
  1689. {
  1690. flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
  1691. | SEC_CODE | SEC_READONLY);
  1692. sec = bfd_make_section_with_flags (abfd, THUMB2ARM_GLUE_SECTION_NAME,
  1693. flags);
  1694. if (sec == NULL
  1695. || ! bfd_set_section_alignment (abfd, sec, 2))
  1696. return FALSE;
  1697. }
  1698. /* Save the bfd for later use. */
  1699. globals->bfd_of_glue_owner = abfd;
  1700. return TRUE;
  1701. }
  1702. bfd_boolean
  1703. bfd_arm_process_before_allocation (bfd * abfd,
  1704. struct bfd_link_info * info,
  1705. int support_old_code)
  1706. {
  1707. asection * sec;
  1708. struct coff_arm_link_hash_table * globals;
  1709. /* If we are only performing a partial link do not bother
  1710. to construct any glue. */
  1711. if (bfd_link_relocatable (info))
  1712. return TRUE;
  1713. /* Here we have a bfd that is to be included on the link. We have a hook
  1714. to do reloc rummaging, before section sizes are nailed down. */
  1715. _bfd_coff_get_external_symbols (abfd);
  1716. globals = coff_arm_hash_table (info);
  1717. BFD_ASSERT (globals != NULL);
  1718. BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
  1719. globals->support_old_code = support_old_code;
  1720. /* Rummage around all the relocs and map the glue vectors. */
  1721. sec = abfd->sections;
  1722. if (sec == NULL)
  1723. return TRUE;
  1724. for (; sec != NULL; sec = sec->next)
  1725. {
  1726. struct internal_reloc * i;
  1727. struct internal_reloc * rel;
  1728. if (sec->reloc_count == 0)
  1729. continue;
  1730. /* Load the relocs. */
  1731. /* FIXME: there may be a storage leak here. */
  1732. i = _bfd_coff_read_internal_relocs (abfd, sec, 1, 0, 0, 0);
  1733. BFD_ASSERT (i != 0);
  1734. for (rel = i; rel < i + sec->reloc_count; ++rel)
  1735. {
  1736. unsigned short r_type = rel->r_type;
  1737. long symndx;
  1738. struct coff_link_hash_entry * h;
  1739. symndx = rel->r_symndx;
  1740. /* If the relocation is not against a symbol it cannot concern us. */
  1741. if (symndx == -1)
  1742. continue;
  1743. /* If the index is outside of the range of our table, something has gone wrong. */
  1744. if (symndx >= obj_conv_table_size (abfd))
  1745. {
  1746. _bfd_error_handler (_("%B: illegal symbol index in reloc: %d"),
  1747. abfd, symndx);
  1748. continue;
  1749. }
  1750. h = obj_coff_sym_hashes (abfd)[symndx];
  1751. /* If the relocation is against a static symbol it must be within
  1752. the current section and so cannot be a cross ARM/Thumb relocation. */
  1753. if (h == NULL)
  1754. continue;
  1755. switch (r_type)
  1756. {
  1757. case ARM_26:
  1758. /* This one is a call from arm code. We need to look up
  1759. the target of the call. If it is a thumb target, we
  1760. insert glue. */
  1761. if (h->symbol_class == C_THUMBEXTFUNC)
  1762. record_arm_to_thumb_glue (info, h);
  1763. break;
  1764. #ifndef ARM_WINCE
  1765. case ARM_THUMB23:
  1766. /* This one is a call from thumb code. We used to look
  1767. for ARM_THUMB9 and ARM_THUMB12 as well. We need to look
  1768. up the target of the call. If it is an arm target, we
  1769. insert glue. If the symbol does not exist it will be
  1770. given a class of C_EXT and so we will generate a stub
  1771. for it. This is not really a problem, since the link
  1772. is doomed anyway. */
  1773. switch (h->symbol_class)
  1774. {
  1775. case C_EXT:
  1776. case C_STAT:
  1777. case C_LABEL:
  1778. record_thumb_to_arm_glue (info, h);
  1779. break;
  1780. default:
  1781. ;
  1782. }
  1783. break;
  1784. #endif
  1785. default:
  1786. break;
  1787. }
  1788. }
  1789. }
  1790. return TRUE;
  1791. }
  1792. #endif /* ! defined (COFF_IMAGE_WITH_PE) */
  1793. #define coff_bfd_reloc_type_lookup coff_arm_reloc_type_lookup
  1794. #define coff_bfd_reloc_name_lookup coff_arm_reloc_name_lookup
  1795. #define coff_relocate_section coff_arm_relocate_section
  1796. #define coff_bfd_is_local_label_name coff_arm_is_local_label_name
  1797. #define coff_adjust_symndx coff_arm_adjust_symndx
  1798. #define coff_link_output_has_begun coff_arm_link_output_has_begun
  1799. #define coff_final_link_postscript coff_arm_final_link_postscript
  1800. #define coff_bfd_merge_private_bfd_data coff_arm_merge_private_bfd_data
  1801. #define coff_bfd_print_private_bfd_data coff_arm_print_private_bfd_data
  1802. #define coff_bfd_set_private_flags _bfd_coff_arm_set_private_flags
  1803. #define coff_bfd_copy_private_bfd_data coff_arm_copy_private_bfd_data
  1804. #define coff_bfd_link_hash_table_create coff_arm_link_hash_table_create
  1805. /* When doing a relocatable link, we want to convert ARM_26 relocs
  1806. into ARM_26D relocs. */
  1807. static bfd_boolean
  1808. coff_arm_adjust_symndx (bfd *obfd ATTRIBUTE_UNUSED,
  1809. struct bfd_link_info *info ATTRIBUTE_UNUSED,
  1810. bfd *ibfd,
  1811. asection *sec,
  1812. struct internal_reloc *irel,
  1813. bfd_boolean *adjustedp)
  1814. {
  1815. if (irel->r_type == ARM_26)
  1816. {
  1817. struct coff_link_hash_entry *h;
  1818. h = obj_coff_sym_hashes (ibfd)[irel->r_symndx];
  1819. if (h != NULL
  1820. && (h->root.type == bfd_link_hash_defined
  1821. || h->root.type == bfd_link_hash_defweak)
  1822. && h->root.u.def.section->output_section == sec->output_section)
  1823. irel->r_type = ARM_26D;
  1824. }
  1825. *adjustedp = FALSE;
  1826. return TRUE;
  1827. }
  1828. /* Called when merging the private data areas of two BFDs.
  1829. This is important as it allows us to detect if we are
  1830. attempting to merge binaries compiled for different ARM
  1831. targets, eg different CPUs or different APCS's. */
  1832. static bfd_boolean
  1833. coff_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
  1834. {
  1835. BFD_ASSERT (ibfd != NULL && obfd != NULL);
  1836. if (ibfd == obfd)
  1837. return TRUE;
  1838. /* If the two formats are different we cannot merge anything.
  1839. This is not an error, since it is permissable to change the
  1840. input and output formats. */
  1841. if ( ibfd->xvec->flavour != bfd_target_coff_flavour
  1842. || obfd->xvec->flavour != bfd_target_coff_flavour)
  1843. return TRUE;
  1844. /* Determine what should happen if the input ARM architecture
  1845. does not match the output ARM architecture. */
  1846. if (! bfd_arm_merge_machines (ibfd, obfd))
  1847. return FALSE;
  1848. /* Verify that the APCS is the same for the two BFDs. */
  1849. if (APCS_SET (ibfd))
  1850. {
  1851. if (APCS_SET (obfd))
  1852. {
  1853. /* If the src and dest have different APCS flag bits set, fail. */
  1854. if (APCS_26_FLAG (obfd) != APCS_26_FLAG (ibfd))
  1855. {
  1856. _bfd_error_handler
  1857. /* xgettext: c-format */
  1858. (_("error: %B is compiled for APCS-%d, whereas %B is compiled for APCS-%d"),
  1859. ibfd, obfd,
  1860. APCS_26_FLAG (ibfd) ? 26 : 32,
  1861. APCS_26_FLAG (obfd) ? 26 : 32
  1862. );
  1863. bfd_set_error (bfd_error_wrong_format);
  1864. return FALSE;
  1865. }
  1866. if (APCS_FLOAT_FLAG (obfd) != APCS_FLOAT_FLAG (ibfd))
  1867. {
  1868. const char *msg;
  1869. if (APCS_FLOAT_FLAG (ibfd))
  1870. /* xgettext: c-format */
  1871. msg = _("error: %B passes floats in float registers, whereas %B passes them in integer registers");
  1872. else
  1873. /* xgettext: c-format */
  1874. msg = _("error: %B passes floats in integer registers, whereas %B passes them in float registers");
  1875. _bfd_error_handler (msg, ibfd, obfd);
  1876. bfd_set_error (bfd_error_wrong_format);
  1877. return FALSE;
  1878. }
  1879. if (PIC_FLAG (obfd) != PIC_FLAG (ibfd))
  1880. {
  1881. const char * msg;
  1882. if (PIC_FLAG (ibfd))
  1883. /* xgettext: c-format */
  1884. msg = _("error: %B is compiled as position independent code, whereas target %B is absolute position");
  1885. else
  1886. /* xgettext: c-format */
  1887. msg = _("error: %B is compiled as absolute position code, whereas target %B is position independent");
  1888. _bfd_error_handler (msg, ibfd, obfd);
  1889. bfd_set_error (bfd_error_wrong_format);
  1890. return FALSE;
  1891. }
  1892. }
  1893. else
  1894. {
  1895. SET_APCS_FLAGS (obfd, APCS_26_FLAG (ibfd) | APCS_FLOAT_FLAG (ibfd) | PIC_FLAG (ibfd));
  1896. /* Set up the arch and fields as well as these are probably wrong. */
  1897. bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
  1898. }
  1899. }
  1900. /* Check the interworking support. */
  1901. if (INTERWORK_SET (ibfd))
  1902. {
  1903. if (INTERWORK_SET (obfd))
  1904. {
  1905. /* If the src and dest differ in their interworking issue a warning. */
  1906. if (INTERWORK_FLAG (obfd) != INTERWORK_FLAG (ibfd))
  1907. {
  1908. const char * msg;
  1909. if (INTERWORK_FLAG (ibfd))
  1910. /* xgettext: c-format */
  1911. msg = _("Warning: %B supports interworking, whereas %B does not");
  1912. else
  1913. /* xgettext: c-format */
  1914. msg = _("Warning: %B does not support interworking, whereas %B does");
  1915. _bfd_error_handler (msg, ibfd, obfd);
  1916. }
  1917. }
  1918. else
  1919. {
  1920. SET_INTERWORK_FLAG (obfd, INTERWORK_FLAG (ibfd));
  1921. }
  1922. }
  1923. return TRUE;
  1924. }
  1925. /* Display the flags field. */
  1926. static bfd_boolean
  1927. coff_arm_print_private_bfd_data (bfd * abfd, void * ptr)
  1928. {
  1929. FILE * file = (FILE *) ptr;
  1930. BFD_ASSERT (abfd != NULL && ptr != NULL);
  1931. /* xgettext:c-format */
  1932. fprintf (file, _("private flags = %x:"), coff_data (abfd)->flags);
  1933. if (APCS_SET (abfd))
  1934. {
  1935. /* xgettext: APCS is ARM Procedure Call Standard, it should not be translated. */
  1936. fprintf (file, " [APCS-%d]", APCS_26_FLAG (abfd) ? 26 : 32);
  1937. if (APCS_FLOAT_FLAG (abfd))
  1938. fprintf (file, _(" [floats passed in float registers]"));
  1939. else
  1940. fprintf (file, _(" [floats passed in integer registers]"));
  1941. if (PIC_FLAG (abfd))
  1942. fprintf (file, _(" [position independent]"));
  1943. else
  1944. fprintf (file, _(" [absolute position]"));
  1945. }
  1946. if (! INTERWORK_SET (abfd))
  1947. fprintf (file, _(" [interworking flag not initialised]"));
  1948. else if (INTERWORK_FLAG (abfd))
  1949. fprintf (file, _(" [interworking supported]"));
  1950. else
  1951. fprintf (file, _(" [interworking not supported]"));
  1952. fputc ('\n', file);
  1953. return TRUE;
  1954. }
  1955. /* Copies the given flags into the coff_tdata.flags field.
  1956. Typically these flags come from the f_flags[] field of
  1957. the COFF filehdr structure, which contains important,
  1958. target specific information.
  1959. Note: Although this function is static, it is explicitly
  1960. called from both coffcode.h and peicode.h. */
  1961. static bfd_boolean
  1962. _bfd_coff_arm_set_private_flags (bfd * abfd, flagword flags)
  1963. {
  1964. flagword flag;
  1965. BFD_ASSERT (abfd != NULL);
  1966. flag = (flags & F_APCS26) ? F_APCS_26 : 0;
  1967. /* Make sure that the APCS field has not been initialised to the opposite
  1968. value. */
  1969. if (APCS_SET (abfd)
  1970. && ( (APCS_26_FLAG (abfd) != flag)
  1971. || (APCS_FLOAT_FLAG (abfd) != (flags & F_APCS_FLOAT))
  1972. || (PIC_FLAG (abfd) != (flags & F_PIC))
  1973. ))
  1974. return FALSE;
  1975. flag |= (flags & (F_APCS_FLOAT | F_PIC));
  1976. SET_APCS_FLAGS (abfd, flag);
  1977. flag = (flags & F_INTERWORK);
  1978. /* If the BFD has already had its interworking flag set, but it
  1979. is different from the value that we have been asked to set,
  1980. then assume that that merged code will not support interworking
  1981. and set the flag accordingly. */
  1982. if (INTERWORK_SET (abfd) && (INTERWORK_FLAG (abfd) != flag))
  1983. {
  1984. if (flag)
  1985. /* xgettext: c-format */
  1986. _bfd_error_handler (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
  1987. abfd);
  1988. else
  1989. /* xgettext: c-format */
  1990. _bfd_error_handler (_("Warning: Clearing the interworking flag of %B due to outside request"),
  1991. abfd);
  1992. flag = 0;
  1993. }
  1994. SET_INTERWORK_FLAG (abfd, flag);
  1995. return TRUE;
  1996. }
  1997. /* Copy the important parts of the target specific data
  1998. from one instance of a BFD to another. */
  1999. static bfd_boolean
  2000. coff_arm_copy_private_bfd_data (bfd * src, bfd * dest)
  2001. {
  2002. BFD_ASSERT (src != NULL && dest != NULL);
  2003. if (src == dest)
  2004. return TRUE;
  2005. /* If the destination is not in the same format as the source, do not do
  2006. the copy. */
  2007. if (src->xvec != dest->xvec)
  2008. return TRUE;
  2009. /* Copy the flags field. */
  2010. if (APCS_SET (src))
  2011. {
  2012. if (APCS_SET (dest))
  2013. {
  2014. /* If the src and dest have different APCS flag bits set, fail. */
  2015. if (APCS_26_FLAG (dest) != APCS_26_FLAG (src))
  2016. return FALSE;
  2017. if (APCS_FLOAT_FLAG (dest) != APCS_FLOAT_FLAG (src))
  2018. return FALSE;
  2019. if (PIC_FLAG (dest) != PIC_FLAG (src))
  2020. return FALSE;
  2021. }
  2022. else
  2023. SET_APCS_FLAGS (dest, APCS_26_FLAG (src) | APCS_FLOAT_FLAG (src)
  2024. | PIC_FLAG (src));
  2025. }
  2026. if (INTERWORK_SET (src))
  2027. {
  2028. if (INTERWORK_SET (dest))
  2029. {
  2030. /* If the src and dest have different interworking flags then turn
  2031. off the interworking bit. */
  2032. if (INTERWORK_FLAG (dest) != INTERWORK_FLAG (src))
  2033. {
  2034. if (INTERWORK_FLAG (dest))
  2035. {
  2036. /* xgettext:c-format */
  2037. _bfd_error_handler (("\
  2038. Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
  2039. dest, src);
  2040. }
  2041. SET_INTERWORK_FLAG (dest, 0);
  2042. }
  2043. }
  2044. else
  2045. {
  2046. SET_INTERWORK_FLAG (dest, INTERWORK_FLAG (src));
  2047. }
  2048. }
  2049. return TRUE;
  2050. }
  2051. /* Note: the definitions here of LOCAL_LABEL_PREFIX and USER_LABEL_PREIFX
  2052. *must* match the definitions in gcc/config/arm/{coff|semi|aout}.h. */
  2053. #ifndef LOCAL_LABEL_PREFIX
  2054. #define LOCAL_LABEL_PREFIX ""
  2055. #endif
  2056. #ifndef USER_LABEL_PREFIX
  2057. #define USER_LABEL_PREFIX "_"
  2058. #endif
  2059. /* Like _bfd_coff_is_local_label_name, but
  2060. a) test against USER_LABEL_PREFIX, to avoid stripping labels known to be
  2061. non-local.
  2062. b) Allow other prefixes than ".", e.g. an empty prefix would cause all
  2063. labels of the form Lxxx to be stripped. */
  2064. static bfd_boolean
  2065. coff_arm_is_local_label_name (bfd * abfd ATTRIBUTE_UNUSED,
  2066. const char * name)
  2067. {
  2068. #ifdef USER_LABEL_PREFIX
  2069. if (USER_LABEL_PREFIX[0] != 0)
  2070. {
  2071. size_t len = strlen (USER_LABEL_PREFIX);
  2072. if (strncmp (name, USER_LABEL_PREFIX, len) == 0)
  2073. return FALSE;
  2074. }
  2075. #endif
  2076. #ifdef LOCAL_LABEL_PREFIX
  2077. /* If there is a prefix for local labels then look for this.
  2078. If the prefix exists, but it is empty, then ignore the test. */
  2079. if (LOCAL_LABEL_PREFIX[0] != 0)
  2080. {
  2081. size_t len = strlen (LOCAL_LABEL_PREFIX);
  2082. if (strncmp (name, LOCAL_LABEL_PREFIX, len) != 0)
  2083. return FALSE;
  2084. /* Perform the checks below for the rest of the name. */
  2085. name += len;
  2086. }
  2087. #endif
  2088. return name[0] == 'L';
  2089. }
  2090. /* This piece of machinery exists only to guarantee that the bfd that holds
  2091. the glue section is written last.
  2092. This does depend on bfd_make_section attaching a new section to the
  2093. end of the section list for the bfd. */
  2094. static bfd_boolean
  2095. coff_arm_link_output_has_begun (bfd * sub, struct coff_final_link_info * info)
  2096. {
  2097. return (sub->output_has_begun
  2098. || sub == coff_arm_hash_table (info->info)->bfd_of_glue_owner);
  2099. }
  2100. static bfd_boolean
  2101. coff_arm_final_link_postscript (bfd * abfd ATTRIBUTE_UNUSED,
  2102. struct coff_final_link_info * pfinfo)
  2103. {
  2104. struct coff_arm_link_hash_table * globals;
  2105. globals = coff_arm_hash_table (pfinfo->info);
  2106. BFD_ASSERT (globals != NULL);
  2107. if (globals->bfd_of_glue_owner != NULL)
  2108. {
  2109. if (! _bfd_coff_link_input_bfd (pfinfo, globals->bfd_of_glue_owner))
  2110. return FALSE;
  2111. globals->bfd_of_glue_owner->output_has_begun = TRUE;
  2112. }
  2113. return bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
  2114. }
  2115. #ifndef bfd_pe_print_pdata
  2116. #define bfd_pe_print_pdata NULL
  2117. #endif
  2118. #include "coffcode.h"
  2119. #ifndef TARGET_LITTLE_SYM
  2120. #define TARGET_LITTLE_SYM arm_coff_le_vec
  2121. #endif
  2122. #ifndef TARGET_LITTLE_NAME
  2123. #define TARGET_LITTLE_NAME "coff-arm-little"
  2124. #endif
  2125. #ifndef TARGET_BIG_SYM
  2126. #define TARGET_BIG_SYM arm_coff_be_vec
  2127. #endif
  2128. #ifndef TARGET_BIG_NAME
  2129. #define TARGET_BIG_NAME "coff-arm-big"
  2130. #endif
  2131. #ifndef TARGET_UNDERSCORE
  2132. #define TARGET_UNDERSCORE 0
  2133. #endif
  2134. #ifndef EXTRA_S_FLAGS
  2135. #ifdef COFF_WITH_PE
  2136. #define EXTRA_S_FLAGS (SEC_CODE | SEC_LINK_ONCE | SEC_LINK_DUPLICATES)
  2137. #else
  2138. #define EXTRA_S_FLAGS SEC_CODE
  2139. #endif
  2140. #endif
  2141. /* Forward declaration for use initialising alternative_target field. */
  2142. extern const bfd_target TARGET_BIG_SYM ;
  2143. /* Target vectors. */
  2144. CREATE_LITTLE_COFF_TARGET_VEC (TARGET_LITTLE_SYM, TARGET_LITTLE_NAME, D_PAGED, EXTRA_S_FLAGS, TARGET_UNDERSCORE, & TARGET_BIG_SYM, COFF_SWAP_TABLE)
  2145. CREATE_BIG_COFF_TARGET_VEC (TARGET_BIG_SYM, TARGET_BIG_NAME, D_PAGED, EXTRA_S_FLAGS, TARGET_UNDERSCORE, & TARGET_LITTLE_SYM, COFF_SWAP_TABLE)