Le dimanche 7 avril 2013 04:07:19, Darren Oakey a écrit :
> I am using a system with no c compiler, no include directories - ie they've
> made some effort to stop you writing c for some reason (even though other
> languages are freely available).   I found tiny cc - and particularly
> PTS-TCC - and thought my problems were solved - hello world and other
> programs worked perfectly.
> 
> Then I ran into a snag.
> 
> However I try - I can't read the environment :( -    getenv, while
> appearing to be there, always returns null.  I looked at the uclibc source
> and getenv uses __environ - which is null, as is environ, if I do a char **
> environ.   If I extend main to have void main (int argv, char **args, char
> **envp) - envp appears to be just random numbers.

I searched what is tcc and the links I found to download pts-tcc are based on 
tcc 0.9.25. This bug was fixed for tcc 0.9.26. You could make yourself and 
many people a service by contacting the author of that software to tell them 
to merge the changes from tcc 0.9.26.

> 
> please help - anyone have any idea how I get at environment variables?  I'm
> trying to use this to build a faster cgi on my web host - so without
> environment variables, I'm toast.

You could try recompiling pts-tcc with itself after applying the attached 
patch to it.

> 
> Thanks,
> Darren

Best regards,

Thomas Preud'homme
From: Thomas Preud'homme <[email protected]>
Date: Mon, 26 Apr 2010 00:46:39 +0200
Subject: Link alias symbols together

Make sure alias symbols resolve to the same address in program .bss or .data
section. This ensures for example that if a program references environ (via an
extern char **environ declaration) and libc changes its value via the
__environ alias after the R_ARCH_COPY relocation has been performed, then
the program will see the new value.

Origin: vendor
Bug-Debian: http://bugs.debian.org/452876
Forwarded: http://lists.nongnu.org/archive/html/tinycc-devel/2010-05/msg00001.html
Last-Update: 2010-05-01
Applied-Upstream: commit: a28b18fa16edaeb6bc7d34cf1ddac690b27ba610
---
 tccelf.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/tccelf.c b/tccelf.c
index f256575..e7e2541 100644
--- a/tccelf.c
+++ b/tccelf.c
@@ -1438,12 +1438,32 @@ int elf_output_file(TCCState *s1, const char *filename)
                                               sym - (ElfW(Sym) *)symtab_section->data);
                             } else if (type == STT_OBJECT) {
                                 unsigned long offset;
+                                ElfW(Sym) *dynsym, *dynsym_end;
                                 offset = bss_section->data_offset;
                                 /* XXX: which alignment ? */
                                 offset = (offset + 16 - 1) & -16;
                                 index = put_elf_sym(s1->dynsym, offset, esym->st_size, 
                                                     esym->st_info, 0, 
                                                     bss_section->sh_num, name);
+                                /* Ensure symbol aliases (that is, symbols with
+                                   the same st_value) resolve to the same
+                                   address in program .bss or .data section. */
+                                dynsym_end = (ElfW(Sym) *)
+                                             (s1->dynsymtab_section->data +
+                                              s1->dynsymtab_section->data_offset);
+                                for(dynsym = (ElfW(Sym) *)s1->dynsymtab_section->data + 1;
+                                    dynsym < dynsym_end; dynsym++) {
+                                    if (dynsym->st_value == esym->st_value) {
+                                        char *dynname;
+                                        dynname = s1->dynsymtab_section->link->data
+                                                  + dynsym->st_name;
+                                        put_elf_sym(s1->dynsym, offset,
+                                                    dynsym->st_size,
+                                                    dynsym->st_info, 0,
+                                                    bss_section->sh_num,
+                                                    dynname);
+                                    }
+                                }
                                 put_elf_reloc(s1->dynsym, bss_section, 
                                               offset, R_COPY, index);
                                 offset += esym->st_size;
-- 

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to