On Thu, Jul 18, 2024 at 9:38 PM Chris Guthrey <ch...@fantail.net.nz> wrote: > > I'm trying to learn how the last version of Go that is bootstrapped from C > works and as a learning exercise, maybe try porting to a new OS (on x86 for > now)... > > So I'm trying to get my head around the xrealdwd() function in > /src/cmd/dist/unix.c - I just can't grok why it is needed. > > A quick search indicates that xrealdwd() is only ever used by build.c, and > the comment in build.c says: > > // xgetwd might return a path with symlinks fully resolved, and if > // there happens to be symlinks in goroot, then the hasprefix test > // will never succeed. Instead, we use xrealwd to get a canonical > // goroot/src before the comparison to avoid this problem. > > I guess my understanding and knowledge of symlinks is lacking, but I guess i > just don't understand why hasprefix() will never succeed if there happens to > be symlinks in goroot...
hasprefix is a simple string comparison. If /home is a symlink to /real/home, and GOROOT is /home/go, then xgetwd can return /real/home/go which won't match /home/go. > The windows.c file also has a similar (at least similar in logic but not in > OS calls) approach to xrealdwd() so I must assume that hasprefix() does not > like symlinks on Windows either? Yes, again, hasprefix is a simple string comparison. > I think if this were ported to an OS that doesnt have symlinks, I might be > able to get away with making xrealwd() always just return the current > directory without trying to get a canonical path to goroot/src... Yes, I suppose. But I don't recommend following the path of porting Go 1.4. Instead, port the current Go tip, and build it on a supported machine, and then use that to cross-compile. See bootstrap.bash. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXqiH%2B6S6dKtsJRMbmrfSeNMmT_6iYxLZwJwkLZOexmEQ%40mail.gmail.com.