Re: ARC binutils init/fini (was Re: [PATCH 03/21] ARC: ABI Implementation)

2019-01-28 Thread Vineet Gupta
On 1/28/19 3:13 PM, Joseph Myers wrote:
> This was discussed at length in the C-Sky discussion.  In short: the 
> proper fix is to change that configure test to apply for cross compilation 
> as well, other than in the very limited case where it tries to run 
> something (but doing so is not appropriate in the current 
> regression-fixes-only GCC development stage).  You can hack around it with 
> gcc_cv_initfini_array=yes for the target in config.gcc, as done by a few 
> architectures.  Or you can define the relevant target macros in 
> gcc/config//.h to force init_array / fini_array use 
> independent of the configure test, as done for AArch64.

Awesome, now I see how it was working for RISCV (config test printed "cached") 
and
AArch64
I've added a local hack to gcc.config to test things out and will tackle this 
over
at gcc mailing list.

Many thx for untangling this for me. I found the C-Sky discussion as well [1]
adding a link here for someone else in future who trips on this again.

-Vineet

[1] https://sourceware.org/ml/libc-alpha/2018-11/msg00870.html


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: ARC binutils init/fini (was Re: [PATCH 03/21] ARC: ABI Implementation)

2019-01-28 Thread Joseph Myers
On Mon, 28 Jan 2019, Vineet Gupta wrote:

> In the failing case, the dsos are NOT getting the DT_INIT/DT_FINI 
> dynamic tags

And they shouldn't be (they should have DT_INIT_ARRAY / DT_FINI_ARRAY 
instead).

> (1). gcc config test failing (false alaram)
> 
> | host-gcc-final-ab544139bfee/build/gcc/config.log
> |
> |configure:22941: checking for .preinit_array/.init_array/.fini_array support
> |configure:23106: checking cross compile... guessing
> |configure:23111: result: no
> 
> gcc was seemingly built w/o init_array support leading to inclusion of default
> gcc/config/initfini-array.h
> However doing a glibc aarch64 build I see the same output so perhaps it is not
> relevant.

This was discussed at length in the C-Sky discussion.  In short: the 
proper fix is to change that configure test to apply for cross compilation 
as well, other than in the very limited case where it tries to run 
something (but doing so is not appropriate in the current 
regression-fixes-only GCC development stage).  You can hack around it with 
gcc_cv_initfini_array=yes for the target in config.gcc, as done by a few 
architectures.  Or you can define the relevant target macros in 
gcc/config//.h to force init_array / fini_array use 
independent of the configure test, as done for AArch64.

-- 
Joseph S. Myers
jos...@codesourcery.com

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


ARC binutils init/fini (was Re: [PATCH 03/21] ARC: ABI Implementation)

2019-01-28 Thread Vineet Gupta
On 12/18/18 3:09 PM, Joseph Myers wrote:
>> diff --git a/sysdeps/arc/crti.S b/sysdeps/arc/crti.S
> As a new port I think it would be best to use init_array in your Implies 
> file so you don't need these crti / crtn files, and make GCC generate 
> init_array / fini_array exclusively.  (See RISC-V and C-Sky discussions of 
> this issue.)
> 

I did the switch and while is working, there are additional test failures

| FAIL: dlfcn/bug-atexit1
| FAIL: dlfcn/bug-atexit2
| FAIL: dlfcn/tstatexit
| FAIL: dlfcn/tstcxaatexit
| FAIL: nptl/tst-atfork2
| FAIL: nptl/tst-cond17
| FAIL: stdlib/test-dlclose-exit-race

In the failing case, the dsos are NOT getting the DT_INIT/DT_FINI dynamic tags

Consider glibc test dlfcn/tstatexit, which uses a dso modatexit.so

In good case

| arc-linux-readelf -a modatexit.os
|
| Section Headers:
|  [Nr] Name  TypeAddr OffSize   ES Flg Lk Inf 
Al
|  [ 9] .init PROGBITS047c 00047c 44 00  AX  0   0  
4
|  [12] .fini PROGBITS06f8 0006f8 28 00  AX  0   0  
4
|
| Dynamic section at offset 0x1f08 contains 23 entries:
|  0x000c (INIT)   0x47c
|  0x000d (FINI)   0x6f8

In broken case, init/fini sections exist,  but DT_INI/DT_FINI are missing.

|
| Dynamic section at offset 0x1f2c contains 19 entries: <-- missing INIT/FINI
|


