0012-x86-Add-a-GNU_PROPERTY_X86_ISA_1_USED-note-if-needed.patch 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. From 6737a6b34f4823deb7142f27b4074831a37ac1e1 Mon Sep 17 00:00:00 2001
  2. From: "H.J. Lu" <hjl.tools@gmail.com>
  3. Date: Fri, 20 Jul 2018 09:18:47 -0700
  4. Subject: [PATCH] x86: Add a GNU_PROPERTY_X86_ISA_1_USED note if needed
  5. When -z separate-code, which is enabled by default for Linux/x86, is
  6. used to create executable, ld won't place any data in the code-only
  7. PT_LOAD segment. If there are no data sections placed before the
  8. code-only PT_LOAD segment, the program headers won't be mapped into
  9. any PT_LOAD segment. When the executable tries to access it (based
  10. on the program header address passed in AT_PHDR), it will lead to
  11. segfault. This patch inserts a GNU_PROPERTY_X86_ISA_1_USED note if
  12. there may be no data sections before the text section so that the
  13. first PT_LOAD segment won't be code-only and will contain the program
  14. header.
  15. Testcases are adjusted to either pass "-z noseparate-code" to ld or
  16. discard the .note.gnu.property section. A Linux/x86 run-time test is
  17. added.
  18. bfd/
  19. PR ld/23428
  20. * elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): If the
  21. separate code program header is needed, make sure that the first
  22. read-only PT_LOAD segment has no code by adding a
  23. GNU_PROPERTY_X86_ISA_1_USED note.
  24. ld/
  25. PR ld/23428
  26. * testsuite/ld-elf/linux-x86.S: New file.
  27. * testsuite/ld-elf/linux-x86.exp: Likewise.
  28. * testsuite/ld-elf/pr23428.c: Likewise.
  29. * testsuite/ld-elf/sec64k.exp: Pass "-z noseparate-code" to ld
  30. for Linux/x86 targets.
  31. * testsuite/ld-i386/abs-iamcu.d: Likewise.
  32. * testsuite/ld-i386/abs.d: Likewise.
  33. * testsuite/ld-i386/pr12718.d: Likewise.
  34. * testsuite/ld-i386/pr12921.d: Likewise.
  35. * testsuite/ld-x86-64/abs-k1om.d: Likewise.
  36. * testsuite/ld-x86-64/abs-l1om.d: Likewise.
  37. * testsuite/ld-x86-64/abs.d: Likewise.
  38. * testsuite/ld-x86-64/pr12718.d: Likewise.
  39. * testsuite/ld-x86-64/pr12921.d: Likewise.
  40. * testsuite/ld-linkonce/zeroeh.ld: Discard .note.gnu.property
  41. section.
  42. * testsuite/ld-scripts/print-memory-usage.t: Likewise.
  43. * testsuite/ld-scripts/size-2.t: Likewise.
  44. * testsuite/lib/ld-lib.exp (run_ld_link_exec_tests): Use ld
  45. to create executable if language is "asm".
  46. (cherry picked from commit 241e64e3b42cd9eba514b8e0ad2ef39a337f10a5)
  47. Signed-off-by: Norbert Lange <nolange79@gmail.com>
  48. ---
  49. bfd/ChangeLog | 8 ++++
  50. bfd/elfxx-x86.c | 60 +++++++++++++++++++-------
  51. ld/ChangeLog | 24 +++++++++++
  52. ld/testsuite/ld-elf/linux-x86.S | 63 ++++++++++++++++++++++++++++
  53. ld/testsuite/ld-elf/linux-x86.exp | 46 ++++++++++++++++++++
  54. ld/testsuite/ld-elf/pr23428.c | 43 +++++++++++++++++++
  55. ld/testsuite/ld-elf/sec64k.exp | 2 +
  56. ld/testsuite/ld-i386/abs-iamcu.d | 2 +-
  57. ld/testsuite/ld-i386/abs.d | 2 +-
  58. ld/testsuite/ld-i386/pr12718.d | 2 +-
  59. ld/testsuite/ld-i386/pr12921.d | 2 +-
  60. ld/testsuite/ld-linkonce/zeroeh.ld | 1 +
  61. ld/testsuite/ld-scripts/print-memory-usage.t | 2 +
  62. ld/testsuite/ld-scripts/size-2.t | 1 +
  63. ld/testsuite/ld-x86-64/abs-k1om.d | 2 +-
  64. ld/testsuite/ld-x86-64/abs-l1om.d | 2 +-
  65. ld/testsuite/ld-x86-64/abs.d | 2 +-
  66. ld/testsuite/ld-x86-64/pr12718.d | 2 +-
  67. ld/testsuite/ld-x86-64/pr12921.d | 2 +-
  68. ld/testsuite/lib/ld-lib.exp | 5 ++-
  69. 20 files changed, 248 insertions(+), 25 deletions(-)
  70. create mode 100644 ld/testsuite/ld-elf/linux-x86.S
  71. create mode 100644 ld/testsuite/ld-elf/linux-x86.exp
  72. create mode 100644 ld/testsuite/ld-elf/pr23428.c
  73. diff --git a/bfd/ChangeLog b/bfd/ChangeLog
  74. index 1c1174a..d3831b7 100644
  75. --- a/bfd/ChangeLog
  76. +++ b/bfd/ChangeLog
  77. @@ -1,3 +1,11 @@
  78. +2018-07-23 H.J. Lu <hongjiu.lu@intel.com>
  79. +
  80. + PR ld/23428
  81. + * elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): If the
  82. + separate code program header is needed, make sure that the first
  83. + read-only PT_LOAD segment has no code by adding a
  84. + GNU_PROPERTY_X86_ISA_1_USED note.
  85. +
  86. 2018-07-18 Nick Clifton <nickc@redhat.com>
  87. * development.sh: Set to true.
  88. diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
  89. index a2497aa..2e4ff88 100644
  90. --- a/bfd/elfxx-x86.c
  91. +++ b/bfd/elfxx-x86.c
  92. @@ -2524,6 +2524,7 @@ _bfd_x86_elf_link_setup_gnu_properties
  93. const struct elf_backend_data *bed;
  94. unsigned int class_align = ABI_64_P (info->output_bfd) ? 3 : 2;
  95. unsigned int got_align;
  96. + bfd_boolean has_text = FALSE;
  97. features = 0;
  98. if (info->ibt)
  99. @@ -2538,24 +2539,59 @@ _bfd_x86_elf_link_setup_gnu_properties
  100. if (bfd_get_flavour (pbfd) == bfd_target_elf_flavour
  101. && bfd_count_sections (pbfd) != 0)
  102. {
  103. + if (!has_text)
  104. + {
  105. + /* Check if there is no non-empty text section. */
  106. + sec = bfd_get_section_by_name (pbfd, ".text");
  107. + if (sec != NULL && sec->size != 0)
  108. + has_text = TRUE;
  109. + }
  110. +
  111. ebfd = pbfd;
  112. if (elf_properties (pbfd) != NULL)
  113. break;
  114. }
  115. - if (ebfd != NULL && features)
  116. + bed = get_elf_backend_data (info->output_bfd);
  117. +
  118. + htab = elf_x86_hash_table (info, bed->target_id);
  119. + if (htab == NULL)
  120. + return pbfd;
  121. +
  122. + if (ebfd != NULL)
  123. {
  124. - /* If features is set, add GNU_PROPERTY_X86_FEATURE_1_IBT and
  125. - GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
  126. - prop = _bfd_elf_get_property (ebfd,
  127. - GNU_PROPERTY_X86_FEATURE_1_AND,
  128. - 4);
  129. - prop->u.number |= features;
  130. - prop->pr_kind = property_number;
  131. + prop = NULL;
  132. + if (features)
  133. + {
  134. + /* If features is set, add GNU_PROPERTY_X86_FEATURE_1_IBT and
  135. + GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
  136. + prop = _bfd_elf_get_property (ebfd,
  137. + GNU_PROPERTY_X86_FEATURE_1_AND,
  138. + 4);
  139. + prop->u.number |= features;
  140. + prop->pr_kind = property_number;
  141. + }
  142. + else if (has_text
  143. + && elf_properties (ebfd) == NULL
  144. + && elf_tdata (info->output_bfd)->o->build_id.sec == NULL
  145. + && !htab->elf.dynamic_sections_created
  146. + && !info->traditional_format
  147. + && (info->output_bfd->flags & D_PAGED) != 0
  148. + && info->separate_code)
  149. + {
  150. + /* If the separate code program header is needed, make sure
  151. + that the first read-only PT_LOAD segment has no code by
  152. + adding a GNU_PROPERTY_X86_ISA_1_USED note. */
  153. + prop = _bfd_elf_get_property (ebfd,
  154. + GNU_PROPERTY_X86_ISA_1_USED,
  155. + 4);
  156. + prop->u.number = GNU_PROPERTY_X86_ISA_1_486;
  157. + prop->pr_kind = property_number;
  158. + }
  159. /* Create the GNU property note section if needed. */
  160. - if (pbfd == NULL)
  161. + if (prop != NULL && pbfd == NULL)
  162. {
  163. sec = bfd_make_section_with_flags (ebfd,
  164. NOTE_GNU_PROPERTY_SECTION_NAME,
  165. @@ -2581,12 +2617,6 @@ error_alignment:
  166. pbfd = _bfd_elf_link_setup_gnu_properties (info);
  167. - bed = get_elf_backend_data (info->output_bfd);
  168. -
  169. - htab = elf_x86_hash_table (info, bed->target_id);
  170. - if (htab == NULL)
  171. - return pbfd;
  172. -
  173. htab->r_info = init_table->r_info;
  174. htab->r_sym = init_table->r_sym;
  175. diff --git a/ld/ChangeLog b/ld/ChangeLog
  176. index c07e442..cfadbd4 100644
  177. --- a/ld/ChangeLog
  178. +++ b/ld/ChangeLog
  179. @@ -1,3 +1,27 @@
  180. +2018-07-23 H.J. Lu <hongjiu.lu@intel.com>
  181. +
  182. + PR ld/23428
  183. + * testsuite/ld-elf/linux-x86.S: New file.
  184. + * testsuite/ld-elf/linux-x86.exp: Likewise.
  185. + * testsuite/ld-elf/pr23428.c: Likewise.
  186. + * testsuite/ld-elf/sec64k.exp: Pass "-z noseparate-code" to ld
  187. + for Linux/x86 targets.
  188. + * testsuite/ld-i386/abs-iamcu.d: Likewise.
  189. + * testsuite/ld-i386/abs.d: Likewise.
  190. + * testsuite/ld-i386/pr12718.d: Likewise.
  191. + * testsuite/ld-i386/pr12921.d: Likewise.
  192. + * testsuite/ld-x86-64/abs-k1om.d: Likewise.
  193. + * testsuite/ld-x86-64/abs-l1om.d: Likewise.
  194. + * testsuite/ld-x86-64/abs.d: Likewise.
  195. + * testsuite/ld-x86-64/pr12718.d: Likewise.
  196. + * testsuite/ld-x86-64/pr12921.d: Likewise.
  197. + * testsuite/ld-linkonce/zeroeh.ld: Discard .note.gnu.property
  198. + section.
  199. + * testsuite/ld-scripts/print-memory-usage.t: Likewise.
  200. + * testsuite/ld-scripts/size-2.t: Likewise.
  201. + * testsuite/lib/ld-lib.exp (run_ld_link_exec_tests): Use ld to
  202. + create executable if language is "asm".
  203. +
  204. 2018-07-18 Nick Clifton <nickc@redhat.com>
  205. 2.31.1 Release point.
  206. diff --git a/ld/testsuite/ld-elf/linux-x86.S b/ld/testsuite/ld-elf/linux-x86.S
  207. new file mode 100644
  208. index 0000000..bdf40c6
  209. --- /dev/null
  210. +++ b/ld/testsuite/ld-elf/linux-x86.S
  211. @@ -0,0 +1,63 @@
  212. + .text
  213. + .globl _start
  214. + .type _start,@function
  215. + .p2align 4
  216. +_start:
  217. + xorl %ebp, %ebp
  218. +#ifdef __LP64__
  219. + popq %rdi
  220. + movq %rsp, %rsi
  221. + andq $~15, %rsp
  222. +#elif defined __x86_64__
  223. + mov (%rsp),%edi
  224. + addl $4,%esp
  225. + movl %esp, %esi
  226. + andl $~15, %esp
  227. +#else
  228. + popl %esi
  229. + movl %esp, %ecx
  230. + andl $~15, %esp
  231. +
  232. + subl $8,%esp
  233. + pushl %ecx
  234. + pushl %esi
  235. +#endif
  236. +
  237. + call main
  238. +
  239. + hlt
  240. +
  241. + .type syscall, @function
  242. + .globl syscall
  243. + .p2align 4
  244. +syscall:
  245. +#ifdef __x86_64__
  246. + movq %rdi, %rax /* Syscall number -> rax. */
  247. + movq %rsi, %rdi /* shift arg1 - arg5. */
  248. + movq %rdx, %rsi
  249. + movq %rcx, %rdx
  250. + movq %r8, %r10
  251. + movq %r9, %r8
  252. + movq 8(%rsp),%r9 /* arg6 is on the stack. */
  253. + syscall /* Do the system call. */
  254. +#else
  255. + push %ebp
  256. + push %edi
  257. + push %esi
  258. + push %ebx
  259. + mov 0x2c(%esp),%ebp
  260. + mov 0x28(%esp),%edi
  261. + mov 0x24(%esp),%esi
  262. + mov 0x20(%esp),%edx
  263. + mov 0x1c(%esp),%ecx
  264. + mov 0x18(%esp),%ebx
  265. + mov 0x14(%esp),%eax
  266. + int $0x80
  267. + pop %ebx
  268. + pop %esi
  269. + pop %edi
  270. + pop %ebp
  271. +#endif
  272. + ret /* Return to caller. */
  273. + .size syscall, .-syscall
  274. + .section .note.GNU-stack,"",@progbits
  275. diff --git a/ld/testsuite/ld-elf/linux-x86.exp b/ld/testsuite/ld-elf/linux-x86.exp
  276. new file mode 100644
  277. index 0000000..36217c6
  278. --- /dev/null
  279. +++ b/ld/testsuite/ld-elf/linux-x86.exp
  280. @@ -0,0 +1,46 @@
  281. +# Expect script for simple native Linux/x86 tests.
  282. +# Copyright (C) 2018 Free Software Foundation, Inc.
  283. +#
  284. +# This file is part of the GNU Binutils.
  285. +#
  286. +# This program is free software; you can redistribute it and/or modify
  287. +# it under the terms of the GNU General Public License as published by
  288. +# the Free Software Foundation; either version 3 of the License, or
  289. +# (at your option) any later version.
  290. +#
  291. +# This program is distributed in the hope that it will be useful,
  292. +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  293. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  294. +# GNU General Public License for more details.
  295. +#
  296. +# You should have received a copy of the GNU General Public License
  297. +# along with this program; if not, write to the Free Software
  298. +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  299. +# MA 02110-1301, USA.
  300. +#
  301. +
  302. +# Test very simple native Linux/x86 programs with linux-x86.S.
  303. +if { ![isnative] || [which $CC] == 0 \
  304. + || (![istarget "i?86-*-linux*"] \
  305. + && ![istarget "x86_64-*-linux*"] \
  306. + && ![istarget "amd64-*-linux*"]) } {
  307. + return
  308. +}
  309. +
  310. +# Add $PLT_CFLAGS if PLT is expected.
  311. +global PLT_CFLAGS
  312. +# Add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if non-PIE is required.
  313. +global NOPIE_CFLAGS NOPIE_LDFLAGS
  314. +
  315. +run_ld_link_exec_tests [list \
  316. + [list \
  317. + "Run PR ld/23428 test" \
  318. + "--no-dynamic-linker -z separate-code" \
  319. + "" \
  320. + { linux-x86.S pr23428.c } \
  321. + "pr23428" \
  322. + "pass.out" \
  323. + "$NOPIE_CFLAGS -fno-asynchronous-unwind-tables" \
  324. + "asm" \
  325. + ] \
  326. +]
  327. diff --git a/ld/testsuite/ld-elf/pr23428.c b/ld/testsuite/ld-elf/pr23428.c
  328. new file mode 100644
  329. index 0000000..3631ed7
  330. --- /dev/null
  331. +++ b/ld/testsuite/ld-elf/pr23428.c
  332. @@ -0,0 +1,43 @@
  333. +#include <unistd.h>
  334. +#include <link.h>
  335. +#include <syscall.h>
  336. +
  337. +#define STRING_COMMA_LEN(STR) (STR), (sizeof (STR) - 1)
  338. +
  339. +int
  340. +main (int argc, char **argv)
  341. +{
  342. + char **ev = &argv[argc + 1];
  343. + char **evp = ev;
  344. + ElfW(auxv_t) *av;
  345. + const ElfW(Phdr) *phdr = NULL;
  346. + size_t phnum = 0;
  347. + size_t loadnum = 0;
  348. + int fd = STDOUT_FILENO;
  349. + size_t i;
  350. +
  351. + while (*evp++ != NULL)
  352. + ;
  353. +
  354. + av = (ElfW(auxv_t) *) evp;
  355. +
  356. + for (; av->a_type != AT_NULL; ++av)
  357. + switch (av->a_type)
  358. + {
  359. + case AT_PHDR:
  360. + phdr = (const void *) av->a_un.a_val;
  361. + break;
  362. + case AT_PHNUM:
  363. + phnum = av->a_un.a_val;
  364. + break;
  365. + }
  366. +
  367. + for (i = 0; i < phnum; i++, phdr++)
  368. + if (phdr->p_type == PT_LOAD)
  369. + loadnum++;
  370. +
  371. + syscall (SYS_write, fd, STRING_COMMA_LEN ("PASS\n"));
  372. +
  373. + syscall (SYS_exit, !loadnum);
  374. + return 0;
  375. +}
  376. diff --git a/ld/testsuite/ld-elf/sec64k.exp b/ld/testsuite/ld-elf/sec64k.exp
  377. index b58139e..3909c0e 100644
  378. --- a/ld/testsuite/ld-elf/sec64k.exp
  379. +++ b/ld/testsuite/ld-elf/sec64k.exp
  380. @@ -177,6 +177,8 @@ if { ![istarget "d10v-*-*"]
  381. foreach sfile $sfiles { puts $ofd "#source: $sfile" }
  382. if { [istarget spu*-*-*] } {
  383. puts $ofd "#ld: --local-store 0:0"
  384. + } elseif { [istarget "i?86-*-linux*"] || [istarget "x86_64-*-linux*"] } {
  385. + puts $ofd "#ld: -z noseparate-code"
  386. } else {
  387. puts $ofd "#ld:"
  388. }
  389. diff --git a/ld/testsuite/ld-i386/abs-iamcu.d b/ld/testsuite/ld-i386/abs-iamcu.d
  390. index ac9beff..aba7d6b 100644
  391. --- a/ld/testsuite/ld-i386/abs-iamcu.d
  392. +++ b/ld/testsuite/ld-i386/abs-iamcu.d
  393. @@ -2,7 +2,7 @@
  394. #source: abs.s
  395. #source: zero.s
  396. #as: --32 -march=iamcu
  397. -#ld: -m elf_iamcu
  398. +#ld: -m elf_iamcu -z noseparate-code
  399. #objdump: -rs -j .text
  400. .*: file format .*
  401. diff --git a/ld/testsuite/ld-i386/abs.d b/ld/testsuite/ld-i386/abs.d
  402. index e660aca..191ee44 100644
  403. --- a/ld/testsuite/ld-i386/abs.d
  404. +++ b/ld/testsuite/ld-i386/abs.d
  405. @@ -2,7 +2,7 @@
  406. #as: --32
  407. #source: abs.s
  408. #source: zero.s
  409. -#ld: -melf_i386
  410. +#ld: -melf_i386 -z noseparate-code
  411. #objdump: -rs
  412. .*: file format .*
  413. diff --git a/ld/testsuite/ld-i386/pr12718.d b/ld/testsuite/ld-i386/pr12718.d
  414. index ec51540..7eba52d 100644
  415. --- a/ld/testsuite/ld-i386/pr12718.d
  416. +++ b/ld/testsuite/ld-i386/pr12718.d
  417. @@ -1,6 +1,6 @@
  418. #name: PR ld/12718
  419. #as: --32
  420. -#ld: -melf_i386
  421. +#ld: -melf_i386 -z noseparate-code
  422. #readelf: -S
  423. There are 5 section headers, starting at offset 0x[0-9a-f]+:
  424. diff --git a/ld/testsuite/ld-i386/pr12921.d b/ld/testsuite/ld-i386/pr12921.d
  425. index e49079b..ea2da3e 100644
  426. --- a/ld/testsuite/ld-i386/pr12921.d
  427. +++ b/ld/testsuite/ld-i386/pr12921.d
  428. @@ -1,6 +1,6 @@
  429. #name: PR ld/12921
  430. #as: --32
  431. -#ld: -melf_i386
  432. +#ld: -melf_i386 -z noseparate-code
  433. #readelf: -S --wide
  434. There are 7 section headers, starting at offset 0x[0-9a-f]+:
  435. diff --git a/ld/testsuite/ld-linkonce/zeroeh.ld b/ld/testsuite/ld-linkonce/zeroeh.ld
  436. index b22eaa1..f89855a 100644
  437. --- a/ld/testsuite/ld-linkonce/zeroeh.ld
  438. +++ b/ld/testsuite/ld-linkonce/zeroeh.ld
  439. @@ -2,4 +2,5 @@ SECTIONS {
  440. .text 0xa00 : { *(.text); *(.gnu.linkonce.t.*) }
  441. .gcc_except_table 0x2000 : { *(.gcc_except_table) }
  442. .eh_frame 0x4000 : { *(.eh_frame) }
  443. + /DISCARD/ : { *(.note.gnu.property) }
  444. }
  445. diff --git a/ld/testsuite/ld-scripts/print-memory-usage.t b/ld/testsuite/ld-scripts/print-memory-usage.t
  446. index 5ff057a..6eda1d2 100644
  447. --- a/ld/testsuite/ld-scripts/print-memory-usage.t
  448. +++ b/ld/testsuite/ld-scripts/print-memory-usage.t
  449. @@ -11,4 +11,6 @@ SECTIONS
  450. *(.data)
  451. *(.rw)
  452. }
  453. +
  454. + /DISCARD/ : { *(.note.gnu.property) }
  455. }
  456. diff --git a/ld/testsuite/ld-scripts/size-2.t b/ld/testsuite/ld-scripts/size-2.t
  457. index 7238639..c3c4edd 100644
  458. --- a/ld/testsuite/ld-scripts/size-2.t
  459. +++ b/ld/testsuite/ld-scripts/size-2.t
  460. @@ -18,4 +18,5 @@ SECTIONS
  461. LONG (SIZEOF (.tdata))
  462. LONG (SIZEOF (.tbss))
  463. } :image
  464. + /DISCARD/ : { *(.note.gnu.property) }
  465. }
  466. diff --git a/ld/testsuite/ld-x86-64/abs-k1om.d b/ld/testsuite/ld-x86-64/abs-k1om.d
  467. index 2c26639..6b0fde0 100644
  468. --- a/ld/testsuite/ld-x86-64/abs-k1om.d
  469. +++ b/ld/testsuite/ld-x86-64/abs-k1om.d
  470. @@ -2,7 +2,7 @@
  471. #source: ../ld-i386/abs.s
  472. #source: ../ld-i386/zero.s
  473. #as: --64 -march=k1om
  474. -#ld: -m elf_k1om
  475. +#ld: -m elf_k1om -z noseparate-code
  476. #objdump: -rs -j .text
  477. .*: file format .*
  478. diff --git a/ld/testsuite/ld-x86-64/abs-l1om.d b/ld/testsuite/ld-x86-64/abs-l1om.d
  479. index 1fb96d4..f87869f 100644
  480. --- a/ld/testsuite/ld-x86-64/abs-l1om.d
  481. +++ b/ld/testsuite/ld-x86-64/abs-l1om.d
  482. @@ -2,7 +2,7 @@
  483. #source: ../ld-i386/abs.s
  484. #source: ../ld-i386/zero.s
  485. #as: --64 -march=l1om
  486. -#ld: -m elf_l1om
  487. +#ld: -m elf_l1om -z noseparate-code
  488. #objdump: -rs -j .text
  489. #target: x86_64-*-linux*
  490. diff --git a/ld/testsuite/ld-x86-64/abs.d b/ld/testsuite/ld-x86-64/abs.d
  491. index b24b018..d99ab46 100644
  492. --- a/ld/testsuite/ld-x86-64/abs.d
  493. +++ b/ld/testsuite/ld-x86-64/abs.d
  494. @@ -1,7 +1,7 @@
  495. #name: Absolute non-overflowing relocs
  496. #source: ../ld-i386/abs.s
  497. #source: ../ld-i386/zero.s
  498. -#ld:
  499. +#ld: -z noseparate-code
  500. #objdump: -rs
  501. .*: file format .*
  502. diff --git a/ld/testsuite/ld-x86-64/pr12718.d b/ld/testsuite/ld-x86-64/pr12718.d
  503. index 07d1732..2c503ff 100644
  504. --- a/ld/testsuite/ld-x86-64/pr12718.d
  505. +++ b/ld/testsuite/ld-x86-64/pr12718.d
  506. @@ -1,6 +1,6 @@
  507. #name: PR ld/12718
  508. #as: --64
  509. -#ld: -melf_x86_64
  510. +#ld: -melf_x86_64 -z noseparate-code
  511. #readelf: -S --wide
  512. There are 5 section headers, starting at offset 0x[0-9a-f]+:
  513. diff --git a/ld/testsuite/ld-x86-64/pr12921.d b/ld/testsuite/ld-x86-64/pr12921.d
  514. index 6fe6abe..1162d55 100644
  515. --- a/ld/testsuite/ld-x86-64/pr12921.d
  516. +++ b/ld/testsuite/ld-x86-64/pr12921.d
  517. @@ -1,6 +1,6 @@
  518. #name: PR ld/12921
  519. #as: --64
  520. -#ld: -melf_x86_64
  521. +#ld: -melf_x86_64 -z noseparate-code
  522. #readelf: -S --wide
  523. There are 7 section headers, starting at offset 0x[0-9a-f]+:
  524. diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
  525. index cfbefe9..1095091 100644
  526. --- a/ld/testsuite/lib/ld-lib.exp
  527. +++ b/ld/testsuite/lib/ld-lib.exp
  528. @@ -1482,7 +1482,10 @@ proc run_ld_link_exec_tests { ldtests args } {
  529. continue
  530. }
  531. - if { [ string match "c++" $lang ] } {
  532. + if { [ string match "asm" $lang ] } {
  533. + set link_proc ld_link
  534. + set link_cmd $ld
  535. + } elseif { [ string match "c++" $lang ] } {
  536. set link_proc ld_link
  537. set link_cmd $CXX
  538. } else {
  539. --
  540. 2.9.3