Re: [Tinycc-devel] -Wl,-rpath not passed through?

2016-06-06 Thread Steffen Nurpmeso
Michael Matz  wrote:
 |On Mon, 6 Jun 2016, Steffen Nurpmeso wrote:

 |I think this leaks memory when opath contains a string already.  pbuf is 

Indeed, pbuf comes from copy_linker_arg(), i sublimely overlooked
it, but indeed see now.  I'm sorry.


--steffen
commit 2a28638 (HEAD -> refs/heads/i)
Author: Steffen (Daode) Nurpmeso 
AuthorDate: 2016-06-04 15:48:15 +0200
Commit: Steffen (Daode) Nurpmeso 
CommitDate: 2016-06-06 21:50:26 +0200

Allow multiple -rpath linker arguments
---
 libtcc.c | 25 -
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/libtcc.c b/libtcc.c
index 12ee171..dd1789c 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -1834,6 +1834,29 @@ static char *copy_linker_arg(const char *p)
 return pstrncpy(tcc_malloc(q - p + 1), p, q - p);
 }
 
+static char *concat_linker_arg_path(char *opath, const char *p)
+{
+size_t plen, ol;
+char *npath, *pbuf;
+
+pbuf = copy_linker_arg(p);
+
+if (opath != NULL) {
+ol = strlen(opath);
+plen = strlen(pbuf) +1;
+npath = tcc_malloc(ol + 1 + plen);
+
+memcpy(npath, opath, ol);
+tcc_free(opath);
+
+npath[ol++] = ':';
+memcpy([ol], pbuf, plen);
+tcc_free(pbuf);
+} else
+npath = pbuf;
+return npath;
+}
+
 /* set linker options */
 static int tcc_set_linker(TCCState *s, const char *option)
 {
@@ -1880,7 +1903,7 @@ static int tcc_set_linker(TCCState *s, const char *option)
 } else if (link_option(option, "O", )) {
 ignoring = 1;
 } else if (link_option(option, "rpath=", )) {
-s->rpath = copy_linker_arg(p);
+s->rpath = concat_linker_arg_path(s->rpath, p);
 } else if (link_option(option, "section-alignment=", )) {
 s->section_align = strtoul(p, , 16);
 } else if (link_option(option, "soname=", )) {
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] -Wl,-rpath not passed through?

2016-06-06 Thread Michael Matz
Hi,

On Mon, 6 Jun 2016, Steffen Nurpmeso wrote:

> Bäh!
> Take this one, please, the other one deleted an option.
> Ciao!

I think this leaks memory when opath contains a string already.  pbuf is 
allocated memory, you free the opath, copy pbuf into npath, but then leak 
pbuf itself (it's not leaked when opath is NULL, then it's freed in the 
next call as opath).  valgrind should find it.  Fix that and push to mob 
I'd say.


Ciao,
Michael.___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] -Wl,-rpath not passed through?

2016-06-06 Thread Steffen Nurpmeso
Bäh!
Take this one, please, the other one deleted an option.
Ciao!

--steffen
commit 2b59c82 (HEAD -> refs/heads/i)
Author: Steffen (Daode) Nurpmeso 
AuthorDate: 2016-06-04 15:48:15 +0200
Commit: Steffen (Daode) Nurpmeso 
CommitDate: 2016-06-06 13:59:30 +0200

Allow multiple -rpath linker arguments
---
 libtcc.c | 24 +++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/libtcc.c b/libtcc.c
index 12ee171..07a3fad 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -1834,6 +1834,28 @@ static char *copy_linker_arg(const char *p)
 return pstrncpy(tcc_malloc(q - p + 1), p, q - p);
 }
 