I suspected some bintuils/gcc shenanigans and tried hacking around, but was led
far too astray.


(1). gcc config test failing (false alaram)

| host-gcc-final-ab544139bfee/build/gcc/config.log
|
|configure:22941: checking for .preinit_array/.init_array/.fini_array support
|configure:23106: checking cross compile... guessing
|configure:23111: result: no

gcc was seemingly built w/o init_array support leading to inclusion of default
gcc/config/initfini-array.h
However doing a glibc aarch64 build I see the same output so perhaps it is not
relevant.

(2). ARC binutils port seems to hardwire _init/_fini (and the only arch to do
that) so I ripped out the relevant handling from ld, but that doesn't help.


https://github.com/foss-for-synopsys-dwc-arc-processors/binutils-gdb/commit/56771171fa7cb9e31c65e26a656a8588d603d924


So I'm not sure if this is deficiency of linker emulation script or code ld/bfd 
etc..

-Vineet

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH 03/21] ARC: ABI Implementation

2018-12-19 Thread Joseph Myers
On Wed, 19 Dec 2018, Vineet Gupta wrote:

> On 12/19/18 9:40 AM, Joseph Myers wrote:
> > Architecture maintainers need wiki accounts in any case (to post test 
> > results for their architectures during every release freeze period), so 
> > you should create an account and post its name so someone can add it to 
> > EditorGroup so you can edit.
> 
> Created now: VineetGupta

Added to EditorGroup.

-- 
Joseph S. Myers
jos...@codesourcery.com

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH 03/21] ARC: ABI Implementation

2018-12-19 Thread Vineet Gupta
On 12/19/18 9:40 AM, Joseph Myers wrote:
> Architecture maintainers need wiki accounts in any case (to post test 
> results for their architectures during every release freeze period), so 
> you should create an account and post its name so someone can add it to 
> EditorGroup so you can edit.

Created now: VineetGupta

Thx,
-Vineet

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH 03/21] ARC: ABI Implementation

2018-12-19 Thread Joseph Myers
On Tue, 18 Dec 2018, Vineet Gupta wrote:

> P.S. Is there a lint file or are these style guidelines in wiki 
> somewhere. If not I can volunteer to capture them in a wiki/readme for 
> future port submissions.

In addition to the GNU Coding Standards (which cover many things such as 
comment formatting and spaces before '('), we have 
 which discusses 
various glibc-specific details.  If you find there are points of the style 
in glibc which aren't documented in either place, then, yes, it would be a 
good idea to add them to the wiki (I just added a few).

Architecture maintainers need wiki accounts in any case (to post test 
results for their architectures during every release freeze period), so 
you should create an account and post its name so someone can add it to 
EditorGroup so you can edit.

Where the formatting issues pointed out exist in some existing code in 
glibc, it might also make sense to fix that existing code to follow the 
standards more closely so it provides a better example for new code.  
However, such formatting changes to existing code may be controversial 
(especially for code that originally came from third-party sources using 
completely different formatting - though in my view, where such files are 
now maintained in glibc without ongoing updates from upstream, we ought to 
make the formatting consistent to simplify maintenance).

-- 
Joseph S. Myers
jos...@codesourcery.com

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH 03/21] ARC: ABI Implementation

2018-12-18 Thread Vineet Gupta
On 12/18/18 3:09 PM, Joseph Myers wrote:
> On Tue, 18 Dec 2018, Vineet Gupta wrote:
> 
>> +/* FLAG 1 is privilege mode only instruction, hence will crash any program 
>> */
> 
> Generally, throughout the port, make sure comments end ".  " (full stop, 
> two spaces, end of comment).  I won't remark on other places with this 
> formatting issue.

OK. Fixed series wide.

>> diff --git a/sysdeps/arc/crti.S b/sysdeps/arc/crti.S
> 
> As a new port I think it would be best to use init_array in your Implies 
> file so you don't need these crti / crtn files, and make GCC generate 
> init_array / fini_array exclusively.  (See RISC-V and C-Sky discussions of 
> this issue.)

OK I can try enabling this !

>> +#ifdef __A7__
>> +#define ARC_PLT_SIZE12
>> +#else
>> +#define ARC_PLT_SIZE16
>> +#endif
> 
> Except for the multiple-include guards round a whole header file, 
> preprocessor directives inside #if should have indentation in glibc, so 
> "# define" (and "#  define" inside two levels of #if, etc.).  (As usual, 
> fix this throughout the port; I won't list other individual places with 
> this issue.)

