[ 
https://issues.apache.org/jira/browse/BEAM-8242?focusedWorklogId=314593&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-314593
 ]

ASF GitHub Bot logged work on BEAM-8242:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 18/Sep/19 19:25
            Start Date: 18/Sep/19 19:25
    Worklog Time Spent: 10m 
      Work Description: ianlancetaylor commented on pull request #9585: 
[BEAM-8242] Support -buildmode=pie with unregistered Go functions
URL: https://github.com/apache/beam/pull/9585#discussion_r325852241
 
 

 ##########
 File path: sdks/go/pkg/beam/core/util/symtab/symtab_test.go
 ##########
 @@ -0,0 +1,115 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package symtab
+
+import (
+       "io/ioutil"
+       "os"
+       "os/exec"
+       "path/filepath"
+       "runtime"
+       "strings"
+       "testing"
+)
+
+// TestSym2Addr builds and runs this test program.
+const testprog = `
+package main
+
+import (
+       "fmt"
+       "os"
+       "runtime"
+
+       "github.com/apache/beam/sdks/go/pkg/beam/core/util/symtab"
+)
+
+func die(format string, a ...interface{}) {
+       fmt.Fprintf(os.Stderr, format, a...)
+       os.Exit(1)
+}
+
+func main() {
+       syms, err := symtab.New(os.Args[0])
+       if err != nil {
+               die("%s: could not read symbols: %v", os.Args[0], err)
+       }
+
+       symPC, err := syms.Sym2Addr("main.main")
+       if err != nil {
+               die("Sym2Addr(%q) failed: %v", "main.main", err)
+       }
+
+       runtimePC := fnaddr()
+       if symPC != runtimePC {
+               die("PC from symbol table %x != runtime PC %x", symPC, 
runtimePC)
+       }
+}
+
+// fnaddr returns the entry address of its caller.
+func fnaddr() uintptr {
+       var pcs [2]uintptr
+       n := runtime.Callers(2, pcs[:])
+       frames := runtime.CallersFrames(pcs[:n])
+       frame, _ := frames.Next()
+       return frame.Func.Entry()
+}
+`
+
+func TestSym2Addr(t *testing.T) {
+       f, err := ioutil.TempFile("", "TestSym2Addr*.go")
+       if err != nil {
+               t.Fatal(err)
+       }
+
+       fname := f.Name()
+       defer os.Remove(fname)
+
+       if _, err := f.WriteString(testprog); err != nil {
+               t.Fatal(err)
+       }
+       if err := f.Close(); err != nil {
+               t.Fatal(err)
+       }
+
+       bin := strings.TrimSuffix(fname, ".go")
+       defer os.Remove(bin)
+
+       gotool := filepath.Join(runtime.GOROOT(), "bin", "go")
+
+       for _, arg := range []string{"", "-buildmode=pie"} {
 
 Review comment:
   Done.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 314593)
    Time Spent: 1h  (was: 50m)

> Go: unregistered Go functions fail when using -buildmode=pie
> ------------------------------------------------------------
>
>                 Key: BEAM-8242
>                 URL: https://issues.apache.org/jira/browse/BEAM-8242
>             Project: Beam
>          Issue Type: Bug
>          Components: sdk-go
>    Affects Versions: 2.15.0
>         Environment: GNU/Linux
>            Reporter: Ian Lance Taylor
>            Assignee: Robert Burke
>            Priority: Major
>   Original Estimate: 0h
>          Time Spent: 1h
>  Remaining Estimate: 0h
>
> If a Go program is built with -buildmode=pie, the code that transfers an 
> unregistered function fails.  It looks up the symbol in the symbol table, but 
> that is not the location of the function at execution time.  This causes a 
> program crash when calling the function.
> I have a patch for this problem that I will send shortly.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to