+static char *concat_linker_arg_path(char *opath, const char *p)
+{
+size_t plen, ol;
+char *npath, *pbuf;
+
+pbuf = copy_linker_arg(p);
+
+if (opath != NULL) {
+ol = strlen(opath);
+plen = strlen(pbuf) +1;
+npath = tcc_malloc(ol + 1 + plen);
+
+memcpy(npath, opath, ol);
+tcc_free(opath);
+
+npath[ol++] = ':';
+memcpy([ol], pbuf, plen);
+} else
+npath = pbuf;
+return npath;
+}
+
 /* set linker options */
 static int tcc_set_linker(TCCState *s, const char *option)
 {
@@ -1880,7 +1902,7 @@ static int tcc_set_linker(TCCState *s, const char *option)
 } else if (link_option(option, "O", )) {
 ignoring = 1;
 } else if (link_option(option, "rpath=", )) {
-s->rpath = copy_linker_arg(p);
+s->rpath = concat_linker_arg_path(s->rpath, p);
 } else if (link_option(option, "section-alignment=", )) {
 s->section_align = strtoul(p, , 16);
 } else if (link_option(option, "soname=", )) {
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] -Wl,-rpath not passed through?

2016-06-06 Thread Steffen Nurpmeso
Sorry, forgot the diff:

--steffen
commit db263ba (HEAD -> refs/heads/i)
Author: Steffen (Daode) Nurpmeso 
AuthorDate: 2016-06-04 15:48:15 +0200
Commit: Steffen (Daode) Nurpmeso 
CommitDate: 2016-06-06 13:37:03 +0200

Allow multiple -rpath linker arguments
---
 libtcc.c | 26 +++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/libtcc.c b/libtcc.c
index 12ee171..ed9662d 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -1834,6 +1834,28 @@ static char *copy_linker_arg(const char *p)
 return pstrncpy(tcc_malloc(q - p + 1), p, q - p);
 }
 
+static char *concat_linker_arg_path(char *opath, const char *p)
+{
+size_t plen, ol;
+char *npath, *pbuf;
+
+pbuf = copy_linker_arg(p);
+
+if (opath != NULL) {
+ol = strlen(opath);
+plen = strlen(pbuf) +1;
+npath = tcc_malloc(ol + 1 + plen);
+
+memcpy(npath, opath, ol);
+tcc_free(opath);
+
+npath[ol++] = ':';
+memcpy([ol], pbuf, plen);
+} else
+npath = pbuf;
+return npath;
+}
+
 /* set linker options */
 static int tcc_set_linker(TCCState *s, const char *option)
 {
@@ -1880,9 +1902,7 @@ static int tcc_set_linker(TCCState *s, const char *option)
 } else if (link_option(option, "O", )) {
 ignoring = 1;
 } else if (link_option(option, "rpath=", )) {
-s->rpath = copy_linker_arg(p);
-} else if (link_option(option, "section-alignment=", )) {
-s->section_align = strtoul(p, , 16);
+s->rpath = concat_linker_arg_path(s->rpath, p);
 } else if (link_option(option, "soname=", )) {
 s->soname = copy_linker_arg(p);
 #ifdef TCC_TARGET_PE
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] -Wl,-rpath not passed through?

2016-06-06 Thread Steffen Nurpmeso
Hello.

David Mertens  wrote:
 |Also, I am not sure what others think about the first line in which y\
 |ou declare two integers and initialize them with the return values of\
 | function 
 |calls. I guess that's fine, but I don't see it often in the codebase.\
 | @Everyone, do we have a coding standard about this?

The attached diff generalizes via a new function that could be
reused.  I hope this is a bit better!
Ciao,

--steffen

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] -Wl,-rpath not passed through?

2016-06-05 Thread Michael Matz

Hi,

On Sat, 4 Jun 2016, David Mertens wrote:

Nice. I am not very familiar with this part of tcc, but I noticed the 
use of ':' as a path separator. Is this the path separator used across 
all platforms?


Yes.  On all those that support DT_RPATH or DT_RUNPATH, which is an 
ELFism ...



In particular, what about Windows?


... and hence Windows simply doesn't and isn't affected.

Also, I am not sure what others think about the first line in which you 
declare two integers and initialize them with the return values of 
function calls. I guess that's fine, but I don't see it often in the 
codebase. @Everyone, do we have a coding standard about this?