Done series wide.

> 
>> +#define reloc_index \
>> +({  \
>> +  unsigned long plt0 = D_PTR (l, l_info[DT_PLTGOT]);\
>> +  unsigned long pltn = reloc_arg;   \
>> +  /* exclude PL0 and PLT1 */\
> 
> Note the first letter of a comment should be capitalized (in addition to 
> ending with ".  ").
> 
>> +  unsigned long idx = (pltn - plt0)/ARC_PLT_SIZE - 2;   \
> 
> glibc style uses "unsigned long int", not just "unsigned long".

Done series wide.

>> diff --git a/sysdeps/arc/tls-macros.h b/sysdeps/arc/tls-macros.h
>> new file mode 100644
>> index ..51855edef6e7
>> --- /dev/null
>> +++ b/sysdeps/arc/tls-macros.h
>> @@ -0,0 +1,29 @@
>> +/* Macros to support TLS testing in times of missing compiler support.  */
> 
> Any file more than ten lines long should have copyright and license 
> notices.

Done.

P.S. Is there a lint file or are these style guidelines in wiki somewhere. If 
not
I can volunteer to capture them in a wiki/readme for future port submissions.

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


Re: [PATCH 03/21] ARC: ABI Implementation

2018-12-18 Thread Joseph Myers
On Tue, 18 Dec 2018, Vineet Gupta wrote:

> +/* FLAG 1 is privilege mode only instruction, hence will crash any program */

Generally, throughout the port, make sure comments end ".  " (full stop, 
two spaces, end of comment).  I won't remark on other places with this 
formatting issue.

> diff --git a/sysdeps/arc/crti.S b/sysdeps/arc/crti.S

As a new port I think it would be best to use init_array in your Implies 
file so you don't need these crti / crtn files, and make GCC generate 
init_array / fini_array exclusively.  (See RISC-V and C-Sky discussions of 
this issue.)

> +#ifdef __A7__
> +#define ARC_PLT_SIZE 12
> +#else
> +#define ARC_PLT_SIZE 16
> +#endif

Except for the multiple-include guards round a whole header file, 
preprocessor directives inside #if should have indentation in glibc, so 
"# define" (and "#  define" inside two levels of #if, etc.).  (As usual, 
fix this throughout the port; I won't list other individual places with 
this issue.)

> +#define reloc_index  \
> +({   \
> +  unsigned long plt0 = D_PTR (l, l_info[DT_PLTGOT]); \
> +  unsigned long pltn = reloc_arg;\
> +  /* exclude PL0 and PLT1 */ \

Note the first letter of a comment should be capitalized (in addition to 
ending with ".  ").

> +  unsigned long idx = (pltn - plt0)/ARC_PLT_SIZE - 2;\

glibc style uses "unsigned long int", not just "unsigned long".

> diff --git a/sysdeps/arc/tls-macros.h b/sysdeps/arc/tls-macros.h
> new file mode 100644
> index ..51855edef6e7
> --- /dev/null
> +++ b/sysdeps/arc/tls-macros.h
> @@ -0,0 +1,29 @@
> +/* Macros to support TLS testing in times of missing compiler support.  */

Any file more than ten lines long should have copyright and license 
notices.

-- 
Joseph S. Myers
jos...@codesourcery.com

___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc


[PATCH 03/21] ARC: ABI Implementation

2018-12-18 Thread Vineet Gupta
This code deals with the ARC ABI.

Signed-off-by: Vineet Gupta 
---
 ChangeLog| 20 
 sysdeps/arc/__longjmp.S  | 50 
 sysdeps/arc/abort-instr.h|  2 ++
 sysdeps/arc/bits/endian.h| 12 +++
 sysdeps/arc/bits/setjmp.h| 33 +++
 sysdeps/arc/bsd-_setjmp.S|  1 +
 sysdeps/arc/bsd-setjmp.S |  1 +
 sysdeps/arc/crti.S   | 77 
 sysdeps/arc/crtn.S   | 56 
 sysdeps/arc/dl-runtime.c | 21 
 sysdeps/arc/dl-sysdep.h  | 25 ++
 sysdeps/arc/dl-trampoline.S  | 72 +
 sysdeps/arc/gccframe.h   | 21 
 sysdeps/arc/gmp-mparam.h | 23 +
 sysdeps/arc/jmpbuf-offsets.h | 46 ++
 sysdeps/arc/jmpbuf-unwind.h  | 47 +++
 sysdeps/arc/machine-gmon.h   | 33 +++
 sysdeps/arc/memusage.h   | 23 +
 sysdeps/arc/setjmp.S | 64 
 sysdeps/arc/sysdep.h | 49 
 sysdeps/arc/tls-macros.h | 29 +
 21 files changed, 705 insertions(+)
 create mode 100644 sysdeps/arc/__longjmp.S
 create mode 100644 sysdeps/arc/abort-instr.h
 create mode 100644 sysdeps/arc/bits/endian.h
 create mode 100644 sysdeps/arc/bits/setjmp.h
 create mode 100644 sysdeps/arc/bsd-_setjmp.S
 create mode 100644 sysdeps/arc/bsd-setjmp.S
 create mode 100644 sysdeps/arc/crti.S
 create mode 100644 sysdeps/arc/crtn.S
 create mode 100644 sysdeps/arc/dl-runtime.c
 create mode 100644 sysdeps/arc/dl-sysdep.h
 create mode 100644 sysdeps/arc/dl-trampoline.S
 create mode 100644 sysdeps/arc/gccframe.h
 create mode 100644 sysdeps/arc/gmp-mparam.h
 create mode 100644 sysdeps/arc/jmpbuf-offsets.h
 create mode 100644 sysdeps/arc/jmpbuf-unwind.h
 create mode 100644 sysdeps/arc/machine-gmon.h
 create mode 100644 sysdeps/arc/memusage.h
 create mode 100644 sysdeps/arc/setjmp.S
 create mode 100644 sysdeps/arc/sysdep.h
 create mode 100644 sysdeps/arc/tls-macros.h

diff --git a/ChangeLog b/ChangeLog
index 3ec6eb82d2fe..c2efdafa9861 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,26 @@
syscall-template file.
* stdlib/longlong.h: Fix asm constraints for ARC code.
* elf/elf.h: add defines for ARC.
+   * sysdeps/arc/__longjmp.S: New file.
+   * sysdeps/arc/abort-instr.h: New file.
+   * sysdeps/arc/bits/endian.h: New file.
+   * sysdeps/arc/bits/setjmp.h: New file.
+   * sysdeps/arc/bsd-_setjmp.S: New file.
+   * sysdeps/arc/bsd-setjmp.S: New file.
+   * sysdeps/arc/crti.S: New file.
+   * sysdeps/arc/crtn.S: New file.
+   * sysdeps/arc/dl-runtime.c: New file.
+   * sysdeps/arc/dl-sysdep.h: New file.
+   * sysdeps/arc/dl-trampoline.S: New file.
+   * sysdeps/arc/gccframe.h: New file.
+   * sysdeps/arc/gmp-mparam.h: New file.
+   * sysdeps/arc/jmpbuf-offsets.h: New file.
+   * sysdeps/arc/jmpbuf-unwind.h: New file.
+   * sysdeps/arc/machine-gmon.h: New file.
+   * sysdeps/arc/memusage.h: New file.
+   * sysdeps/arc/setjmp.S: New file.
+   * sysdeps/arc/sysdep.h: New file.
+   * sysdeps/arc/tls-macros.h: New file.
 
 2018-12-17  Joseph Myers  
 
diff --git a/sysdeps/arc/__longjmp.S b/sysdeps/arc/__longjmp.S
new file mode 100644
index ..5ef271536bcc
--- /dev/null
+++ b/sysdeps/arc/__longjmp.S
@@ -0,0 +1,50 @@
+/* longjmp for ARC.
+   Copyright (C) 2017-2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   .  */
+
+#include 
+#include 
+
+;@ r0 = jump buffer from which regs will be restored
+;@ r1 = value that setjmp( ) will return due to this longjmp
+
+ENTRY(__longjmp)
+
+   ld_s r13,   [r0]
+   ld_s r14,   [r0,4]
+   ld   r15,   [r0,8]
+   ld   r16,   [r0,12]
+   ld   r17,   [r0,16]
+   ld   r18,   [r0,20]
+   ld   r19,   [r0,24]
+   ld   r20,   [r0,28]
+   ld   r21,   [r0,32]
+   ld   r22,   [r0,36]
+   ld   r23,   [r0,40]
+   ld   r24,   [r0,44]
+   ld   r25,   [r0,48]
+
+   ld   blink, [r0,60]
+   ld   fp,[r0,52]
+   ld   sp,[r0,56]
+
+   mov.f  r0, r1   ;