* [Patch] Windows TLS enhancements
@ 2012-01-16 17:26 Daniel Green
2012-08-03 20:09 ` NightStrike
2012-08-07 13:47 ` nick clifton
0 siblings, 2 replies; 3+ messages in thread
From: Daniel Green @ 2012-01-16 17:26 UTC (permalink / raw)
To: binutils
[-- Attachment #1: Type: text/plain, Size: 396 bytes --]
Included are 2 patches to help support TLS on Windows.
secrel32.patch:
Allows use of secrel32 as an operand in gas. Such as "movl
$symbol@secrel32, %eax"
pe_tls.patch:
Convention requires that the symbols defining the start and end of
the TLS section be within .tls$AAA and .tls$ZZZ. The changes here
ensure those sections appear at the start and end of the TLS section.
Daniel
[-- Attachment #2: secrel32.patch --]
[-- Type: text/plain, Size: 3305 bytes --]
Index: gas/config/tc-i386.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-i386.c,v
retrieving revision 1.480
diff -u -p -r1.480 tc-i386.c
--- gas/config/tc-i386.c 13 Jan 2012 22:19:31 -0000 1.480
+++ gas/config/tc-i386.c 16 Jan 2012 17:07:57 -0000
@@ -6685,6 +6685,105 @@ lex_got (enum bfd_reloc_code_real *rel,
}
#endif
+#ifdef TE_PE
+ #ifdef lex_got
+ #undef lex_got
+ #endif
+/* Parse operands of the form
+ <symbol>@SECREL32+<nnn>
+
+ If we find one, set up the correct relocation in RELOC and copy the
+ input string, minus the `@SECREL32' into a malloc'd buffer for
+ parsing by the calling routine. Return this buffer, and if ADJUST
+ is non-null set it to the length of the string we removed from the
+ input line. Otherwise return NULL.
+
+ This function is copied from the ELF version above adjusted for PE targets.
+ */
+static char *
+lex_got (enum bfd_reloc_code_real *rel ATTRIBUTE_UNUSED,
+ int *adjust ATTRIBUTE_UNUSED,
+ i386_operand_type *types ATTRIBUTE_UNUSED)
+{
+ static const struct {
+ const char *str;
+ int len;
+ const enum bfd_reloc_code_real rel[2];
+ const i386_operand_type types64;
+ } gotrel[] = {
+ { STRING_COMMA_LEN ("SECREL32"), { BFD_RELOC_32_SECREL,
+ BFD_RELOC_32_SECREL },
+ OPERAND_TYPE_IMM32_32S_64_DISP32_64 },
+ };
+
+ char *cp;
+ unsigned j;
+
+ for (cp = input_line_pointer; *cp != '@'; cp++)
+ if (is_end_of_line[(unsigned char) *cp] || *cp == ',')
+ return NULL;
+
+ for (j = 0; j < ARRAY_SIZE (gotrel); j++)
+ {
+ int len = gotrel[j].len;
+ if (strncasecmp (cp + 1, gotrel[j].str, len) == 0)
+ {
+ if (gotrel[j].rel[object_64bit] != 0)
+ {
+ int first, second;
+ char *tmpbuf, *past_reloc;
+
+ *rel = gotrel[j].rel[object_64bit];
+ if (adjust)
+ *adjust = len;
+
+ if (types)
+ {
+ if (flag_code != CODE_64BIT)
+ {
+ types->bitfield.imm32 = 1;
+ types->bitfield.disp32 = 1;
+ }
+ else
+ *types = gotrel[j].types64;
+ }
+
+ /* The length of the first part of our input line. */
+ first = cp - input_line_pointer;
+
+ /* The second part goes from after the reloc token until
+ (and including) an end_of_line char or comma. */
+ past_reloc = cp + 1 + len;
+ cp = past_reloc;
+ while (!is_end_of_line[(unsigned char) *cp] && *cp != ',')
+ ++cp;
+ second = cp + 1 - past_reloc;
+
+ /* Allocate and copy string. The trailing NUL shouldn't
+ be necessary, but be safe. */
+ tmpbuf = (char *) xmalloc (first + second + 2);
+ memcpy (tmpbuf, input_line_pointer, first);
+ if (second != 0 && *past_reloc != ' ')
+ /* Replace the relocation token with ' ', so that
+ errors like foo@SECLREL321 will be detected. */
+ tmpbuf[first++] = ' ';
+ memcpy (tmpbuf + first, past_reloc, second);
+ tmpbuf[first + second] = '\0';
+ return tmpbuf;
+ }
+
+ as_bad (_("@%s reloc is not supported with %d-bit output format"),
+ gotrel[j].str, 1 << (5 + object_64bit));
+ return NULL;
+ }
+ }
+
+ /* Might be a symbol version string. Don't as_bad here. */
+ return NULL;
+}
+#endif
+
+
void
x86_cons (expressionS *exp, int size)
{
[-- Attachment #3: pe_tls.patch --]
[-- Type: text/plain, Size: 2106 bytes --]
Index: ld/scripttempl/pe.sc
===================================================================
RCS file: /cvs/src/src/ld/scripttempl/pe.sc,v
retrieving revision 1.29
diff -u -p -r1.29 pe.sc
--- ld/scripttempl/pe.sc 27 Sep 2011 15:59:55 -0000 1.29
+++ ld/scripttempl/pe.sc 16 Jan 2012 17:07:59 -0000
@@ -39,9 +39,11 @@ if test "${RELOCATING}"; then
R_CRT_XP='*(SORT(.CRT$XP*)) /* Pre-termination */'
R_CRT_XT='*(SORT(.CRT$XT*)) /* Termination */'
R_TLS='
+ *(.tls$AAA)
*(.tls)
*(.tls$)
- *(SORT(.tls$*))'
+ *(SORT(.tls$*))
+ *(.tls$ZZZ)'
R_RSRC='*(SORT(.rsrc$*))'
else
R_TEXT=
@@ -179,6 +181,10 @@ SECTIONS
${RELOCATING+___crt_xt_end__ = . ;}
}
+ /* Windows TLS expects .tls\$AAA to be at the start and .tls\$ZZZ to be
+ at the end of section. This is important because _tls_start MUST
+ be at the beginning of the section to enable SECREL32 relocations with TLS
+ data. */
.tls ${RELOCATING+BLOCK(__section_alignment__)} :
{
${RELOCATING+___tls_start__ = . ;}
Index: ld/scripttempl/pep.sc
===================================================================
RCS file: /cvs/src/src/ld/scripttempl/pep.sc,v
retrieving revision 1.18
diff -u -p -r1.18 pep.sc
--- ld/scripttempl/pep.sc 27 Sep 2011 15:59:55 -0000 1.18
+++ ld/scripttempl/pep.sc 16 Jan 2012 17:07:59 -0000
@@ -39,9 +39,11 @@ if test "${RELOCATING}"; then
R_CRT_XP='*(SORT(.CRT$XP*)) /* Pre-termination */'
R_CRT_XT='*(SORT(.CRT$XT*)) /* Termination */'
R_TLS='
+ *(.tls$AAA)
*(.tls)
*(.tls$)
- *(SORT(.tls$*))'
+ *(SORT(.tls$*))
+ *(.tls$ZZZ)'
R_RSRC='*(SORT(.rsrc$*))'
else
R_TEXT=
@@ -185,6 +187,10 @@ SECTIONS
${RELOCATING+___crt_xt_end__ = . ;}
}
+ /* Windows TLS expects .tls\$AAA to be at the start and .tls\$ZZZ to be
+ at the end of the .tls section. This is important because _tls_start MUST
+ be at the beginning of the section to enable SECREL32 relocations with TLS
+ data. */
.tls ${RELOCATING+BLOCK(__section_alignment__)} :
{
${RELOCATING+___tls_start__ = . ;}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Patch] Windows TLS enhancements
2012-01-16 17:26 [Patch] Windows TLS enhancements Daniel Green
@ 2012-08-03 20:09 ` NightStrike
2012-08-07 13:47 ` nick clifton
1 sibling, 0 replies; 3+ messages in thread
From: NightStrike @ 2012-08-03 20:09 UTC (permalink / raw)
To: binutils; +Cc: Kai Tietz
Ping
On Mon, Jan 16, 2012 at 7:26 AM, Daniel Green <venix1@gmail.com> wrote:
> Included are 2 patches to help support TLS on Windows.
>
> secrel32.patch:
> Allows use of secrel32 as an operand in gas. Such as "movl
> $symbol@secrel32, %eax"
>
> pe_tls.patch:
> Convention requires that the symbols defining the start and end of the
> TLS section be within .tls$AAA and .tls$ZZZ. The changes here ensure those
> sections appear at the start and end of the TLS section.
>
> Daniel
This email went unnoticed. I contacted Daniel, and he never got a review.
Daniel, do you have a patch for GCC for this as well? Also, are you
able to make this patch current, or do you need someone else to help
in that area?
I am CC'ing Kai for help on this. Thanks, Kai!
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Patch] Windows TLS enhancements
2012-01-16 17:26 [Patch] Windows TLS enhancements Daniel Green
2012-08-03 20:09 ` NightStrike
@ 2012-08-07 13:47 ` nick clifton
1 sibling, 0 replies; 3+ messages in thread
From: nick clifton @ 2012-08-07 13:47 UTC (permalink / raw)
To: Daniel Green; +Cc: binutils
Hi Daniel,
> secrel32.patch:
> Allows use of secrel32 as an operand in gas. Such as "movl
> $symbol@secrel32, %eax"
>
> pe_tls.patch:
> Convention requires that the symbols defining the start and end of
> the TLS section be within .tls$AAA and .tls$ZZZ. The changes here
> ensure those sections appear at the start and end of the TLS section.
Approved and applied.
Note - I extended the gas/testsuite/gas/i386/secrel.[sd] testcase to
include a check that the syntax is parsed correctly.
Cheers
Nick
gas/ChangeLog
2012-08-07 Daniel Green <venix1@gmail.com>
* config/tc-i386.c (lex_got): Provide implementation for PE
format.
ld/ChangeLog
2012-08-07 Daniel Green <venix1@gmail.com>
* scripttempl/pe.sc (R_TLS): Add .tls$AAA and .tls$ZZZ.
* scripttempl/pep.sc (R_TLS): Add .tls$AAA and .tls$ZZZ.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-08-07 13:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-16 17:26 [Patch] Windows TLS enhancements Daniel Green
2012-08-03 20:09 ` NightStrike
2012-08-07 13:47 ` nick clifton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).