No.  IMHO it's fine.  Push to mob.


Ciao,
Michael.

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] -Wl,-rpath not passed through?

2016-06-04 Thread David Mertens
Nice. I am not very familiar with this part of tcc, but I noticed the use
of ':' as a path separator. Is this the path separator used across all
platforms? In particular, what about Windows?

Also, I am not sure what others think about the first line in which you
declare two integers and initialize them with the return values of function
calls. I guess that's fine, but I don't see it often in the codebase.
@Everyone, do we have a coding standard about this?

David

On Sat, Jun 4, 2016 at 9:46 AM, Steffen Nurpmeso  wrote:

> Hi!
>
> Pretty stormy here, huh?
>
> i wrote:
>  |Hello again!
>  |
>  |I have just recognized that i need to use -Wl,-rpath now (new
>
>  |So then, here we go:
>  |  ?0[steffen@wales nail.git]$ readelf -d s-nail
>
>  |   0x000f (RPATH)  Library rpath: [/usr/lib]
>
>  |This is still true for [mob:1ca685f], but which no longer needs
>  |a cherry-picked commit to do it.  Cool!  :-)
>
> With the attached diff we get
>
>   ?0[steffen@wales nail.git]$ readelf -d s-nail
>   Dynamic section at offset 0xf6a78 contains 19 entries:
> TagType Name/Value
>0x0001 (NEEDED) Shared library: [libssl.so.1.1]
>0x0001 (NEEDED) Shared library:
> [libcrypto.so.1.1]
>
>0x000f (RPATH)  Library rpath:
> [/home/steffen/usr/opt/.ssl-1.1.0/lib:/home/steffen/usr/lib:/home/steffen/usr/opt/tcc-mob/lib:/home/steffen/usr/opt/pcc/lib:/lib:/usr/local/lib:/usr/lib]
>
> Yay.
> Ciao!
>
> --steffen
>
> ___
> Tinycc-devel mailing list
> Tinycc-devel@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>
>


-- 
 "Debugging is twice as hard as writing the code in the first place.
  Therefore, if you write the code as cleverly as possible, you are,
  by definition, not smart enough to debug it." -- Brian Kernighan
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] -Wl,-rpath not passed through?

2016-06-04 Thread Steffen Nurpmeso
Hi!

Pretty stormy here, huh?

i wrote:
 |Hello again!
 |
 |I have just recognized that i need to use -Wl,-rpath now (new

 |So then, here we go:
 |  ?0[steffen@wales nail.git]$ readelf -d s-nail

 |   0x000f (RPATH)  Library rpath: [/usr/lib]

 |This is still true for [mob:1ca685f], but which no longer needs
 |a cherry-picked commit to do it.  Cool!  :-)

With the attached diff we get

  ?0[steffen@wales nail.git]$ readelf -d s-nail
  Dynamic section at offset 0xf6a78 contains 19 entries:
TagType Name/Value
   0x0001 (NEEDED) Shared library: [libssl.so.1.1]
   0x0001 (NEEDED) Shared library: [libcrypto.so.1.1]

   0x000f (RPATH)  Library rpath: 
[/home/steffen/usr/opt/.ssl-1.1.0/lib:/home/steffen/usr/lib:/home/steffen/usr/opt/tcc-mob/lib:/home/steffen/usr/opt/pcc/lib:/lib:/usr/local/lib:/usr/lib]

Yay.
Ciao!

