coff-arm.c 68 KB

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