--steffen
diff --git a/libtcc.c b/libtcc.c
index 12ee171..6759daa 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -1880,7 +1880,19 @@ static int tcc_set_linker(TCCState *s, const char *option)
 } else if (link_option(option, "O", )) {
 ignoring = 1;
 } else if (link_option(option, "rpath=", )) {
-s->rpath = copy_linker_arg(p);
+char *pbuf = copy_linker_arg(p);
+
+if (s->rpath != NULL) {
+size_t plen = strlen(pbuf) +1, ol = strlen(s->rpath);
+char *nbuf = tcc_malloc(ol + 1 + plen);
+
+memcpy(nbuf, s->rpath, ol);
+nbuf[ol++] = ':';
+tcc_free(s->rpath);
+memcpy([ol], pbuf, plen);
+s->rpath = nbuf;
+} else
+s->rpath = pbuf;
 } else if (link_option(option, "section-alignment=", )) {
 s->section_align = strtoul(p, , 16);
 } else if (link_option(option, "soname=", )) {
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


[Tinycc-devel] -Wl,-rpath not passed through?

2016-06-02 Thread Steffen Nurpmeso
Hello again!

I have just recognized that i need to use -Wl,-rpath now (new
layout for/with optional (hidden) packages in my ~/usr/opt/), so
great that tcc(1) does support this!  (I always wondered why -L
isn't automatically taken over for this purpose, however, since it
is standardized and why should i include something in -L but not
want it to end up as a runtime path?  Especially if something
actually had been found during the link process.  But, well...)

So then, here we go:

  Building..
$ tcc -Wl,-rpath=/home/steffen/usr/opt/.ssl-1.1.0/lib 
-Wl,-rpath=/home/steffen/usr/lib -Wl,-rpath=/home/steffen/usr/opt/tcc-mob/lib 
-Wl,-rpath=/home/steffen/usr/opt/pcc/lib -Wl,-rpath=/lib 
-Wl,-rpath=/usr/local/lib -Wl,-rpath=/usr/lib   -o s-nail accmacvar.o 
attachments.o auxlily.o cmd1.o cmd2.o cmd3.o cmd_cnd.o collect.o colour.o 
dotlock.o edit.o filter.o fio.o folder.o head.o imap_search.o lex_input.o 
list.o mailcap.o maildir.o main.o memory.o message.o mime.o mime_enc.o 
mime_param.o mime_parse.o mime_types.o nam_a_grp.o openpgp.o openssl.o path.o 
pop3.o popen.o privacy.o quit.o send.o sendout.o signal.o smtp.o socket.o 
spam.o ssl.o strings.o termcap.o thread.o tty.o ui_str.o urlcrecry.o wordexp.o 
-L/home/steffen/usr/opt/.ssl-1.1.0/lib -L/home/steffen/usr/lib 
-L/home/steffen/usr/opt/tcc-mob/lib -L/home/steffen/usr/opt/pcc/lib -L/lib 
-L/usr/local/lib -L/usr/lib -lssl -lcrypto -lgssapi_krb5 -lkrb5 -lk5crypto 
-lcom_err -lidn -lcurses
 textdata bss dec hex filename
   882664  136640  112760 1132064  114620 s-nail
  make[1]: Leaving directory '/home/steffen/src/nail.git'
  ?0[steffen@wales nail.git]$ l /home/steffen/usr/opt/.ssl-1.1.0/lib
  pkgconfig/  ../  libcrypto.a  libssl.a  libcrypto.so.1.1  libcrypto.so@  
libssl.so.1.1  libssl.so@  ./  engines/
  ?0[steffen@wales nail.git]$ readelf -d s-nail 
 

  Dynamic section at offset 0xf66f8 contains 19 entries:
TagType Name/Value
   0x0001 (NEEDED) Shared library: [libssl.so.1.1]
   0x0001 (NEEDED) Shared library: [libcrypto.so.1.1]
Yes!
   [.]
   0x000f (RPATH)  Library rpath: [/usr/lib]
No!

For gcc(1) we end up as desired:

   0x000f (RPATH)  Library rpath: 
[/home/steffen/usr/opt/.ssl-1.1.0/lib:/home/steffen/usr/lib:/home/steffen/usr/opt/tcc-mob/lib:/home/steffen/usr/opt/pcc/lib:/lib:/usr/local/lib:/usr/lib]

This is still true for [mob:1ca685f], but which no longer needs
a cherry-picked commit to do it.  Cool!  :-)
Ciao!

--steffen

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel